public class AlpacaAPI
extends java.lang.Object
| Constructor | Description |
|---|---|
AlpacaAPI() |
Instantiates a new Alpaca API using properties specified in alpaca.properties file (or relevant
defaults)
|
AlpacaAPI(java.lang.String keyId,
java.lang.String secret,
java.lang.String baseAccountUrl) |
Instantiates a new Alpaca API using the specified keyId, secret, and baseAccountUrl.
|
AlpacaAPI(java.lang.String keyId,
java.lang.String secret,
java.lang.String baseAccountUrl,
java.lang.String baseDataUrl) |
Instantiates a new Alpaca API using the specified keyId, secret, baseAccountUrl, and
baseDataUrl.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
addAlpacaStreamListener(AlpacaStreamListener streamListener) |
Adds the alpaca stream listener.
|
boolean |
cancelOrder(java.lang.String orderId) |
Cancel order.
|
Account |
getAccount() |
Gets the account.
|
Asset |
getAssetBySymbol(java.lang.String symbol) |
Gets the asset by symbol or asset_id.
|
java.util.List<Asset> |
getAssets() |
Gets the assets using the following API defaults:
Status: Active Asset Class: us_equity.
|
java.util.List<Asset> |
getAssets(AssetStatus assetStatus,
java.lang.String assetClass) |
Gets the assets.
|
java.util.Map<java.lang.String,java.util.List<Bar>> |
getBars(BarsTimeFrame timeframe,
java.lang.String[] symbols,
java.lang.Integer limit,
java.time.LocalDateTime start,
java.time.LocalDateTime end,
java.time.LocalDateTime after,
java.time.LocalDateTime until) |
Gets the bars.
|
java.util.List<Bar> |
getBars(BarsTimeFrame timeframe,
java.lang.String symbol,
java.lang.Integer limit,
java.time.LocalDateTime start,
java.time.LocalDateTime end,
java.time.LocalDateTime after,
java.time.LocalDateTime until) |
Gets the bars.
|
java.util.List<Calendar> |
getCalendar() |
Gets the calendar.
|
java.util.List<Calendar> |
getCalendar(java.time.LocalDate start,
java.time.LocalDate end) |
Gets the calendar.
|
Clock |
getClock() |
Gets the clock.
|
Position |
getOpenPositionBySymbol(java.lang.String symbol) |
Gets the open position by symbol.
|
java.util.List<Position> |
getOpenPositions() |
Gets the open positions.
|
Order |
getOrder(java.lang.String orderId) |
Gets the order.
|
Order |
getOrderByClientId(java.lang.String clientOrderId) |
Gets the order by client id.
|
java.util.List<Order> |
getOrders() |
Gets the orders using the following API defaults:.
|
java.util.List<Order> |
getOrders(OrderStatus status,
java.lang.Integer limit,
java.time.LocalDateTime after,
java.time.LocalDateTime until,
Direction direction) |
Gets the orders.
|
void |
removeAlpacaStreamListener(AlpacaStreamListener streamListener) |
Removes the alpaca stream listener.
|
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.String clientOrderId) |
Request/Submits new order.
|
public AlpacaAPI()
public AlpacaAPI(java.lang.String keyId,
java.lang.String secret,
java.lang.String baseAccountUrl,
java.lang.String baseDataUrl)
keyId - the key idsecret - the secretbaseAccountUrl - the base account urlbaseDataUrl - the base data urlpublic AlpacaAPI(java.lang.String keyId,
java.lang.String secret,
java.lang.String baseAccountUrl)
keyId - the key idsecret - the secretbaseAccountUrl - the base account urlpublic Account getAccount() throws AlpacaAPIException
AlpacaAPIException - the alpaca API exceptionpublic java.util.List<Order> getOrders() throws AlpacaAPIException
AlpacaAPIException - the alpaca API exceptionpublic java.util.List<Order> getOrders(OrderStatus status, java.lang.Integer limit, java.time.LocalDateTime after, java.time.LocalDateTime until, Direction direction) throws AlpacaAPIException
status - the status (Open if null)limit - the limit (50 if null)after - the afteruntil - the untildirection - the direction (Descending if null)AlpacaAPIException - 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.String clientOrderId) throws AlpacaAPIException
symbol - the symbol or asset_id (required)quantity - the quantity (required)side - the side (required)type - the type (required)timeInForce - the time in force (required)limitPrice - the limit price (required if Limit or Stop Limit)stopPrice - the stop price (required if Stop or Stop Limit)clientOrderId - the client order id (optional)AlpacaAPIException - the alpaca API exceptionpublic Order getOrder(java.lang.String orderId) throws AlpacaAPIException
orderId - the order id (required)AlpacaAPIException - the alpaca API exceptionpublic Order getOrderByClientId(java.lang.String clientOrderId) throws AlpacaAPIException
clientOrderId - the client order id (required)AlpacaAPIException - the alpaca API exceptionpublic boolean cancelOrder(java.lang.String orderId)
throws AlpacaAPIException
orderId - the order id (required)AlpacaAPIException - the alpaca API exceptionpublic java.util.List<Position> getOpenPositions() throws AlpacaAPIException
AlpacaAPIException - the alpaca API exceptionpublic Position getOpenPositionBySymbol(java.lang.String symbol) throws AlpacaAPIException
symbol - the symbol or asset_id (required)AlpacaAPIException - the alpaca API exceptionpublic java.util.List<Asset> getAssets() throws AlpacaAPIException
AlpacaAPIException - the alpaca API exceptionpublic java.util.List<Asset> getAssets(AssetStatus assetStatus, java.lang.String assetClass) throws AlpacaAPIException
assetStatus - the asset status (Active if null)assetClass - the asset class (us_equity if null)AlpacaAPIException - the alpaca API exceptionpublic Asset getAssetBySymbol(java.lang.String symbol) throws AlpacaAPIException
symbol - the symbol (required)AlpacaAPIException - the alpaca API exceptionpublic java.util.List<Calendar> getCalendar() throws AlpacaAPIException
AlpacaAPIException - the alpaca API exceptionpublic java.util.List<Calendar> getCalendar(java.time.LocalDate start, java.time.LocalDate end) throws AlpacaAPIException
start - the startend - the endAlpacaAPIException - the alpaca API exceptionpublic Clock getClock() throws AlpacaAPIException
AlpacaAPIException - the alpaca API exceptionpublic java.util.Map<java.lang.String,java.util.List<Bar>> getBars(BarsTimeFrame timeframe, java.lang.String[] symbols, java.lang.Integer limit, java.time.LocalDateTime start, java.time.LocalDateTime end, java.time.LocalDateTime after, java.time.LocalDateTime until) throws AlpacaAPIException
timeframe - the timeframe (required)symbols - One or more (max 200) symbol names (required)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. (100 if null)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.AlpacaAPIException - the alpaca API exceptionpublic java.util.List<Bar> getBars(BarsTimeFrame timeframe, java.lang.String symbol, java.lang.Integer limit, java.time.LocalDateTime start, java.time.LocalDateTime end, java.time.LocalDateTime after, java.time.LocalDateTime until) throws AlpacaAPIException
timeframe - the timeframe (required)symbol - One symbol name (required)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. (100 if null)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.AlpacaAPIException - the alpaca API exceptionpublic void addAlpacaStreamListener(AlpacaStreamListener streamListener)
streamListener - the stream listenerpublic void removeAlpacaStreamListener(AlpacaStreamListener streamListener)
streamListener - the stream listener