correlation between position and orders

methetrader
Is there a way to figure out a list of all trades that have contributed to an open position?
Both orders and trades have an order_id attribute, so one can correlate trades to orders.
My use case is that I want to run two strategies, say strategyA and strategyB. I can tag the orders as strategyA or strategyB. However, when an exit signal has come for a strategy , say for strategyA , I want to exit only those positions that have been created as a result of strategyA . For this, I need to look at my open positions and see how many of these positions have been created as a result of strategyA .
I can always look at the num of bought and sold orders for each strategy and correlate that with the open positions but that gets tricky with new orders and trades being created while I am performing these calculations.
The best way would be to explore a link between potions and orders. Is such a link present?.
Thanks.
  • SRIJAN
    There is no api for correlation between positions and orders.
    You have to handle this at your end.

    Like for example,for strategy A,
    You can tag all orders fired from this strategy with a tag let's say 'Strategy A',then fetch orderbook and filter all the completed orders according to this tag 'Strategy A'. Get the quantity from every order and add all the quantities.
    Then send square off order for that quantity.
  • methetrader
    is there an explicit square off api? or do I buy for sell and sell for buy?
  • SRIJAN
    There is no specific api. You have to place a reverse transaction type order to square off.
Sign In or Register to comment.