hbdmapi / huobi_futures_Python

An Asynchronous Event-driven High-frequency Trading System,huobi future,huobi coin margined swap, huobi usdt margined swap included.
MIT License
267 stars 113 forks source link

Open Price vs Position Price in Positions #41

Closed igkoh closed 4 years ago

igkoh commented 4 years ago

In on_event_positionupdate, position at GMT+8 12:00 settlement time in perpetual Ether swap is: [platform: huobi_swap, account: ingyukoh@gmail.com, strategy: my_test_strategy, symbol: ETH-USD/SWAP, short_quantity: 170, short_avg_price: 374.72820298727004, long_quantity: 0, long_avg_price: 0, liquidprice: None, utime: 1600661846690]

In strategy.py in huobi_option_mm, the method get_account_position is: accounts, error = await self.trader.rest_api.get_account_position(self.symbol) which is given in strategy.py in huobi_optionmm gives {'status': 'ok', 'data': [{'symbol': 'ETH', 'contract_code': 'ETH-USD', 'margin_balance': 90.1868916400575, 'margin_position': 0.4538295202755012, 'margin_frozen': 0.0559671691360006, 'margin_available': 89.677094950646, 'profit_real': 0.000941082248881205, 'profit_unreal': 0.0016737623406359, 'risk_rate': 176.75756631661787, 'withdraw_available': 89.67542118830535, 'liquidation_price': None, 'lever_rate': 10, 'adjust_factor': 0.15, 'margin_static': 90.18521787771685, 'positions': [{'symbol': 'ETH', 'contract_code': 'ETH-USD', 'volume': 170.0, 'available': 0.0, 'frozen': 170.0, 'cost_open': 374.45550419799616, 'cost_hold': 374.72820298727004, 'profit_unreal': 0.0016737623406359, 'profit_rate': -0.00359048031191001, 'lever_rate': 10, 'position_margin': 0.4538295202755012, 'direction': 'sell', 'profit': -0.0016300512241947, 'lastprice': 374.59}]}], 'ts': 1600661846860}

For the _actual cost of price of position is given accounts['data'][0]['positions']['costopen'].

I want to check my conjecture that the position price : changes to compute funding of perpetual swap 3 times a day in GMT+8: 4:00 12:00 20:00 computed from the newly added position from the last settlement time. _374.728 short_avgprice of position, changed after settlement time of refund at GMT+8: 1200 from 374.455 just prior to settlement time ( at GMT+8: 1159)

the open price : the volume weighted average price of position which does not change in settlement time. _'cost_open': 374.455, 'cost_hold': 374.728 in rest_api.get_accountposition

After closing the position, the realized PnL is computed with open price, not position price. Open price is obtained from rest_api.get_account_position, and not from position in strategy.py of huobi_swap.

Best regards, Ingyu

foonsun commented 4 years ago

Hi, @igkoh You are right.The price shall be open price.we will fix the bug.

igkoh commented 4 years ago

@foonsun, thanks.

Best regards, Ingyu

foonsun commented 4 years ago

@igkoh Hi, the bug has been fixed.