From 199426460a4b1ba6bae242eff2b7b07e9f5ddfcc Mon Sep 17 00:00:00 2001 From: Yuliyan Perfanov Date: Sun, 2 Jun 2019 13:25:09 +0300 Subject: [PATCH 1/5] implemented DataProvider.orderbook() --- freqtrade/data/dataprovider.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/freqtrade/data/dataprovider.py b/freqtrade/data/dataprovider.py index df4accf93..2852cbcb0 100644 --- a/freqtrade/data/dataprovider.py +++ b/freqtrade/data/dataprovider.py @@ -85,8 +85,7 @@ class DataProvider(object): """ return latest orderbook data """ - # TODO: Implement me - pass + return self._exchange.get_order_book(pair, max) @property def runmode(self) -> RunMode: From c68fe7a6857468c8c39c4aec1110c393663b2883 Mon Sep 17 00:00:00 2001 From: Yuliyan Perfanov Date: Sun, 2 Jun 2019 13:27:44 +0300 Subject: [PATCH 2/5] example how to use best bid and ask in strategy --- user_data/strategies/test_strategy.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/user_data/strategies/test_strategy.py b/user_data/strategies/test_strategy.py index 66a5f8c09..7edaead14 100644 --- a/user_data/strategies/test_strategy.py +++ b/user_data/strategies/test_strategy.py @@ -253,6 +253,15 @@ class TestStrategy(IStrategy): dataframe['ha_low'] = heikinashi['low'] """ + # Retrieve best bid and best ask + # ------------------------------------ + """ + ob = self.dp.orderbook(metadata['pair'], 1) + print(ob) + dataframe['best_bid'] = ob['bids'][0][0] + dataframe['best_ask'] = ob['asks'][0][0] + """ + return dataframe def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: From 2e6ded06a91d8b51930d25ec9b77380c115b15a2 Mon Sep 17 00:00:00 2001 From: Yuliyan Perfanov Date: Thu, 6 Jun 2019 18:25:58 +0300 Subject: [PATCH 3/5] removed redundant print() --- user_data/strategies/test_strategy.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/user_data/strategies/test_strategy.py b/user_data/strategies/test_strategy.py index 7edaead14..6b7770a8f 100644 --- a/user_data/strategies/test_strategy.py +++ b/user_data/strategies/test_strategy.py @@ -253,15 +253,16 @@ class TestStrategy(IStrategy): dataframe['ha_low'] = heikinashi['low'] """ - # Retrieve best bid and best ask + # Retrieve best bid and best ask # ------------------------------------ """ - ob = self.dp.orderbook(metadata['pair'], 1) - print(ob) - dataframe['best_bid'] = ob['bids'][0][0] - dataframe['best_ask'] = ob['asks'][0][0] + # first check if dataprovider is available + if self.dp: + ob = self.dp.orderbook(metadata['pair'], 1) + dataframe['best_bid'] = ob['bids'][0][0] + dataframe['best_ask'] = ob['asks'][0][0] """ - + return dataframe def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: From a9ed5da369d606da23223b16bf7fcc834bb13949 Mon Sep 17 00:00:00 2001 From: Yuliyan Perfanov Date: Thu, 6 Jun 2019 18:48:26 +0300 Subject: [PATCH 4/5] added doc for DataProvider.orderbook() --- docs/strategy-customization.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/strategy-customization.md b/docs/strategy-customization.md index 51540f690..b44775dfb 100644 --- a/docs/strategy-customization.md +++ b/docs/strategy-customization.md @@ -298,6 +298,18 @@ if self.dp: !!! Warning Warning in hyperopt This option cannot currently be used during hyperopt. +#### Orderbook + +``` python +if self.dp: + if self.dp.runmode in ('live', 'dry_run'): + ob = self.dp.orderbook(metadata['pair'], 1) + dataframe['best_bid'] = ob['bids'][0][0] + dataframe['best_ask'] = ob['asks'][0][0] +``` +!Warning The order book is not part of the historic data which means backtesting and hyperopt will not work if this + method is used. + #### Available Pairs ``` python @@ -306,6 +318,7 @@ if self.dp: print(f"available {pair}, {ticker}") ``` + #### Get data for non-tradeable pairs Data for additional, informative pairs (reference pairs) can be beneficial for some strategies. From f9fe2663644cd003224919540cc95bddbee8fc36 Mon Sep 17 00:00:00 2001 From: Yuliyan Perfanov Date: Thu, 6 Jun 2019 18:52:14 +0300 Subject: [PATCH 5/5] check for runmode before retrieving the orderbook --- user_data/strategies/test_strategy.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/user_data/strategies/test_strategy.py b/user_data/strategies/test_strategy.py index 6b7770a8f..2415e43eb 100644 --- a/user_data/strategies/test_strategy.py +++ b/user_data/strategies/test_strategy.py @@ -258,9 +258,10 @@ class TestStrategy(IStrategy): """ # first check if dataprovider is available if self.dp: - ob = self.dp.orderbook(metadata['pair'], 1) - dataframe['best_bid'] = ob['bids'][0][0] - dataframe['best_ask'] = ob['asks'][0][0] + if self.dp.runmode in ('live', 'dry_run'): + ob = self.dp.orderbook(metadata['pair'], 1) + dataframe['best_bid'] = ob['bids'][0][0] + dataframe['best_ask'] = ob['asks'][0][0] """ return dataframe