public class AlpacaAPI
extends java.lang.Object
Constructor and Description |
---|
AlpacaAPI()
Instantiates a new Alpaca API using properties specified in alpaca.properties file (or relevant defaults)
|
AlpacaAPI(java.lang.String apiVersion)
Instantiates a new Alpaca API using the specified apiVersion
|
AlpacaAPI(java.lang.String apiVersion,
java.lang.String keyId,
java.lang.String secret)
Instantiates a new Alpaca API using the specified apiVersion, keyId, and secret.
|
AlpacaAPI(java.lang.String apiVersion,
java.lang.String keyId,
java.lang.String secret,
java.lang.String baseAPIURL)
Instantiates a new Alpaca API using the specified apiVersion, keyId, secret, and baseAPIURL.
|
AlpacaAPI(java.lang.String apiVersion,
java.lang.String keyId,
java.lang.String secret,
java.lang.String baseAPIURL,
java.lang.String baseDataUrl)
Instantiates a new Alpaca API using the specified keyId, secret, baseAPIURL, and baseDataUrl.
|
Modifier and Type | Method and Description |
---|---|
void |
addAlpacaStreamListener(AlpacaStreamListener streamListener)
Adds the alpaca stream listener.
|
Watchlist |
addWatchlistAsset(java.lang.String watchlistID,
java.lang.String symbol)
Append an asset for the symbol to the end of watchlist asset list
|
java.util.ArrayList<CancelledOrder> |
cancelAllOrders()
Attempts to cancel all open orders.
|
boolean |
cancelOrder(java.lang.String orderId)
Attempts to cancel an open order.
|
java.util.ArrayList<ClosePositionOrder> |
closeAllPositions()
Closes (liquidates) all of the account’s open long and short positions.
|
Order |
closePosition(java.lang.String symbol)
Closes (liquidates) the account’s open position for the given symbol.
|
Watchlist |
createWatchlist(java.lang.String name,
java.lang.String... symbols)
Create a new watchlist with initial set of assets.
|
boolean |
deleteWatchlist(java.lang.String watchlistID)
Delete a watchlist.
|
Account |
getAccount()
Returns the account associated with the API key.
|
java.util.ArrayList<AccountActivity> |
getAccountActivities(java.time.ZonedDateTime date,
java.time.ZonedDateTime until,
java.time.ZonedDateTime after,
Direction direction,
java.lang.Integer pageSize,
java.lang.String pageToken,
ActivityType... activityTypes)
Returns account activity entries for many or for a specific type of activity.
|
AccountConfiguration |
getAccountConfiguration()
Returns the current account configuration values.
|
Asset |
getAssetBySymbol(java.lang.String symbolOrAssetID)
Gets the asset by symbol or asset_id.
|
java.util.ArrayList<Asset> |
getAssets(AssetStatus assetStatus,
java.lang.String assetClass)
Get a list of assets.
|
java.util.Map<java.lang.String,java.util.ArrayList<Bar>> |
getBars(BarsTimeFrame timeframe,
java.lang.String[] symbols,
java.lang.Integer limit,
java.time.ZonedDateTime start,
java.time.ZonedDateTime end,
java.time.ZonedDateTime after,
java.time.ZonedDateTime until)
Retrieves a list of bars for each requested symbol.
|
java.util.Map<java.lang.String,java.util.ArrayList<Bar>> |
getBars(BarsTimeFrame timeframe,
java.lang.String symbol,
java.lang.Integer limit,
java.time.ZonedDateTime start,
java.time.ZonedDateTime end,
java.time.ZonedDateTime after,
java.time.ZonedDateTime until)
Retrieves a list of bars for each requested symbol.
|
java.util.ArrayList<Calendar> |
getCalendar()
Returns the market calendar.
|
java.util.ArrayList<Calendar> |
getCalendar(java.time.LocalDate start,
java.time.LocalDate end)
Returns the market calendar.
|
Clock |
getClock()
Returns the market clock.
|
Position |
getOpenPositionBySymbol(java.lang.String symbol)
Gets the open position by symbol.
|
java.util.ArrayList<Position> |
getOpenPositions()
Gets the open positions.
|
Order |
getOrder(java.lang.String orderID,
java.lang.Boolean nested)
Retrieves a single order for the given order_id.
|
Order |
getOrderByClientID(java.lang.String clientOrderId)
Retrieves a single order for the given client_order_id.
|
java.util.ArrayList<Order> |
getOrders(OrderStatus status,
java.lang.Integer limit,
java.time.ZonedDateTime after,
java.time.ZonedDateTime until,
Direction direction,
java.lang.Boolean nested)
Retrieves a list of orders for the account, filtered by the supplied query parameters.
|
PortfolioHistory |
getPortfolioHistory(java.lang.Integer periodLength,
PortfolioPeriodUnit periodUnit,
PortfolioTimeFrame timeFrame,
java.time.LocalDate dateEnd,
java.lang.Boolean extendedHours)
Returns timeseries data about equity and profit/loss (P/L) of the account in requested timespan.
|
Watchlist |
getWatchlist(java.lang.String watchlistID)
Returns a watchlist identified by the ID.
|
java.util.ArrayList<Watchlist> |
getWatchlists()
Returns the list of watchlists registered under the account.
|
void |
removeAlpacaStreamListener(AlpacaStreamListener streamListener)
Removes the alpaca stream listener.
|
Watchlist |
removeSymbolFromWatchlist(java.lang.String watchlistID,
java.lang.String symbol)
Delete one entry for an asset by symbol name.
|
Order |
replaceOrder(java.lang.String orderID,
java.lang.Integer quantity,
OrderTimeInForce timeInForce,
java.lang.Double limitPrice,
java.lang.Double stopPrice,
java.lang.String clientOrderId)
Replaces a single order with updated parameters.
|
Order |
requestNewLimitBracketOrder(java.lang.String symbol,
java.lang.Integer quantity,
OrderSide side,
OrderTimeInForce timeInForce,
java.lang.Double limitPrice,
java.lang.Boolean extendedHours,
java.lang.Double takeProfitLimitPrice,
java.lang.Double stopLossStopPrice,
java.lang.Double stopLossLimitPrice)
A bracket order is a chain of three orders that can be used to manage your position entry and exit.
|
Order |
requestNewLimitOrder(java.lang.String symbol,
java.lang.Integer quantity,
OrderSide side,
OrderTimeInForce timeInForce,
java.lang.Double limitPrice,
java.lang.Boolean extendedHours)
A limit order is an order to buy or sell at a specified price or better.
|
Order |
requestNewMarketBracketOrder(java.lang.String symbol,
java.lang.Integer quantity,
OrderSide side,
OrderTimeInForce timeInForce,
java.lang.Boolean extendedHours,
java.lang.Double takeProfitLimitPrice,
java.lang.Double stopLossStopPrice,
java.lang.Double stopLossLimitPrice)
A bracket order is a chain of three orders that can be used to manage your position entry and exit.
|
Order |
requestNewMarketOrder(java.lang.String symbol,
java.lang.Integer quantity,
OrderSide side,
OrderTimeInForce timeInForce,
java.lang.Boolean extendedHours)
A market order is a request to buy or sell a security at the currently available market price.
|
Order |
requestNewOCOOrder(java.lang.String symbol,
java.lang.Integer quantity,
OrderSide side,
OrderTimeInForce timeInForce,
java.lang.Boolean extendedHours,
java.lang.Double takeProfitLimitPrice,
java.lang.Double stopLossStopPrice,
java.lang.Double stopLossLimitPrice)
OCO (One-Cancels-Other) is another type of advanced order type.
|
Order |
requestNewOrder(java.lang.String symbol,
java.lang.Integer quantity,
OrderSide side,
OrderType type,
OrderTimeInForce timeInForce,
java.lang.Double limitPrice,
java.lang.Double stopPrice,
java.lang.Boolean extendedHours,
java.lang.String clientOrderId,
OrderClass orderClass,
java.lang.Double takeProfitLimitPrice,
java.lang.Double stopLossStopPrice,
java.lang.Double stopLossLimitPrice)
Places a new order for the given account.
|
Order |
requestNewOTOLimitOrder(java.lang.String symbol,
java.lang.Integer quantity,
OrderSide side,
OrderTimeInForce timeInForce,
java.lang.Double limitPrice,
java.lang.Boolean extendedHours,
java.lang.Double takeProfitLimitPrice,
java.lang.Double stopLossStopPrice,
java.lang.Double stopLossLimitPrice)
OTO (One-Triggers-Other) is a variant of bracket order.
|
Order |
requestNewOTOMarketOrder(java.lang.String symbol,
java.lang.Integer quantity,
OrderSide side,
OrderTimeInForce timeInForce,
java.lang.Boolean extendedHours,
java.lang.Double takeProfitLimitPrice,
java.lang.Double stopLossStopPrice,
java.lang.Double stopLossLimitPrice)
OTO (One-Triggers-Other) is a variant of bracket order.
|
Order |
requestNewOTOStopLimitOrder(java.lang.String symbol,
java.lang.Integer quantity,
OrderSide side,
OrderTimeInForce timeInForce,
java.lang.Double limitPrice,
java.lang.Double stopPrice,
java.lang.Boolean extendedHours,
java.lang.Double takeProfitLimitPrice,
java.lang.Double stopLossStopPrice,
java.lang.Double stopLossLimitPrice)
OTO (One-Triggers-Other) is a variant of bracket order.
|
Order |
requestNewOTOStopOrder(java.lang.String symbol,
java.lang.Integer quantity,
OrderSide side,
OrderTimeInForce timeInForce,
java.lang.Double stopPrice,
java.lang.Boolean extendedHours,
java.lang.Double takeProfitLimitPrice,
java.lang.Double stopLossStopPrice,
java.lang.Double stopLossLimitPrice)
OTO (One-Triggers-Other) is a variant of bracket order.
|
Order |
requestNewStopLimitOrder(java.lang.String symbol,
java.lang.Integer quantity,
OrderSide side,
OrderTimeInForce timeInForce,
java.lang.Double limitPrice,
java.lang.Double stopPrice,
java.lang.Boolean extendedHours)
A stop-limit order is a conditional trade over a set time frame that combines the features of a stop order with
those of a limit order and is used to mitigate risk.
|
Order |
requestNewStopOrder(java.lang.String symbol,
java.lang.Integer quantity,
OrderSide side,
OrderTimeInForce timeInForce,
java.lang.Double stopPrice,
java.lang.Boolean extendedHours)
A stop (market) order is an order to buy or sell a security when its price moves past a particular point,
ensuring a higher probability of achieving a predetermined entry or exit price.
|
AccountConfiguration |
setAccountConfiguration(AccountConfiguration accountConfiguration)
Sets account configuration.
|
java.lang.String |
toString() |
Watchlist |
updateWatchlist(java.lang.String watchlistID,
java.lang.String name,
java.lang.String... symbols)
Update the name and/or content of watchlist.
|
public AlpacaAPI()
public AlpacaAPI(java.lang.String apiVersion)
apiVersion
- the api versionpublic AlpacaAPI(java.lang.String apiVersion, java.lang.String keyId, java.lang.String secret)
keyId
- the key idsecret
- the secretpublic AlpacaAPI(java.lang.String apiVersion, java.lang.String keyId, java.lang.String secret, java.lang.String baseAPIURL)
apiVersion
- the api versionkeyId
- the key idsecret
- the secretbaseAPIURL
- the api account urlpublic AlpacaAPI(java.lang.String apiVersion, java.lang.String keyId, java.lang.String secret, java.lang.String baseAPIURL, java.lang.String baseDataUrl)
apiVersion
- the api versionkeyId
- the key idsecret
- the secretbaseAPIURL
- the base api urlbaseDataUrl
- the base data urlpublic Account getAccount() throws AlpacaAPIRequestException
AlpacaAPIRequestException
- the alpaca API exceptionpublic java.util.ArrayList<AccountActivity> getAccountActivities(java.time.ZonedDateTime date, java.time.ZonedDateTime until, java.time.ZonedDateTime after, Direction direction, java.lang.Integer pageSize, java.lang.String pageToken, ActivityType... activityTypes) throws AlpacaAPIRequestException
date
- The date for which you want to see activities.until
- The response will contain only activities submitted before this date. (Cannot be used with
date.)after
- The response will contain only activities submitted after this date. (Cannot be used with
date.)direction
- asc or desc (default desc if unspecified.)pageSize
- The maximum number of entries to return in the response. (See the section on paging above.)pageToken
- The ID of the end of your current page of results. (See the section on paging above.)activityTypes
- the activity types (null for all activities)AlpacaAPIRequestException
- the alpaca api exceptionpublic AccountConfiguration getAccountConfiguration() throws AlpacaAPIRequestException
AlpacaAPIRequestException
- the alpaca api exceptionpublic AccountConfiguration setAccountConfiguration(AccountConfiguration accountConfiguration) throws AlpacaAPIRequestException
accountConfiguration
- the account configurationAlpacaAPIRequestException
- the alpaca api exceptionpublic java.util.ArrayList<Order> getOrders(OrderStatus status, java.lang.Integer limit, java.time.ZonedDateTime after, java.time.ZonedDateTime until, Direction direction, java.lang.Boolean nested) throws AlpacaAPIRequestException
status
- Order status to be queried. open, closed or all. Defaults to open.limit
- The maximum number of orders in response. Defaults to 50 and max is 500.after
- The response will include only ones submitted after this timestamp (exclusive.)until
- The response will include only ones submitted until this timestamp (exclusive.)direction
- The chronological order of response based on the submission time. asc or desc. Defaults to
desc.nested
- If true, the result will roll up multi-leg orders under the legs field of primary order.AlpacaAPIRequestException
- the alpaca API exceptionpublic Order requestNewOrder(java.lang.String symbol, java.lang.Integer quantity, OrderSide side, OrderType type, OrderTimeInForce timeInForce, java.lang.Double limitPrice, java.lang.Double stopPrice, java.lang.Boolean extendedHours, java.lang.String clientOrderId, OrderClass orderClass, java.lang.Double takeProfitLimitPrice, java.lang.Double stopLossStopPrice, java.lang.Double stopLossLimitPrice) throws AlpacaAPIRequestException
symbol
- symbol or asset ID to identify the asset to tradequantity
- number of shares to tradeside
- buy or selltype
- market, limit, stop, or stop_limittimeInForce
- day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.limitPrice
- required if type is limit or stop_limitstopPrice
- required if type is stop or stop_limitextendedHours
- (default) false. If true, order will be eligible to execute in premarket/afterhours.
Only works with type limit and time_in_force day.clientOrderId
- A unique identifier for the order. Automatically generated if not sent.orderClass
- Simple, bracket, oco, or oto. For details of non-simple order classes, please see
Bracket Order Overview on the Alpaca Docs.takeProfitLimitPrice
- Additional parameter for take-profit leg of advanced orders. Required for bracket
orders.stopLossStopPrice
- Additional parameters for stop-loss leg of advanced orders. Required for bracket
orders.stopLossLimitPrice
- Additional parameters for stop-loss leg of advanced orders. The stop-loss order
becomes a stop-limit order if specified.AlpacaAPIRequestException
- the alpaca API exceptionpublic Order requestNewMarketOrder(java.lang.String symbol, java.lang.Integer quantity, OrderSide side, OrderTimeInForce timeInForce, java.lang.Boolean extendedHours) throws AlpacaAPIRequestException
requestNewOrder(String, Integer, OrderSide, OrderType, OrderTimeInForce, Double, Double, Boolean, String,
OrderClass, Double, Double, Double)
with OrderType.MARKET
.symbol
- symbol or asset ID to identify the asset to tradequantity
- number of shares to tradeside
- buy or selltimeInForce
- day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.extendedHours
- (default) false. If true, order will be eligible to execute in premarket/afterhours. Only
works with type limit and time_in_force day.AlpacaAPIRequestException
- the alpaca api request exceptionpublic Order requestNewLimitOrder(java.lang.String symbol, java.lang.Integer quantity, OrderSide side, OrderTimeInForce timeInForce, java.lang.Double limitPrice, java.lang.Boolean extendedHours) throws AlpacaAPIRequestException
requestNewOrder(String, Integer,
OrderSide, OrderType, OrderTimeInForce, Double, Double, Boolean, String, OrderClass, Double, Double, Double)
with OrderType.LIMIT
.symbol
- symbol or asset ID to identify the asset to tradequantity
- number of shares to tradeside
- buy or selltimeInForce
- day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.limitPrice
- required if type is limit or stop_limitextendedHours
- (default) false. If true, order will be eligible to execute in premarket/afterhours. Only
works with type limit and time_in_force day.AlpacaAPIRequestException
- the alpaca api request exceptionpublic Order requestNewStopOrder(java.lang.String symbol, java.lang.Integer quantity, OrderSide side, OrderTimeInForce timeInForce, java.lang.Double stopPrice, java.lang.Boolean extendedHours) throws AlpacaAPIRequestException
requestNewOrder(String, Integer, OrderSide, OrderType, OrderTimeInForce, Double, Double, Boolean, String,
OrderClass, Double, Double, Double)
with OrderType.STOP
.symbol
- symbol or asset ID to identify the asset to tradequantity
- number of shares to tradeside
- buy or selltimeInForce
- day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.stopPrice
- required if type is stop or stop_limitextendedHours
- (default) false. If true, order will be eligible to execute in premarket/afterhours. Only
works with type limit and time_in_force day.AlpacaAPIRequestException
- the alpaca api request exceptionpublic Order requestNewStopLimitOrder(java.lang.String symbol, java.lang.Integer quantity, OrderSide side, OrderTimeInForce timeInForce, java.lang.Double limitPrice, java.lang.Double stopPrice, java.lang.Boolean extendedHours) throws AlpacaAPIRequestException
requestNewOrder(String, Integer, OrderSide, OrderType, OrderTimeInForce, Double, Double, Boolean, String,
OrderClass, Double, Double, Double)
with OrderType.STOP_LIMIT
.symbol
- symbol or asset ID to identify the asset to tradequantity
- number of shares to tradeside
- buy or selltimeInForce
- day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.limitPrice
- required if type is limit or stop_limitstopPrice
- required if type is stop or stop_limitextendedHours
- (default) false. If true, order will be eligible to execute in premarket/afterhours. Only
works with type limit and time_in_force day.AlpacaAPIRequestException
- the alpaca api request exceptionpublic Order requestNewMarketBracketOrder(java.lang.String symbol, java.lang.Integer quantity, OrderSide side, OrderTimeInForce timeInForce, java.lang.Boolean extendedHours, java.lang.Double takeProfitLimitPrice, java.lang.Double stopLossStopPrice, java.lang.Double stopLossLimitPrice) throws AlpacaAPIRequestException
requestNewOrder(String, Integer, OrderSide, OrderType, OrderTimeInForce, Double, Double, Boolean, String,
OrderClass, Double, Double, Double)
with OrderType.MARKET
and with parameters for a bracket order.symbol
- symbol or asset ID to identify the asset to tradequantity
- number of shares to tradeside
- buy or selltimeInForce
- day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.extendedHours
- (default) false. If true, order will be eligible to execute in premarket/afterhours.
Only works with type limit and time_in_force day.takeProfitLimitPrice
- Additional parameter for take-profit leg of advanced orders. Required for bracket
orders.stopLossStopPrice
- Additional parameters for stop-loss leg of advanced orders. Required for bracket
orders.stopLossLimitPrice
- Additional parameters for stop-loss leg of advanced orders. The stop-loss order
becomes a stop-limit order if specified.AlpacaAPIRequestException
- the alpaca api request exceptionpublic Order requestNewLimitBracketOrder(java.lang.String symbol, java.lang.Integer quantity, OrderSide side, OrderTimeInForce timeInForce, java.lang.Double limitPrice, java.lang.Boolean extendedHours, java.lang.Double takeProfitLimitPrice, java.lang.Double stopLossStopPrice, java.lang.Double stopLossLimitPrice) throws AlpacaAPIRequestException
requestNewOrder(String, Integer, OrderSide, OrderType, OrderTimeInForce, Double, Double, Boolean, String,
OrderClass, Double, Double, Double)
with OrderType.LIMIT
and with parameters for a bracket order.symbol
- symbol or asset ID to identify the asset to tradequantity
- number of shares to tradeside
- buy or selltimeInForce
- day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.limitPrice
- required if type is limit or stop_limitextendedHours
- (default) false. If true, order will be eligible to execute in premarket/afterhours.
Only works with type limit and time_in_force day.takeProfitLimitPrice
- Additional parameter for take-profit leg of advanced orders. Required for bracket
orders.stopLossStopPrice
- Additional parameters for stop-loss leg of advanced orders. Required for bracket
orders.stopLossLimitPrice
- Additional parameters for stop-loss leg of advanced orders. The stop-loss order
becomes a stop-limit order if specified.AlpacaAPIRequestException
- the alpaca api request exceptionpublic Order requestNewOCOOrder(java.lang.String symbol, java.lang.Integer quantity, OrderSide side, OrderTimeInForce timeInForce, java.lang.Boolean extendedHours, java.lang.Double takeProfitLimitPrice, java.lang.Double stopLossStopPrice, java.lang.Double stopLossLimitPrice) throws AlpacaAPIRequestException
requestNewOrder(String, Integer, OrderSide, OrderType,
OrderTimeInForce, Double, Double, Boolean, String, OrderClass, Double, Double, Double)
with parameters for an
OCO order type.symbol
- symbol or asset ID to identify the asset to tradequantity
- number of shares to tradeside
- buy or selltimeInForce
- day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.extendedHours
- (default) false. If true, order will be eligible to execute in premarket/afterhours.
Only works with type limit and time_in_force day.takeProfitLimitPrice
- Additional parameter for take-profit leg of advanced orders.stopLossStopPrice
- Additional parameters for stop-loss leg of advanced orders.stopLossLimitPrice
- Additional parameters for stop-loss leg of advanced orders. The stop-loss order
becomes a stop-limit order if specified.AlpacaAPIRequestException
- the alpaca api request exceptionpublic Order requestNewOTOMarketOrder(java.lang.String symbol, java.lang.Integer quantity, OrderSide side, OrderTimeInForce timeInForce, java.lang.Boolean extendedHours, java.lang.Double takeProfitLimitPrice, java.lang.Double stopLossStopPrice, java.lang.Double stopLossLimitPrice) throws AlpacaAPIRequestException
requestNewOrder(String, Integer, OrderSide, OrderType,
OrderTimeInForce, Double, Double, Boolean, String, OrderClass, Double, Double, Double)
with OrderType.LIMIT
and with parameters for an OTO order type.symbol
- symbol or asset ID to identify the asset to tradequantity
- number of shares to tradeside
- buy or selltimeInForce
- day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.extendedHours
- (default) false. If true, order will be eligible to execute in premarket/afterhours.
Only works with type limit and time_in_force day.takeProfitLimitPrice
- Additional parameter for take-profit leg of advanced orders.stopLossStopPrice
- Additional parameters for stop-loss leg of advanced orders.stopLossLimitPrice
- Additional parameters for stop-loss leg of advanced orders. The stop-loss order
becomes a stop-limit order if specified.AlpacaAPIRequestException
- the alpaca api request exceptionpublic Order requestNewOTOLimitOrder(java.lang.String symbol, java.lang.Integer quantity, OrderSide side, OrderTimeInForce timeInForce, java.lang.Double limitPrice, java.lang.Boolean extendedHours, java.lang.Double takeProfitLimitPrice, java.lang.Double stopLossStopPrice, java.lang.Double stopLossLimitPrice) throws AlpacaAPIRequestException
requestNewOrder(String, Integer, OrderSide, OrderType,
OrderTimeInForce, Double, Double, Boolean, String, OrderClass, Double, Double, Double)
with OrderType.LIMIT
and with parameters for an OTO order type.symbol
- symbol or asset ID to identify the asset to tradequantity
- number of shares to tradeside
- buy or selltimeInForce
- day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.limitPrice
- required if type is limit or stop_limitextendedHours
- (default) false. If true, order will be eligible to execute in premarket/afterhours.
Only works with type limit and time_in_force day.takeProfitLimitPrice
- Additional parameter for take-profit leg of advanced orders.stopLossStopPrice
- Additional parameters for stop-loss leg of advanced orders.stopLossLimitPrice
- Additional parameters for stop-loss leg of advanced orders. The stop-loss order
becomes a stop-limit order if specified.AlpacaAPIRequestException
- the alpaca api request exceptionpublic Order requestNewOTOStopOrder(java.lang.String symbol, java.lang.Integer quantity, OrderSide side, OrderTimeInForce timeInForce, java.lang.Double stopPrice, java.lang.Boolean extendedHours, java.lang.Double takeProfitLimitPrice, java.lang.Double stopLossStopPrice, java.lang.Double stopLossLimitPrice) throws AlpacaAPIRequestException
requestNewOrder(String, Integer, OrderSide, OrderType,
OrderTimeInForce, Double, Double, Boolean, String, OrderClass, Double, Double, Double)
with OrderType.STOP
and with parameters for an OTO order type.symbol
- symbol or asset ID to identify the asset to tradequantity
- number of shares to tradeside
- buy or selltimeInForce
- day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.stopPrice
- required if type is stop or stop_limitextendedHours
- (default) false. If true, order will be eligible to execute in premarket/afterhours.
Only works with type limit and time_in_force day.takeProfitLimitPrice
- Additional parameter for take-profit leg of advanced orders.stopLossStopPrice
- Additional parameters for stop-loss leg of advanced orders.stopLossLimitPrice
- Additional parameters for stop-loss leg of advanced orders. The stop-loss order
becomes a stop-limit order if specified.AlpacaAPIRequestException
- the alpaca api request exceptionpublic Order requestNewOTOStopLimitOrder(java.lang.String symbol, java.lang.Integer quantity, OrderSide side, OrderTimeInForce timeInForce, java.lang.Double limitPrice, java.lang.Double stopPrice, java.lang.Boolean extendedHours, java.lang.Double takeProfitLimitPrice, java.lang.Double stopLossStopPrice, java.lang.Double stopLossLimitPrice) throws AlpacaAPIRequestException
requestNewOrder(String, Integer, OrderSide, OrderType,
OrderTimeInForce, Double, Double, Boolean, String, OrderClass, Double, Double, Double)
with OrderType.STOP_LIMIT
and with parameters for an OTO order type.symbol
- symbol or asset ID to identify the asset to tradequantity
- number of shares to tradeside
- buy or selltimeInForce
- day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.limitPrice
- required if type is limit or stop_limitstopPrice
- required if type is stop or stop_limitextendedHours
- (default) false. If true, order will be eligible to execute in premarket/afterhours.
Only works with type limit and time_in_force day.takeProfitLimitPrice
- Additional parameter for take-profit leg of advanced orders.stopLossStopPrice
- Additional parameters for stop-loss leg of advanced orders.stopLossLimitPrice
- Additional parameters for stop-loss leg of advanced orders. The stop-loss order
becomes a stop-limit order if specified.AlpacaAPIRequestException
- the alpaca api request exceptionpublic Order getOrder(java.lang.String orderID, java.lang.Boolean nested) throws AlpacaAPIRequestException
orderID
- Order IDnested
- If true, the result will roll up multi-leg orders under the legs field of primary order.AlpacaAPIRequestException
- the alpaca API exceptionpublic Order getOrderByClientID(java.lang.String clientOrderId) throws AlpacaAPIRequestException
clientOrderId
- the client order idAlpacaAPIRequestException
- the alpaca API exceptionpublic Order replaceOrder(java.lang.String orderID, java.lang.Integer quantity, OrderTimeInForce timeInForce, java.lang.Double limitPrice, java.lang.Double stopPrice, java.lang.String clientOrderId) throws AlpacaAPIRequestException
orderID
- Order idquantity
- number of shares to tradetimeInForce
- day, gtc, opg, cls, ioc, fok. Please see Understand Orders for more info.limitPrice
- required if type is limit or stop_limitstopPrice
- required if type is stop or stop_limitclientOrderId
- A unique identifier for the order. Automatically generated if not sent.AlpacaAPIRequestException
- the alpaca api request exceptionpublic java.util.ArrayList<CancelledOrder> cancelAllOrders() throws AlpacaAPIRequestException
AlpacaAPIRequestException
- the alpaca api request exceptionpublic boolean cancelOrder(java.lang.String orderId) throws AlpacaAPIRequestException
orderId
- Order IDAlpacaAPIRequestException
- the alpaca API exceptionpublic java.util.ArrayList<Position> getOpenPositions() throws AlpacaAPIRequestException
AlpacaAPIRequestException
- the alpaca API exceptionpublic Position getOpenPositionBySymbol(java.lang.String symbol) throws AlpacaAPIRequestException
symbol
- the symbol or asset_id (required)AlpacaAPIRequestException
- the alpaca API exceptionpublic java.util.ArrayList<ClosePositionOrder> closeAllPositions() throws AlpacaAPIRequestException
AlpacaAPIRequestException
- the alpaca API exceptionpublic Order closePosition(java.lang.String symbol) throws AlpacaAPIRequestException
symbol
- symbol or asset_idAlpacaAPIRequestException
- the alpaca API exceptionpublic java.util.ArrayList<Asset> getAssets(AssetStatus assetStatus, java.lang.String assetClass) throws AlpacaAPIRequestException
assetStatus
- e.g. “active”. By default, all statuses are included.assetClass
- Defaults to us_equity.AlpacaAPIRequestException
- the alpaca API exceptionpublic Asset getAssetBySymbol(java.lang.String symbolOrAssetID) throws AlpacaAPIRequestException
symbolOrAssetID
- the symbol or asset_id (required)AlpacaAPIRequestException
- the alpaca API exceptionpublic java.util.ArrayList<Watchlist> getWatchlists() throws AlpacaAPIRequestException
AlpacaAPIRequestException
- the alpaca api exceptionpublic Watchlist createWatchlist(java.lang.String name, java.lang.String... symbols) throws AlpacaAPIRequestException
name
- arbitrary name string, up to 64 characterssymbols
- set of symbol stringAlpacaAPIRequestException
- the alpaca api exceptionpublic Watchlist getWatchlist(java.lang.String watchlistID) throws AlpacaAPIRequestException
watchlistID
- Watchlist IDAlpacaAPIRequestException
- the alpaca api exceptionpublic Watchlist updateWatchlist(java.lang.String watchlistID, java.lang.String name, java.lang.String... symbols) throws AlpacaAPIRequestException
watchlistID
- Watchlist IDname
- the new watchlist namesymbols
- the new list of symbol names to replace the watchlist contentAlpacaAPIRequestException
- the alpaca api exceptionpublic Watchlist addWatchlistAsset(java.lang.String watchlistID, java.lang.String symbol) throws AlpacaAPIRequestException
watchlistID
- Watchlist IDsymbol
- the symbol name to add to the watchlistAlpacaAPIRequestException
- the alpaca api exceptionpublic boolean deleteWatchlist(java.lang.String watchlistID) throws AlpacaAPIRequestException
watchlistID
- Watchlist IDAlpacaAPIRequestException
- the alpaca api exceptionpublic Watchlist removeSymbolFromWatchlist(java.lang.String watchlistID, java.lang.String symbol) throws AlpacaAPIRequestException
watchlistID
- Watchlist IDsymbol
- symbol name to remove from the watchlist contentAlpacaAPIRequestException
- the alpaca api exceptionpublic PortfolioHistory getPortfolioHistory(java.lang.Integer periodLength, PortfolioPeriodUnit periodUnit, PortfolioTimeFrame timeFrame, java.time.LocalDate dateEnd, java.lang.Boolean extendedHours) throws AlpacaAPIRequestException
periodLength
- The duration of the data in "number + unit", such as 1D, where unit can be D for day, W for
week, M for month and A for year. Defaults to 1M. This parameter is the number.periodUnit
- The duration of the data in "number + unit", such as 1D, where unit can be D for day, W for
week, M for month and A for year. Defaults to 1M. This parameter is the unit.timeFrame
- The resolution of time window. 1Min, 5Min, 15Min, 1H, or 1D. If omitted, 1Min for less than
7 days period, 15Min for less than 30 days, or otherwise 1D.dateEnd
- The date the data is returned up to, in "YYYY-MM-DD" format. Defaults to the current market
date (rolls over at the market open if extended_hours is false, otherwise at 7am ET)extendedHours
- If true, include extended hours in the result. This is effective only for timeframe less
than 1D.AlpacaAPIRequestException
- the alpaca api request exceptionpublic java.util.ArrayList<Calendar> getCalendar() throws AlpacaAPIRequestException
AlpacaAPIRequestException
- the alpaca API exceptionpublic java.util.ArrayList<Calendar> getCalendar(java.time.LocalDate start, java.time.LocalDate end) throws AlpacaAPIRequestException
start
- The first date to retrieve data for (inclusive)end
- The last date to retrieve data for (inclusive)AlpacaAPIRequestException
- the alpaca API exceptionpublic Clock getClock() throws AlpacaAPIRequestException
AlpacaAPIRequestException
- the alpaca API exceptionpublic java.util.Map<java.lang.String,java.util.ArrayList<Bar>> getBars(BarsTimeFrame timeframe, java.lang.String symbol, java.lang.Integer limit, java.time.ZonedDateTime start, java.time.ZonedDateTime end, java.time.ZonedDateTime after, java.time.ZonedDateTime until) throws AlpacaAPIRequestException
Currently, no “incomplete” bars are returned. For example, a 1 minute bar for 09:30 will not be returned until 09:31.
timeframe
- One of minute, 1Min, 5Min, 15Min, day or 1D. minute is an alias of 1Min. Similarly, day is of
1D.symbol
- One symbol name.limit
- The maximum number of bars to be returned for each symbol. It can be between 1 and 1000. Default
is 100 if parameter is unspecified or 0.start
- Filter bars equal to or after this time. Cannot be used with after.end
- Filter bars equal to or before this time. Cannot be used with until.after
- Filter bars after this time. Cannot be used with start.until
- Filter bars before this time. Cannot be used with end.AlpacaAPIRequestException
- the alpaca API exceptionpublic java.util.Map<java.lang.String,java.util.ArrayList<Bar>> getBars(BarsTimeFrame timeframe, java.lang.String[] symbols, java.lang.Integer limit, java.time.ZonedDateTime start, java.time.ZonedDateTime end, java.time.ZonedDateTime after, java.time.ZonedDateTime until) throws AlpacaAPIRequestException
Currently, no “incomplete” bars are returned. For example, a 1 minute bar for 09:30 will not be returned until 09:31.
timeframe
- One of minute, 1Min, 5Min, 15Min, day or 1D. minute is an alias of 1Min. Similarly, day is of
1D.symbols
- One or more (max 200) symbol names split by commas (“,”).limit
- The maximum number of bars to be returned for each symbol. It can be between 1 and 1000. Default
is 100 if parameter is unspecified or 0.start
- Filter bars equal to or after this time. Cannot be used with after.end
- Filter bars equal to or before this time. Cannot be used with until.after
- Filter bars after this time. Cannot be used with start.until
- Filter bars before this time. Cannot be used with end.AlpacaAPIRequestException
- the alpaca API exceptionpublic void addAlpacaStreamListener(AlpacaStreamListener streamListener)
streamListener
- the stream listenerpublic void removeAlpacaStreamListener(AlpacaStreamListener streamListener)
streamListener
- the stream listenerpublic java.lang.String toString()
toString
in class java.lang.Object