Calculate running M2M

jeevansevar
hi Sujit i tried calculating running m2m for live positions every second using this formula pnl = (sellValue - buyValue) + (netQuantity * lastPrice * multiplier);

but still i am not getting updated M2M
Tagged:
  • sujith
    How are you getting the last price?
  • jeevansevar
    Last price i get in getposition api only ... one of property of position data
  • jeevansevar
    Convert.ToDouble((item.SellValue - item.BuyValue) + (item.Quantity * item.LastPrice * item.Multiplier));
    here is code snip
    /* here item refers to position data
  • sujith
    You need to fetch the latest last price from the Quote API or Websockets.
  • jeevansevar
    yes it works with that, but logically it should fatch correct lastprice as well with position API... even PNL also should have calculated in position API itself .. jsut an suggestion ..
    simply need to make extra call
  • sujith
    One shouldn't poll positions API just to get the latest P&L values. Apps should calculate it at their end.
  • jeevansevar
    but app need to sync with running positions right .. else how do we know that what all positions are running... before calling placeorder method ..i need to check weather order already exist with same script or not ... hence i need to check positions regularly .. and PNL i need to because based on latest PNL value i do square off all positions if meet my Max PNL conditions
    you can suggest better way to do this without calling position API regularly.. even i want to reduce this call
  • sujith
    Positions only update when one places an order or modifies or when one gets an order update.
    One can fetch positions and cache it locally and keep updating the P&L using the last price fetched from Websockets API.
    An optimized solution is to fetch positions only in case of the above-mentioned events.
Sign In or Register to comment.