@@ -61,7 +61,7 @@ def __init__(self, trader, symbol_contract):
61
61
self .fee_to_close = constants .ZERO
62
62
63
63
# Size
64
- self .quantity = constants .ZERO
64
+ self .single_contract_value = constants .ONE
65
65
self .size = constants .ZERO
66
66
self .already_reduced_size = constants .ZERO
67
67
self .value = constants .ZERO
@@ -120,7 +120,7 @@ def _should_change(self, original_value, new_value):
120
120
121
121
def _update (self , position_id , symbol , currency , market , timestamp ,
122
122
entry_price , mark_price , liquidation_price ,
123
- quantity , size , value , initial_margin ,
123
+ single_contract_value , size , value , initial_margin ,
124
124
unrealized_pnl , realised_pnl , fee_to_close ,
125
125
status = None ):
126
126
changed : bool = False
@@ -141,8 +141,8 @@ def _update(self, position_id, symbol, currency, market, timestamp,
141
141
self .creation_time = self .exchange_manager .exchange .get_uniformized_timestamp (timestamp )
142
142
self .timestamp = self .creation_time
143
143
144
- if self ._should_change (self .quantity , quantity ):
145
- self .quantity = quantity
144
+ if self ._should_change (self .single_contract_value , single_contract_value ):
145
+ self .single_contract_value = single_contract_value
146
146
changed = True
147
147
148
148
if self ._should_change (self .size , size ):
@@ -186,7 +186,6 @@ def _update(self, position_id, symbol, currency, market, timestamp,
186
186
if self ._should_change (self .status .value , status ):
187
187
self .status = enums .PositionStatus (status )
188
188
189
- self ._update_quantity_or_size_if_necessary ()
190
189
# update side after quantity as it relies on self.quantity
191
190
self ._update_side (not entry_price )
192
191
self ._update_prices_if_necessary (mark_price )
@@ -408,7 +407,6 @@ def _update_size(self, size_update, realised_pnl_update=constants.ZERO,
408
407
size_update , is_closing = self ._is_update_closing (size_update ),
409
408
update_price = self .mark_price , trigger_source = trigger_source )
410
409
self ._check_and_update_size (size_update )
411
- self ._update_quantity ()
412
410
self ._update_side (True )
413
411
if self .exchange_manager .is_simulated :
414
412
margin_update = self ._update_initial_margin ()
@@ -463,19 +461,10 @@ def _check_and_update_size(self, size_update):
463
461
self .size += size_update
464
462
465
463
def _update_quantity_or_size_if_necessary (self ):
466
- """
467
- Set quantity from size if quantity is not set and size is set or update size
468
- """
469
- if self .quantity == constants .ZERO and self .size != constants .ZERO :
470
- self ._update_quantity ()
471
- elif self .size == constants .ZERO and self .quantity != constants .ZERO :
472
- self .size = self .quantity * self .symbol_contract .current_leverage
464
+ raise NotImplementedError ("_update_quantity_or_size_if_necessary not implemented" )
473
465
474
466
def _update_quantity (self ):
475
- """
476
- Update position quantity from position quantity
477
- """
478
- self .quantity = self .size / self .symbol_contract .current_leverage
467
+ raise NotImplementedError ("_update_quantity not implemented" )
479
468
480
469
def update_value (self ):
481
470
raise NotImplementedError ("update_value not implemented" )
@@ -647,7 +636,7 @@ def is_short(self):
647
636
return self .side is enums .PositionSide .SHORT
648
637
649
638
def is_idle (self ):
650
- return self .quantity == constants .ZERO
639
+ return self .size == constants .ZERO
651
640
652
641
def get_quantity_to_close (self ):
653
642
"""
@@ -713,7 +702,7 @@ def update_from_raw(self, raw_position):
713
702
mark_price = raw_position .get (enums .ExchangeConstantsPositionColumns .MARK_PRICE .value , constants .ZERO ),
714
703
liquidation_price = raw_position .get (enums .ExchangeConstantsPositionColumns .LIQUIDATION_PRICE .value ,
715
704
constants .ZERO ),
716
- quantity = raw_position .get (enums .ExchangeConstantsPositionColumns .QUANTITY .value , constants .ZERO ),
705
+ single_contract_value = raw_position .get (enums .ExchangeConstantsPositionColumns .QUANTITY .value , constants .ONE ),
717
706
size = raw_position .get (enums .ExchangeConstantsPositionColumns .SIZE .value , constants .ZERO ),
718
707
value = raw_position .get (enums .ExchangeConstantsPositionColumns .NOTIONAL .value , constants .ZERO ),
719
708
initial_margin = raw_position .get (enums .ExchangeConstantsPositionColumns .INITIAL_MARGIN .value ,
@@ -734,7 +723,7 @@ def to_dict(self):
734
723
enums .ExchangeConstantsPositionColumns .STATUS .value : self .status .value ,
735
724
enums .ExchangeConstantsPositionColumns .TIMESTAMP .value : self .timestamp ,
736
725
enums .ExchangeConstantsPositionColumns .SIDE .value : self .side .value ,
737
- enums .ExchangeConstantsPositionColumns .QUANTITY .value : self .quantity ,
726
+ enums .ExchangeConstantsPositionColumns .QUANTITY .value : self .single_contract_value ,
738
727
enums .ExchangeConstantsPositionColumns .SIZE .value : self .size ,
739
728
enums .ExchangeConstantsPositionColumns .NOTIONAL .value : self .value ,
740
729
enums .ExchangeConstantsPositionColumns .INITIAL_MARGIN .value : self .initial_margin ,
@@ -778,11 +767,11 @@ def _update_side(self, reset_entry_price):
778
767
"""
779
768
if self .symbol_contract .is_one_way_position_mode () or self .side is enums .PositionSide .UNKNOWN :
780
769
changed_side = False
781
- if self .quantity > constants .ZERO :
770
+ if self .size > constants .ZERO :
782
771
if self .side is not enums .PositionSide .LONG :
783
772
self .side = enums .PositionSide .LONG
784
773
changed_side = True
785
- elif self .quantity < constants .ZERO :
774
+ elif self .size < constants .ZERO :
786
775
if self .side is not enums .PositionSide .SHORT :
787
776
self .side = enums .PositionSide .SHORT
788
777
changed_side = True
@@ -822,7 +811,7 @@ async def reset(self):
822
811
self .entry_price = constants .ZERO
823
812
self .exit_price = constants .ZERO
824
813
self .mark_price = constants .ZERO
825
- self .quantity = constants .ZERO
814
+ self .single_contract_value = constants .ONE
826
815
self .size = constants .ZERO
827
816
self .already_reduced_size = constants .ZERO
828
817
self .value = constants .ZERO
@@ -858,7 +847,7 @@ def restore(self, other_position):
858
847
self .mark_price = other_position .mark_price
859
848
self .liquidation_price = other_position .liquidation_price
860
849
self .fee_to_close = other_position .fee_to_close
861
- self .quantity = other_position .quantity
850
+ self .single_contract_value = other_position .single_contract_value
862
851
self .size = other_position .size
863
852
self .already_reduced_size = other_position .already_reduced_size
864
853
self .value = other_position .value
0 commit comments