catalyst icon indicating copy to clipboard operation
catalyst copied to clipboard

incorrect position when partially filled in live trading

Open superluminance opened this issue 7 years ago • 5 comments

Dear Catalyst Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment

  • Operating System: Windows
  • Python Version: 3.6
  • Python Bitness:
  • How did you install Catalyst: pip
  • Python packages: catalyst 0.5.20

Now that you know a little about me, let me tell you about the issue I am having:

Description of Issue

The position is not updating when an order is partially filled on HitBTC (updates: found same issue on Binance too). It will update when fully filled. For a test case, the algo sends out a sell order with -100 * xem_eth at best ask price. -10 were filled. context.portfolio.positions[context.asset].amount remains 0 till all -100 were filled.

Here is my code that does the test image , where context.cmx_risk.position is updated by calling context.portfolio.positions[context.asset].amount.

The context.cmx_exec.send_orders is my order manager who maintains order quantity and keeps the queue position. In this case, when -10 filled, the order manager sent out another order with amount of -10 to achieve the targeted -100 quantity.

In the log, the position remained 0 while order was partially filled. The position didn't change until the order was fully filled. image

  • What did you expect to happen? When partial fill happens, position updates by the filled amount.
  • What happened instead? Position doesn't update until fully filled.

Here is how you can reproduce this issue on your machine:

Reproduction Steps

  1. pick a slow moving product (I used XEM.ETH) and make algo send out a buy / sell order to make a new BBO on exchange hitbtc;
  2. manually place an opposite order on exchange with a smaller amount than it was in 1, so the algo order is now partially filled;
  3. check position, 'context.portfolio.positions[context.asset].amount'
  4. when the algo's order is fully filled, check position again.

Sincerely, Frank

superluminance avatar Sep 17 '18 22:09 superluminance

Hi @FWangTrading ,

Thanks for reporting this, we will investigate.

Lena

lenak25 avatar Sep 20 '18 15:09 lenak25

@lenak25 @EmbarAlmog Thanks for digging into this. I think this issue happens on all the supported exchanges, not only HitBTC.

superluminance avatar Oct 03 '18 16:10 superluminance

@EmbarAlmog Sorry, I unassigned you unintentionally. I changed the title and the system automatically did that.

superluminance avatar Nov 13 '18 20:11 superluminance

Are there any workarounds for this? This makes using limit orders practically unusable. Any single partial fill hoses the portfolio objects tracking.

hanibash avatar Nov 26 '18 18:11 hanibash

@hanibash I created a PnL calculator locally, which reads trade updates and calculates positions and pnls. I am surprising that no one reported the similar issue

superluminance avatar Nov 26 '18 18:11 superluminance