Identifying changes of a Futures position using Websockets


I was attempting to identify changes to Future’s positions using Websockets.

  1. I am trying to record changes to the Position. To do this, should I only log changes that have a pa > 0 for the positions listed under “P”? For example, down below (in the record listing), there are 3 entries listed under “P”. Only one of them has a pa> 0 Why are these other 2 records (under “P”) listed even when they have amounts = 0? What is the purpose of the fields “cr”?

  2. I am also trying to determine when the position is closed. What rules can I follow to make sure I do this correctly?

Any help, hints or advice on how to do this would be greatly appreciated.

{'E': 1609378092165,
 'T': 1609378092162,
 'a': {'B': [{'a': 'USDT', 'cw': '9982.90119401', 'wb': '9999.96580239'}],
       'P': [{'cr': '43.59957000',       <----- what does this mean
              'ep': '0.00000',
              'iw': '0',
              'ma': 'USDT',
              'mt': 'isolated',
              'pa': '0',   <--- why is this record listed in the results under "P"
              'ps': 'BOTH',
              's': 'BTCUSDT',
              'up': '0'},
             {'cr': '780.48126002',
              'ep': '28498.01000',
              'iw': '17.06460838',
              'ma': 'USDT',
              'mt': 'isolated',
              'pa': '0.003',
              'ps': 'LONG',
              's': 'BTCUSDT',
              'up': '0.10569000'},
             {'cr': '-673.46186999',   <---- what does this mean
              'ep': '0.00000',
              'iw': '0',
              'ma': 'USDT',
              'mt': 'isolated',
              'pa': '0',      <---- why is this record listed in the results under "P"
              'ps': 'SHORT',
              's': 'BTCUSDT',
              'up': '0'}],
       'm': 'ORDER'},

You need to confirm your position mode using GET /fapi/v1/positionSide/dual; If it’s ‘one-way’ (dual is false), check the ‘pa’ in ‘ps’ == ‘BOTH’; otherwise you’d need to check ‘LONG’ and ‘SHORT’ pa; ‘cr’ means accumulated realized profit

If you understand me in your first question, this shouldn’t be hard

Thanks for the response - I was also looking for what each of the fields mean (as it is not so obvious to me):

Does “wb” mean “writing before”
Does “cw” mean “current work”
Does “cr” mean “credit”
Of course, “s” obviously means “symbol”


Any help, hints or advice would be appreciated.


“ps”:“BOTH” // BOTH position always be pushed.

I am seeing the information here:

OK, never mind. I found it here: