Amount to precision has _amount_to_contract_size in it
This commit is contained in:
parent
ee63f12236
commit
e10ceb2362
@ -587,6 +587,7 @@ class Exchange:
|
|||||||
Re-implementation of ccxt internal methods - ensuring we can test the result is correct
|
Re-implementation of ccxt internal methods - ensuring we can test the result is correct
|
||||||
based on our definitions.
|
based on our definitions.
|
||||||
"""
|
"""
|
||||||
|
amount = self._amount_to_contract_size(pair, amount)
|
||||||
if self.markets[pair]['precision']['amount']:
|
if self.markets[pair]['precision']['amount']:
|
||||||
amount = float(decimal_to_precision(amount, rounding_mode=TRUNCATE,
|
amount = float(decimal_to_precision(amount, rounding_mode=TRUNCATE,
|
||||||
precision=self.markets[pair]['precision']['amount'],
|
precision=self.markets[pair]['precision']['amount'],
|
||||||
@ -649,9 +650,11 @@ class Exchange:
|
|||||||
|
|
||||||
if ('amount' in limits and 'min' in limits['amount']
|
if ('amount' in limits and 'min' in limits['amount']
|
||||||
and limits['amount']['min'] is not None):
|
and limits['amount']['min'] is not None):
|
||||||
|
min_stake_amounts.append(
|
||||||
self._contract_size_to_amount(
|
self._contract_size_to_amount(
|
||||||
pair,
|
pair,
|
||||||
min_stake_amounts.append(limits['amount']['min'] * price)
|
limits['amount']['min'] * price
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if not min_stake_amounts:
|
if not min_stake_amounts:
|
||||||
@ -688,7 +691,7 @@ class Exchange:
|
|||||||
def create_dry_run_order(self, pair: str, ordertype: str, side: str, amount: float,
|
def create_dry_run_order(self, pair: str, ordertype: str, side: str, amount: float,
|
||||||
rate: float, leverage: float, params: Dict = {}) -> Dict[str, Any]:
|
rate: float, leverage: float, params: Dict = {}) -> Dict[str, Any]:
|
||||||
order_id = f'dry_run_{side}_{datetime.now().timestamp()}'
|
order_id = f'dry_run_{side}_{datetime.now().timestamp()}'
|
||||||
_amount = self.amount_to_precision(pair, amount)
|
_amount = self._contract_size_to_amount(pair, self.amount_to_precision(pair, amount))
|
||||||
dry_order: Dict[str, Any] = {
|
dry_order: Dict[str, Any] = {
|
||||||
'id': order_id,
|
'id': order_id,
|
||||||
'symbol': pair,
|
'symbol': pair,
|
||||||
@ -840,15 +843,15 @@ class Exchange:
|
|||||||
|
|
||||||
def _amount_to_contract_size(self, pair: str, amount: float):
|
def _amount_to_contract_size(self, pair: str, amount: float):
|
||||||
|
|
||||||
if ('contractSize' in self._api.markets[pair]):
|
if ('contractSize' in self.markets[pair]):
|
||||||
return amount / self._api.markets[pair]['contractSize']
|
return amount / self.markets[pair]['contractSize']
|
||||||
else:
|
else:
|
||||||
return amount
|
return amount
|
||||||
|
|
||||||
def _contract_size_to_amount(self, pair: str, amount: float):
|
def _contract_size_to_amount(self, pair: str, amount: float):
|
||||||
|
|
||||||
if ('contractSize' in self._api.markets[pair]):
|
if ('contractSize' in self.markets[pair]):
|
||||||
return amount * self._api.markets[pair]['contractSize']
|
return amount * self.markets[pair]['contractSize']
|
||||||
else:
|
else:
|
||||||
return amount
|
return amount
|
||||||
|
|
||||||
@ -869,7 +872,6 @@ class Exchange:
|
|||||||
rate_for_order = self.price_to_precision(pair, rate) if needs_price else None
|
rate_for_order = self.price_to_precision(pair, rate) if needs_price else None
|
||||||
|
|
||||||
self._lev_prep(pair, leverage)
|
self._lev_prep(pair, leverage)
|
||||||
amount = self._amount_to_contract_size(pair, amount)
|
|
||||||
order = self._api.create_order(
|
order = self._api.create_order(
|
||||||
pair,
|
pair,
|
||||||
ordertype,
|
ordertype,
|
||||||
@ -1269,7 +1271,7 @@ class Exchange:
|
|||||||
# validate that markets are loaded before trying to get fee
|
# validate that markets are loaded before trying to get fee
|
||||||
if self._api.markets is None or len(self._api.markets) == 0:
|
if self._api.markets is None or len(self._api.markets) == 0:
|
||||||
self._api.load_markets()
|
self._api.load_markets()
|
||||||
|
# TODO-lev: Convert this amount to contract size?
|
||||||
return self._api.calculate_fee(symbol=symbol, type=type, side=side, amount=amount,
|
return self._api.calculate_fee(symbol=symbol, type=type, side=side, amount=amount,
|
||||||
price=price, takerOrMaker=taker_or_maker)['rate']
|
price=price, takerOrMaker=taker_or_maker)['rate']
|
||||||
except ccxt.DDoSProtection as e:
|
except ccxt.DDoSProtection as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user