Implement the contract_size property

This commit is contained in:
Saleh Mir
2021-03-09 16:34:04 +01:00
parent 53992318ff
commit e3bbd8a4fc
2 changed files with 12 additions and 3 deletions

View File

@@ -1205,3 +1205,14 @@ class Strategy(ABC):
return self.position.exchange.futures_leverage
else:
raise ValueError('exchange type not supported!')
@property
def contract_size(self):
if self.position.exchange.type != 'inverse futures':
raise exceptions.InvalidStrategy(
'Only inverse futures have access to the contract_size property. You are accessing it from a {} exchange'.format(
self.position.exchange.type
)
)
return self.position.exchange.contract_size

View File

@@ -10,9 +10,7 @@ class TestCanDetectInverseFutures(Strategy):
assert self.position.exchange.type == 'inverse futures'
assert self.symbol == 'BTC-PERP'
assert self.leverage == 2
assert self.position.exchange.contract_size == 1
# TODO:
# assert self.contract_size == 1
assert self.contract_size == 1
return False