Freeze

API to query trade PL

Programming


My strategy need the unrealized PL of my trades to decide take profit or stop loss. 
I checked the tech doc a few times but still can't find related implementation details. 
Anyone know what is the API function??

 
Ultraman
Seems no such API yet. 
You can simply calculate using this formula: PL = Position*(market price - open price)
 
admin
Hi Freeze, sorry that the current API doesn't support query PL by trade. 
As we received a few users requesting for similar feature, we will add it into our development roadmap. 
 
Kururu
Original Posted by - b'Ultraman': Seems no such API yet. 
You can simply calculate using this formula: PL = Position*(market price - open price)
the formula also needs to multiply with  
  • contract size 
  • exchange rate if the asset currency if different from your base currency
 
admin

We are pleased to announce that this feature has been newly implemented on the platform!

For more details, please refer to the Technical Documentation: Tech Doc.

For instance, if you are utilizing a pair trading strategy that assigns a unique order reference to each pair, you can calculate the total profit and loss (PL) of a specific pair as follows:


def on_marketdatafeed(self, md, ab):

    pl = 0
    myRef = "XXX"

    _, orders, _ = self.evt.getSystemOrders()
    for tradeID in orders:
        if orders[tradeID]['orderRef']==myRef:
            pl+=orders[tradeID]['pl']

    self.evt.consoleLog('my pair trades pl is ',pl)