Skip to content

Commit

Permalink
Merge pull request freqtrade#1686 from iuvbio/refactor/binance
Browse files Browse the repository at this point in the history
Refactor/binance
  • Loading branch information
xmatthias authored Mar 28, 2019
2 parents d09b33a + 9b22d5c commit 0a8c152
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
1 change: 1 addition & 0 deletions freqtrade/exchange/binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Binance(Exchange):

_ft_has: Dict = {
"stoploss_on_exchange": True,
"order_time_in_force": ['gtc', 'fok', 'ioc'],
}

def get_order_book(self, pair: str, limit: int = 100) -> dict:
Expand Down
20 changes: 7 additions & 13 deletions freqtrade/exchange/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,14 @@
import ccxt.async_support as ccxt_async
from pandas import DataFrame

from freqtrade import constants, OperationalException, DependencyException, TemporaryError
from freqtrade import constants, DependencyException, OperationalException, TemporaryError
from freqtrade.data.converter import parse_ticker_dataframe

logger = logging.getLogger(__name__)

API_RETRY_COUNT = 4


# Urls to exchange markets, insert quote and base with .format()
_EXCHANGE_URLS = {
ccxt.bittrex.__name__: '/Market/Index?MarketName={quote}-{base}',
ccxt.binance.__name__: '/tradeDetail.html?symbol={base}_{quote}',
}


def retrier_async(f):
async def wrapper(*args, **kwargs):
count = kwargs.pop('count', API_RETRY_COUNT)
Expand Down Expand Up @@ -72,8 +65,9 @@ class Exchange(object):
# Dict to specify which options each exchange implements
# TODO: this should be merged with attributes from subclasses
# To avoid having to copy/paste this to all subclasses.
_ft_has = {
_ft_has: Dict = {
"stoploss_on_exchange": False,
"order_time_in_force": ["gtc"],
}

def __init__(self, config: dict) -> None:
Expand Down Expand Up @@ -275,10 +269,10 @@ def validate_order_time_in_force(self, order_time_in_force: Dict) -> None:
"""
Checks if order time in force configured in strategy/config are supported
"""
if any(v != 'gtc' for k, v in order_time_in_force.items()):
if self.name != 'Binance':
raise OperationalException(
f'Time in force policies are not supporetd for {self.name} yet.')
if any(v not in self._ft_has["order_time_in_force"]
for k, v in order_time_in_force.items()):
raise OperationalException(
f'Time in force policies are not supported for {self.name} yet.')

def exchange_has(self, endpoint: str) -> bool:
"""
Expand Down
22 changes: 22 additions & 0 deletions freqtrade/tests/exchange/test_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,28 @@ def test_exchange_resolver(default_conf, mocker, caplog):
caplog.record_tuples)


def test_validate_order_time_in_force(default_conf, mocker, caplog):
caplog.set_level(logging.INFO)
# explicitly test bittrex, exchanges implementing other policies need seperate tests
ex = get_patched_exchange(mocker, default_conf, id="bittrex")
tif = {
"buy": "gtc",
"sell": "gtc",
}

ex.validate_order_time_in_force(tif)
tif2 = {
"buy": "fok",
"sell": "ioc",
}
with pytest.raises(OperationalException, match=r"Time in force.*not supported for .*"):
ex.validate_order_time_in_force(tif2)

# Patch to see if this will pass if the values are in the ft dict
ex._ft_has.update({"order_time_in_force": ["gtc", "fok", "ioc"]})
ex.validate_order_time_in_force(tif2)


def test_symbol_amount_prec(default_conf, mocker):
'''
Test rounds down to 4 Decimal places
Expand Down

0 comments on commit 0a8c152

Please sign in to comment.