Align method names to internal ccxt names

These methods are reimplemented from ccxt so we can test their behaviour.
This commit is contained in:
Matthias
2020-01-12 14:55:05 +01:00
parent b60d7ad42f
commit 5fcab1eee8
8 changed files with 47 additions and 46 deletions

View File

@@ -41,7 +41,7 @@ class Binance(Exchange):
"""
ordertype = "stop_loss_limit"
stop_price = self.symbol_price_prec(pair, stop_price)
stop_price = self.price_to_precision(pair, stop_price)
# Ensure rate is less than stop price
if stop_price <= rate:
@@ -57,9 +57,9 @@ class Binance(Exchange):
params = self._params.copy()
params.update({'stopPrice': stop_price})
amount = self.symbol_amount_prec(pair, amount)
amount = self.amount_to_precision(pair, amount)
rate = self.symbol_price_prec(pair, rate)
rate = self.price_to_precision(pair, rate)
order = self._api.create_order(pair, ordertype, 'sell',
amount, rate, params)

View File

@@ -7,7 +7,6 @@ import inspect
import logging
from copy import deepcopy
from datetime import datetime, timezone
from math import ceil
from random import randint
from typing import Any, Dict, List, Optional, Tuple
@@ -368,10 +367,11 @@ class Exchange:
"""
return endpoint in self._api.has and self._api.has[endpoint]
def symbol_amount_prec(self, pair, amount: float) -> float:
def amount_to_precision(self, pair, amount: float) -> float:
'''
Returns the amount to buy or sell to a precision the Exchange accepts
Rounded down
Reimplementation of ccxt internal methods - ensuring we can test the result is correct
based on our definitions.
'''
if self.markets[pair]['precision']['amount']:
amount = float(decimal_to_precision(amount, rounding_mode=TRUNCATE,
@@ -381,10 +381,11 @@ class Exchange:
return amount
def symbol_price_prec(self, pair, price: float) -> float:
def price_to_precision(self, pair, price: float) -> float:
'''
Returns the price buying or selling with to the precision the Exchange accepts
Rounds up
Reimplementation of ccxt internal methods - ensuring we can test the result is correct
based on our definitions.
'''
if self.markets[pair]['precision']['price']:
price = float(decimal_to_precision(price, rounding_mode=ROUND,
@@ -396,7 +397,7 @@ class Exchange:
def dry_run_order(self, pair: str, ordertype: str, side: str, amount: float,
rate: float, params: Dict = {}) -> Dict[str, Any]:
order_id = f'dry_run_{side}_{randint(0, 10**6)}'
_amount = self.symbol_amount_prec(pair, amount)
_amount = self.amount_to_precision(pair, amount)
dry_order = {
"id": order_id,
'pair': pair,
@@ -431,13 +432,13 @@ class Exchange:
rate: float, params: Dict = {}) -> Dict:
try:
# Set the precision for amount and price(rate) as accepted by the exchange
amount = self.symbol_amount_prec(pair, amount)
amount = self.amount_to_precision(pair, amount)
needs_price = (ordertype != 'market'
or self._api.options.get("createMarketBuyOrderRequiresPrice", False))
rate = self.symbol_price_prec(pair, rate) if needs_price else None
rate_for_order = self.price_to_precision(pair, rate) if needs_price else None
return self._api.create_order(pair, ordertype, side,
amount, rate, params)
amount, rate_for_order, params)
except ccxt.InsufficientFunds as e:
raise DependencyException(

View File

@@ -35,8 +35,8 @@ class PrecisionFilter(IPairList):
"""
stop_price = ticker['ask'] * stoploss
# Adjust stop-prices to precision
sp = self._exchange.symbol_price_prec(ticker["symbol"], stop_price)
stop_gap_price = self._exchange.symbol_price_prec(ticker["symbol"], stop_price * 0.99)
sp = self._exchange.price_to_precision(ticker["symbol"], stop_price)
stop_gap_price = self._exchange.price_to_precision(ticker["symbol"], stop_price * 0.99)
logger.debug(f"{ticker['symbol']} - {sp} : {stop_gap_price}")
if sp <= stop_gap_price:
logger.info(f"Removed {ticker['symbol']} from whitelist, "