Class PositionsEndpoint
java.lang.Object
net.jacobpeterson.alpaca.rest.endpoint.AlpacaEndpoint
net.jacobpeterson.alpaca.rest.endpoint.positions.PositionsEndpoint
public class PositionsEndpoint extends AlpacaEndpoint
AlpacaEndpoint
for Positions.-
Field Summary
Fields inherited from class net.jacobpeterson.alpaca.rest.endpoint.AlpacaEndpoint
alpacaClient, endpointPathSegment
-
Constructor Summary
Constructors Constructor Description PositionsEndpoint(AlpacaClient alpacaClient)
Instantiates a newPositionsEndpoint
. -
Method Summary
Modifier and Type Method Description Order
close(String symbolOrAssetID, Integer quantity, Double percentage)
Closes (liquidates) the account’s open position for the givensymbol
.List<ClosePositionOrder>
closeAll(Boolean cancelOrders)
Closes (liquidates) all of the account’s open long and shortPosition
s.List<Position>
get()
Retrieves a list of the account's openPosition
s.Position
getBySymbol(String symbolOrAssetID)
Retrieves the account's openPosition
s for the given symbol orAsset.getId()
.
-
Constructor Details
-
PositionsEndpoint
Instantiates a newPositionsEndpoint
.- Parameters:
alpacaClient
- theAlpacaClient
-
-
Method Details
-
get
Retrieves a list of the account's openPosition
s.- Returns:
- a
List
of openPosition
s - Throws:
AlpacaClientException
- thrown forAlpacaClientException
s
-
getBySymbol
Retrieves the account's openPosition
s for the given symbol orAsset.getId()
.- Parameters:
symbolOrAssetID
- the symbol orAsset.getId()
(required)- Returns:
- the open
Position
- Throws:
AlpacaClientException
- thrown forAlpacaClientException
s
-
closeAll
Closes (liquidates) all of the account’s open long and shortPosition
s. A response will be provided for each order that is attempted to be cancelled. If an order is no longer cancelable, the server will respond with status 500 and reject the request.- Parameters:
cancelOrders
- if true is specified, cancel all open orders before liquidating all positions- Returns:
- a
List
of openClosePositionOrder
s - Throws:
AlpacaClientException
- thrown forAlpacaClientException
s
-
close
public Order close(String symbolOrAssetID, Integer quantity, Double percentage) throws AlpacaClientExceptionCloses (liquidates) the account’s open position for the givensymbol
. Works for both long and short positions.- Parameters:
symbolOrAssetID
- the symbol orAsset.getId()
quantity
- the number of shares to liquidate. Can accept up to9
decimal points. Cannot work withpercentage
.percentage
- the percentage of the position to liquidate. Must be between0
and100
. Would only sell fractional if position is originally fractional. Can accept up to9
decimal points. Cannot work withquantity
.- Returns:
- a closing
Position
Order
- Throws:
AlpacaClientException
- thrown forAlpacaClientException
s
-