Tracking a strategy life with bracket orders

Hello!

I am struggling with tracking an order (the open position + profit target + trailing stop loss). So for my strategy, say for example I launch a market order Sell with a trailing stop of 5 points and target profit of 10 points ex:

{"s": 200, "i": 6, "d": {"orderStrategy": {"id": 11738003, "accountId": 11737, "timestamp": "2022-05-13T14:05:06.417Z", "contractId": 2553031, "orderStrategyTypeId": 2, "action": "Buy", "params": "{\"entryVersion\": {\"orderQty\": 1, \"orderType\": \"Market\", \"timeInForce\": \"Day\"}, \"brackets\": [{\"qty\": 1, \"profitTarget\": 10, \"stopLoss\": -5, \"trailingStop\": true}]}", "status": "ActiveStrategy", "archived": false, "senderId": 353801, "userSessionId": 11736}}}

So the request that I launched returned trade id: 11738003

I then seriously struggle to follow the lifecycle of where the current position is, where the limit profit target is, and where the trailing stop price is at.

I see a orderStrategyLink, which seems to link 8003 to 8004:

{"e": "props", "d": {"entityType": "orderStrategyLink", "eventType": "Created", "entity": {"id": 11738004, "orderStrategyId": 11738003, "orderId": 11738004, "label": "256"}}}

Tracking the 8004, I see:

{"e": "props", "d": {"entityType": "executionReport", "eventType": "Created", "entity": {"id": 11738007, "commandId": 11738004, "name": "1.814075112588798", "accountId": 11737, "contractId": 2553031, "timestamp": "2022-05-13T14:05:07.789Z", "orderId": 11738004, "execType": "Trade", "ordStatus": "Filled", "action": "Buy", "cumQty": 1, "avgPx": 12290.25, "lastQty": 1, "lastPx": 12290.25, "externalClOrdId": "0.8401415241415733"}}}

Which I think says a “Buy” was filled at 12290.25.

I then see the original 8003 having another strategy link to 8014 and 8016.

{"e": "props", "d": {"entityType": "orderStrategyLink", "eventType": "Created", "entity": {"id": 11738014, "orderStrategyId": 11738003, "orderId": 11738014, "label": "0"}}}

{"e": "props", "d": {"entityType": "orderStrategyLink", "eventType": "Created", "entity": {"id": 11738016, "orderStrategyId": 11738003, "orderId": 11738016, "label": "0"}}}

Looking at previous messages prior to the orderStrategyLink, I see:

{"e": "props", "d": {"entityType": "orderVersion", "eventType": "Created", "entity": {"id": 11738014, "orderId": 11738014, "orderQty": 1, "orderType": "Limit", "price": 12300.25, "timeInForce": "Day", "text": "multibracket"}}}

{"e": "props", "d": {"entityType": "orderVersion", "eventType": "Created", "entity": {"id": 11738016, "orderId": 11738016, "orderQty": 1, "orderType": "TrailingStop", "stopPrice": 12285.25, "timeInForce": "Day", "text": "multibracket"}}}

So 8016 is my trailing stop and 8014 is my target profit.

I then see the following updates:

{"e": "props", "d": {"entityType": "orderVersion", "eventType": "Created", "entity": {"id": 11738030, "orderId": 11738016, "orderQty": 1, "orderType": "TrailingStop", "stopPrice": 12286.0, "pegDifference": 3.25, "timeInForce": "Day", "text": "Trail Update"}}}
{"e": "props", "d": {"entityType": "orderVersion", "eventType": "Created", "entity": {"id": 11738033, "orderId": 11738016, "orderQty": 1, "orderType": "TrailingStop", "stopPrice": 12286.5, "pegDifference": 3.25, "timeInForce": "Day", "text": "Trail Update"}}}
{"e": "props", "d": {"entityType": "orderVersion", "eventType": "Created", "entity": {"id": 11738048, "orderId": 11738016, "orderQty": 1, "orderType": "TrailingStop", "stopPrice": 12292.0, "pegDifference": 3.25, "timeInForce": "Day", "text": "Trail Update"}}}

So the trailing stop is being updated.

I eventually see:

{"e": "props", "d": {"entityType": "executionReport", "eventType": "Created", "entity": {"id": 11738051, "commandId": 11738018, "name": "0.2803497855389074", "accountId": 11737, "contractId": 2553031, "timestamp": "2022-05-13T14:05:09.201Z", "orderId": 11738016, "execType": "Trade", "ordStatus": "Filled", "action": "Sell", "cumQty": 1, "avgPx": 12291.75, "lastQty": 1, "lastPx": 12291.75, "externalClOrdId": "0.4152835934618888"}}}

Which is the orderId of 8016 has been filled.

I then see:

{"e": "props", "d": {"entityType": "command", "eventType": "Updated", "entity": {"id": 11738059, "orderId": 11738014, "timestamp": "2022-05-13T14:05:09.209Z", "commandType": "Cancel", "commandStatus": "AtExecution", "senderId": 353801, "userSessionId": 11736}}}

8014 (the target profit) has been Canceled

{"e": "props", "d": {"entityType": "orderStrategy", "eventType": "Updated", "entity": {"id": 11738003, "accountId": 11737, "timestamp": "2022-05-13T14:05:06.417Z", "contractId": 2553031, "orderStrategyTypeId": 2, "action": "Buy", "params": "{\"entryVersion\": {\"orderQty\": 1, \"orderType\": \"Market\", \"timeInForce\": \"Day\"}, \"brackets\": [{\"qty\": 1, \"profitTarget\": 10, \"stopLoss\": -5, \"trailingStop\": true}]}", "status": "ExecutionInterrupted", "archived": false, "senderId": 353801, "userSessionId": 11736}}}

So the 8003 (the original buy order) has been “ExecutionInterrupted”

So two questions:

  1. Does anyone (or our hero @Alexander :slight_smile: ) have a typical template they follow for tracking a multi-bracket order in sort of real-time? Or is there instead some other endpoint I should be listening to that provides an update in a more straightforward way?

  2. For profit/loss, I see fill/cash balance stuff info. I first see a loss (I believe trade costs), then it eventually updates with the profit of the above trade. Any better suggestions for managing this?

{"e": "props", "d": {"entityType": "fill", "eventType": "Created", "entity": {"id": 11738051, "orderId": 11738016, "contractId": 2553031, "timestamp": "2022-05-13T14:05:09.201Z", "tradeDate": {"year": 2022, "month": 5, "day": 13}, "action": "Sell", "qty": 1, "price": 12291.75, "active": true, "finallyPaired": 0, "external": false}}}
{"e": "props", "d": {"entityType": "fillFee", "eventType": "Created", "entity": {"id": 11738051, "clearingFee": 0.09, "clearingCurrencyId": 1, "exchangeFee": 1.28, "exchangeCurrencyId": 1, "nfaFee": 0.02, "nfaCurrencyId": 1, "commission": 0.79, "commissionCurrencyId": 1}}}
{"e": "props", "d": {"entityType": "cashBalance", "eventType": "Updated", "entity": {"id": 11738001, "accountId": 11737, "timestamp": "2022-05-13T14:05:09.205Z", "tradeDate": {"year": 2022, "month": 5, "day": 13}, "currencyId": 1, "amount": 50996.54, "realizedPnL": -3.46, "weekRealizedPnL": -3.46, "archived": false}}}
{"e": "props", "d": {"entityType": "cashBalanceLog", "eventType": "Created", "entity": {"id": 11738052, "accountId": 11737, "timestamp": "2022-05-13T14:05:09.205Z", "tradeDate": {"year": 2022, "month": 5, "day": 13}, "currencyId": 1, "amount": 50996.54, "realizedPnL": -3.46, "weekRealizedPnL": -3.46, "archived": false, "cashChangeType": "ExchangeFee", "fillId": 11738051, "delta": -1.28}}}
{"e": "props", "d": {"entityType": "cashBalance", "eventType": "Updated", "entity": {"id": 11738001, "accountId": 11737, "timestamp": "2022-05-13T14:05:09.205Z", "tradeDate": {"year": 2022, "month": 5, "day": 13}, "currencyId": 1, "amount": 50996.45, "realizedPnL": -3.55, "weekRealizedPnL": -3.55, "archived": false}}}
{"e": "props", "d": {"entityType": "cashBalanceLog", "eventType": "Created", "entity": {"id": 11738053, "accountId": 11737, "timestamp": "2022-05-13T14:05:09.205Z", "tradeDate": {"year": 2022, "month": 5, "day": 13}, "currencyId": 1, "amount": 50996.45, "realizedPnL": -3.55, "weekRealizedPnL": -3.55, "archived": false, "cashChangeType": "ClearingFee", "fillId": 11738051, "delta": -0.09}}}
{"e": "props", "d": {"entityType": "cashBalance", "eventType": "Updated", "entity": {"id": 11738001, "accountId": 11737, "timestamp": "2022-05-13T14:05:09.205Z", "tradeDate": {"year": 2022, "month": 5, "day": 13}, "currencyId": 1, "amount": 50996.43, "realizedPnL": -3.57, "weekRealizedPnL": -3.57, "archived": false}}}
{"e": "props", "d": {"entityType": "cashBalanceLog", "eventType": "Created", "entity": {"id": 11738054, "accountId": 11737, "timestamp": "2022-05-13T14:05:09.205Z", "tradeDate": {"year": 2022, "month": 5, "day": 13}, "currencyId": 1, "amount": 50996.43, "realizedPnL": -3.57, "weekRealizedPnL": -3.57, "archived": false, "cashChangeType": "NfaFee", "fillId": 11738051, "delta": -0.02}}}
{"e": "props", "d": {"entityType": "cashBalance", "eventType": "Updated", "entity": {"id": 11738001, "accountId": 11737, "timestamp": "2022-05-13T14:05:09.205Z", "tradeDate": {"year": 2022, "month": 5, "day": 13}, "currencyId": 1, "amount": 50995.64, "realizedPnL": -4.36, "weekRealizedPnL": -4.36, "archived": false}}}
{"e": "props", "d": {"entityType": "cashBalanceLog", "eventType": "Created", "entity": {"id": 11738055, "accountId": 11737, "timestamp": "2022-05-13T14:05:09.205Z", "tradeDate": {"year": 2022, "month": 5, "day": 13}, "currencyId": 1, "amount": 50995.64, "realizedPnL": -4.36, "weekRealizedPnL": -4.36, "archived": false, "cashChangeType": "Commission", "fillId": 11738051, "delta": -0.79}}}
{"e": "props", "d": {"entityType": "position", "eventType": "Updated", "entity": {"id": 11738012, "accountId": 11737, "contractId": 2553031, "timestamp": "2022-05-13T14:05:07.789Z", "tradeDate": {"year": 2022, "month": 5, "day": 13}, "netPos": 1, "netPrice": 12290.25, "bought": 1, "boughtValue": 12290.25, "sold": 0, "soldValue": 0.0, "archived": true, "prevPos": 0}}}
{"e": "props", "d": {"entityType": "position", "eventType": "Updated", "entity": {"id": 11738012, "accountId": 11737, "contractId": 2553031, "timestamp": "2022-05-13T14:05:09.201Z", "tradeDate": {"year": 2022, "month": 5, "day": 13}, "netPos": 0, "bought": 1, "boughtValue": 12290.25, "sold": 1, "soldValue": 12291.75, "archived": true, "prevPos": 0}}}
{"e": "props", "d": {"entityType": "positionLog", "eventType": "Created", "entity": {"id": 11738057, "accountId": 11737, "contractId": 2553031, "timestamp": "2022-05-13T14:05:09.201Z", "tradeDate": {"year": 2022, "month": 5, "day": 13}, "netPos": 0, "bought": 1, "boughtValue": 12290.25, "sold": 1, "soldValue": 12291.75, "archived": false, "positionChangeType": "Trade", "fillId": 11738051}}}
{"e": "props", "d": {"entityType": "fillPair", "eventType": "Created", "entity": {"id": 11738056, "positionId": 11738012, "buyFillId": 11738007, "sellFillId": 11738051, "qty": 1, "buyPrice": 12290.25, "sellPrice": 12291.75, "active": true, "archived": false}}}
{"e": "props", "d": {"entityType": "cashBalance", "eventType": "Updated", "entity": {"id": 11738001, "accountId": 11737, "timestamp": "2022-05-13T14:05:09.205Z", "tradeDate": {"year": 2022, "month": 5, "day": 13}, "currencyId": 1, "amount": 51025.64, "realizedPnL": 25.64, "weekRealizedPnL": 25.64, "archived": false}}}
{"e": "props", "d": {"entityType": "cashBalanceLog", "eventType": "Created", "entity": {"id": 11738058, "accountId": 11737, "timestamp": "2022-05-13T14:05:09.205Z", "tradeDate": {"year": 2022, "month": 5, "day": 13}, "currencyId": 1, "amount": 51025.64, "realizedPnL": 25.64, "weekRealizedPnL": 25.64, "archived": false, "cashChangeType": "TradePaired", "fillPairId": 11738056, "delta": 30.0}}}

Thanks for your help!