diff --git a/config.json.example b/config.json.example index 7060e9881..ac4324aba 100644 --- a/config.json.example +++ b/config.json.example @@ -5,6 +5,7 @@ "fiat_display_currency": "USD", "ticker_interval" : "5m", "dry_run": false, + "disable_buy" : true, "unfilledtimeout": { "buy":10, "sell":30 diff --git a/config_full.json.example b/config_full.json.example index 5fdf7b036..299060489 100644 --- a/config_full.json.example +++ b/config_full.json.example @@ -4,6 +4,7 @@ "stake_amount": 0.05, "fiat_display_currency": "USD", "dry_run": false, + "disable_buy" : true, "ticker_interval": "5m", "minimal_roi": { "40": 0.0, diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 26e828db3..6bbc55f66 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -240,9 +240,9 @@ def get_balances() -> dict: raise OperationalException(e) @retrier -def get_order_book(pair: str, refresh: Optional[bool] = True) -> dict: +def get_order_book(pair: str, limit: Optional[int] = 1000) -> dict: try: - return _API.fetch_order_book(pair) + return _API.fetch_order_book(pair, limit) except ccxt.NotSupported as e: raise OperationalException( f'Exchange {_API.name} does not support fetching order book.' diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index d36bbefca..02a3834e1 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -159,8 +159,11 @@ class FreqtradeBot(object): state_changed |= self.process_maybe_execute_sell(trade) # Then looking for buy opportunities - if len(trades) < self.config['max_open_trades']: - state_changed = self.process_maybe_execute_buy() + if (self.config['disable_buy']): + logger.info('Buy disabled...') + else: + if len(trades) < self.config['max_open_trades']: + state_changed = self.process_maybe_execute_buy() if 'unfilledtimeout' in self.config: # Check and handle any timed out open orders @@ -244,17 +247,23 @@ class FreqtradeBot(object): :return: float: Price """ + ticker = exchange.get_ticker(pair); + if ticker['ask'] < ticker['last']: + return ticker['ask'] + balance = self.config['bid_strategy']['ask_last_balance'] + ticker_rate = ticker['ask'] + balance * (ticker['last'] - ticker['ask']) + if self.config['bid_strategy']['use_book_order']: logger.info('Getting price from Order Book') orderBook = exchange.get_order_book(pair) - return orderBook['bids'][self.config['bid_strategy']['book_order_top']][0] + orderBook_rate = orderBook['bids'][self.config['bid_strategy']['book_order_top']][0] + # if ticker has lower rate, then use ticker ( usefull if down trending ) + if ticker_rate < orderBook_rate: + return ticker_rate + return orderBook_rate else: logger.info('Using Ask / Last Price') - ticker = exchange.get_ticker(pair); - if ticker['ask'] < ticker['last']: - return ticker['ask'] - balance = self.config['bid_strategy']['ask_last_balance'] - return ticker['ask'] + balance * (ticker['last'] - ticker['ask']) + return ticker_rate def create_trade(self) -> bool: @@ -444,7 +453,10 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \ orderBook = exchange.get_order_book(trade.pair) # logger.debug('Order book %s',orderBook) for i in range(self.config['ask_strategy']['book_order_min'],self.config['ask_strategy']['book_order_max']+1): - sell_rate = orderBook['asks'][i-1][0] + orderBook_rate = orderBook['asks'][i-1][0] + # if orderbook has higher rate (high profit), use orderbook, otherwise just use sell rate + if (sell_rate < orderBook_rate): + sell_rate = orderBook_rate if self.check_sell(trade, sell_rate, buy, sell): return True break diff --git a/freqtrade/tests/conftest.py b/freqtrade/tests/conftest.py index fd4421d22..04145d531 100644 --- a/freqtrade/tests/conftest.py +++ b/freqtrade/tests/conftest.py @@ -85,7 +85,11 @@ def default_conf(): "0": 0.04 }, "stoploss": -0.10, - "unfilledtimeout": 600, + "disable_buy": False, + "unfilledtimeout": { + "buy":10, + "sell":30 + }, "bid_strategy": { "use_book_order": False, "book_order_top": 6, @@ -248,7 +252,8 @@ def limit_buy_order(): 'price': 0.00001099, 'amount': 90.99181073, 'remaining': 0.0, - 'status': 'closed' + 'status': 'closed', + 'filled':0.0 } @@ -263,7 +268,8 @@ def limit_buy_order_old(): 'price': 0.00001099, 'amount': 90.99181073, 'remaining': 90.99181073, - 'status': 'open' + 'status': 'open', + 'filled':0.0 } @@ -278,7 +284,8 @@ def limit_sell_order_old(): 'price': 0.00001099, 'amount': 90.99181073, 'remaining': 90.99181073, - 'status': 'open' + 'status': 'open', + 'filled':0.0 } @@ -293,7 +300,8 @@ def limit_buy_order_old_partial(): 'price': 0.00001099, 'amount': 90.99181073, 'remaining': 67.99181073, - 'status': 'open' + 'status': 'open', + 'filled':0.0 } diff --git a/freqtrade/tests/test_freqtradebot.py b/freqtrade/tests/test_freqtradebot.py index a2fd5260a..4ebc7bfeb 100644 --- a/freqtrade/tests/test_freqtradebot.py +++ b/freqtrade/tests/test_freqtradebot.py @@ -852,7 +852,7 @@ def test_check_handle_timedout_buy(default_conf, ticker, limit_buy_order_old, fe Trade.session.add(trade_buy) # check it does cancel buy orders over the time limit - freqtrade.check_handle_timedout(600) + freqtrade.check_handle_timedout() assert cancel_order_mock.call_count == 1 assert rpc_mock.call_count == 1 trades = Trade.query.filter(Trade.open_order_id.is_(trade_buy.open_order_id)).all() @@ -893,7 +893,7 @@ def test_check_handle_timedout_sell(default_conf, ticker, limit_sell_order_old, Trade.session.add(trade_sell) # check it does cancel sell orders over the time limit - freqtrade.check_handle_timedout(600) + freqtrade.check_handle_timedout() assert cancel_order_mock.call_count == 1 assert rpc_mock.call_count == 1 assert trade_sell.is_open is True @@ -933,7 +933,7 @@ def test_check_handle_timedout_partial(default_conf, ticker, limit_buy_order_old # check it does cancel buy orders over the time limit # note this is for a partially-complete buy order - freqtrade.check_handle_timedout(600) + freqtrade.check_handle_timedout() assert cancel_order_mock.call_count == 1 assert rpc_mock.call_count == 1 trades = Trade.query.filter(Trade.open_order_id.is_(trade_buy.open_order_id)).all() @@ -984,7 +984,7 @@ def test_check_handle_timedout_exception(default_conf, ticker, mocker, caplog) - 'recent call last):\n.*' ) - freqtrade.check_handle_timedout(600) + freqtrade.check_handle_timedout() assert filter(regexp.match, caplog.record_tuples)