Difference between order(id) and position(id)
Here we discuss order and position creation and the difference between orderId
and positionId
When you decide to open a position you will first need to create an order, which instructs your broker to open a position for you when (if) certain conditions are met. You can do this by making a POST
request to /trade/account/{accountId}/orders
. If the order has been successfully accepted by the broker, you will receive an orderId
as a response. Otherwise, the response will indicate an error and no order will be created.
All non-final orders (the ones that have not been canceled or filled) can be found by querying GET /trade/account/{accountId}/orders
At this point, no position has yet been opened. If you placed a market order, a position will most likely be opened at a market price; if you placed a limit order, a position will open if your price is met, which can happen immediately, but also after minutes, hours, days, or even never.
Once a position is opened (i.e. the order is filled), the order changes it's status from "PENDING" to "FILLED"; it also stops being visible in /trade/accounts/{accountId}/orders
, and starts being visible in /trade/accounts/{accountId}/ordersHistory
. Finally, a new position is created in the system, with its own positionId
(different than the original orderId
). For a given orderId
, you will now be able to find it's matching positionId
by querying the/trade/accounts/{accountId}/ordersHistory
endpoint and finding the row where orderId
matches.
Finally, you can get the list of currently opened positions by querying the GET /trade/account/{accountId}/positions
.
You can see an example of creating an order, getting orderId, finding a corresponding positionId, (modifying) partially closing a position and closing a position in the following recipe: https://tradelocker-public-api.readme.io/v1.2/update/recipes#/
Updated about 1 month ago