tests and flake8 compliance
This commit is contained in:
parent
735356197d
commit
2f6673fbe7
@ -247,7 +247,7 @@ class Analyze(object):
|
|||||||
return {pair: self.populate_indicators(self.parse_ticker_dataframe(pair_data))
|
return {pair: self.populate_indicators(self.parse_ticker_dataframe(pair_data))
|
||||||
for pair, pair_data in tickerdata.items()}
|
for pair, pair_data in tickerdata.items()}
|
||||||
|
|
||||||
def trunc_num(self,f, n):
|
def trunc_num(self, f, n):
|
||||||
import math
|
import math
|
||||||
return math.floor(f * 10 ** n) / 10 ** n
|
return math.floor(f * 10 ** n) / 10 ** n
|
||||||
|
|
||||||
@ -257,5 +257,4 @@ class Analyze(object):
|
|||||||
for duration, threshold in self.strategy.minimal_roi.items():
|
for duration, threshold in self.strategy.minimal_roi.items():
|
||||||
if time_diff > duration:
|
if time_diff > duration:
|
||||||
roi_rate = (trade.open_rate * (1 + threshold)) * (1+(2.1*get_fee(trade.pair)))
|
roi_rate = (trade.open_rate * (1 + threshold)) * (1+(2.1*get_fee(trade.pair)))
|
||||||
return self.trunc_num(roi_rate,8)
|
return self.trunc_num(roi_rate, 8)
|
||||||
|
|
@ -61,7 +61,7 @@ CONF_SCHEMA = {
|
|||||||
'buy': {'type': 'number', 'minimum': 1},
|
'buy': {'type': 'number', 'minimum': 1},
|
||||||
'sell': {'type': 'number', 'minimum': 1}
|
'sell': {'type': 'number', 'minimum': 1}
|
||||||
},
|
},
|
||||||
'required': ['buy','sell']
|
'required': ['buy', 'sell']
|
||||||
},
|
},
|
||||||
'bid_strategy': {
|
'bid_strategy': {
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
@ -74,9 +74,9 @@ CONF_SCHEMA = {
|
|||||||
},
|
},
|
||||||
'use_book_order': {'type': 'boolean'},
|
'use_book_order': {'type': 'boolean'},
|
||||||
'book_order_top': {'type': 'number', 'maximum': 20, 'minimum': 1},
|
'book_order_top': {'type': 'number', 'maximum': 20, 'minimum': 1},
|
||||||
'percent_from_top' : {'type': 'number', 'minimum': 0}
|
'percent_from_top': {'type': 'number', 'minimum': 0}
|
||||||
},
|
},
|
||||||
'required': ['ask_last_balance','use_book_order']
|
'required': ['ask_last_balance', 'use_book_order']
|
||||||
},
|
},
|
||||||
'ask_strategy': {
|
'ask_strategy': {
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
|
@ -244,9 +244,8 @@ class FreqtradeBot(object):
|
|||||||
:param ticker: Ticker to use for getting Ask and Last Price
|
:param ticker: Ticker to use for getting Ask and Last Price
|
||||||
:return: float: Price
|
:return: float: Price
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ticker = exchange.get_ticker(pair)
|
ticker = exchange.get_ticker(pair)
|
||||||
logger.info('ticker data %s',ticker)
|
logger.info('ticker data %s', ticker)
|
||||||
|
|
||||||
if ticker['ask'] < ticker['last']:
|
if ticker['ask'] < ticker['last']:
|
||||||
ticker_rate = ticker['ask']
|
ticker_rate = ticker['ask']
|
||||||
@ -258,24 +257,28 @@ class FreqtradeBot(object):
|
|||||||
|
|
||||||
if self.config['bid_strategy']['use_book_order']:
|
if self.config['bid_strategy']['use_book_order']:
|
||||||
logger.info('Getting price from Order Book')
|
logger.info('Getting price from Order Book')
|
||||||
orderBook = exchange.get_order_book(pair,self.config['bid_strategy']['book_order_top'])
|
orderBook = exchange.get_order_book(pair, self.config['bid_strategy']['book_order_top'])
|
||||||
orderBook_rate = orderBook['bids'][self.config['bid_strategy']['book_order_top']][0]
|
orderBook_rate = orderBook['bids'][self.config['bid_strategy']['book_order_top']][0]
|
||||||
orderBook_rate = orderBook_rate+0.00000001
|
orderBook_rate = orderBook_rate+0.00000001
|
||||||
# if ticker has lower rate, then use ticker ( usefull if down trending )
|
# if ticker has lower rate, then use ticker ( usefull if down trending )
|
||||||
logger.info('...book order bid rate %0.8f',orderBook_rate)
|
logger.info('...book order bid rate %0.8f', orderBook_rate)
|
||||||
if ticker_rate < orderBook_rate:
|
if ticker_rate < orderBook_rate:
|
||||||
logger.info('...using ticker rate instead %0.8f',ticker_rate )
|
logger.info('...using ticker rate instead %0.8f', ticker_rate)
|
||||||
used_rate = ticker_rate
|
used_rate = ticker_rate
|
||||||
used_rate = orderBook_rate
|
used_rate = orderBook_rate
|
||||||
else:
|
else:
|
||||||
logger.info('Using Last Ask / Last Price')
|
logger.info('Using Last Ask / Last Price')
|
||||||
used_rate = ticker_rate
|
used_rate = ticker_rate
|
||||||
|
|
||||||
logger.info('used rate %0.8f',used_rate)
|
logger.info('used rate %0.8f', used_rate)
|
||||||
|
|
||||||
|
logger.info('percent_from_top %0.8f', self.config['bid_strategy']['percent_from_top'])
|
||||||
|
logger.info('percent_from_top %s', self.config['bid_strategy']['percent_from_top'] > 0)
|
||||||
if self.config['bid_strategy']['percent_from_top'] > 0:
|
if self.config['bid_strategy']['percent_from_top'] > 0:
|
||||||
used_rate = self.analyze.trunc_num(used_rate - (used_rate * self.config['bid_strategy']['percent_from_top']),8)
|
used_rate = used_rate - (used_rate * self.config['bid_strategy']['percent_from_top'])
|
||||||
logger.info('used rate xx %0.8f',used_rate)
|
used_rate = self.analyze.trunc_num(used_rate, 8)
|
||||||
|
logger.info('used rate xx %0.8f', used_rate)
|
||||||
|
|
||||||
return used_rate
|
return used_rate
|
||||||
|
|
||||||
def create_trade(self) -> bool:
|
def create_trade(self) -> bool:
|
||||||
@ -285,6 +288,7 @@ class FreqtradeBot(object):
|
|||||||
:return: True if a trade object has been created and persisted, False otherwise
|
:return: True if a trade object has been created and persisted, False otherwise
|
||||||
"""
|
"""
|
||||||
stake_amount = self.config['stake_amount']
|
stake_amount = self.config['stake_amount']
|
||||||
|
|
||||||
interval = self.analyze.get_ticker_interval()
|
interval = self.analyze.get_ticker_interval()
|
||||||
stake_currency = self.config['stake_currency']
|
stake_currency = self.config['stake_currency']
|
||||||
fiat_currency = self.config['fiat_display_currency']
|
fiat_currency = self.config['fiat_display_currency']
|
||||||
@ -295,8 +299,10 @@ class FreqtradeBot(object):
|
|||||||
stake_amount
|
stake_amount
|
||||||
)
|
)
|
||||||
whitelist = copy.deepcopy(self.config['exchange']['pair_whitelist'])
|
whitelist = copy.deepcopy(self.config['exchange']['pair_whitelist'])
|
||||||
|
|
||||||
# Check if stake_amount is fulfilled
|
# Check if stake_amount is fulfilled
|
||||||
if exchange.get_balance(stake_currency) < stake_amount:
|
current_balance = exchange.get_balance(self.config['stake_currency'])
|
||||||
|
if current_balance < stake_amount:
|
||||||
raise DependencyException(
|
raise DependencyException(
|
||||||
f'stake amount is not fulfilled (currency={stake_currency})')
|
f'stake amount is not fulfilled (currency={stake_currency})')
|
||||||
|
|
||||||
@ -454,7 +460,7 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \
|
|||||||
|
|
||||||
logger.info('Handling %s ...', trade)
|
logger.info('Handling %s ...', trade)
|
||||||
sell_rate = exchange.get_ticker(trade.pair)['bid']
|
sell_rate = exchange.get_ticker(trade.pair)['bid']
|
||||||
logger.info(' ticker rate %0.8f',sell_rate)
|
logger.info(' ticker rate %0.8f', sell_rate)
|
||||||
(buy, sell) = (False, False)
|
(buy, sell) = (False, False)
|
||||||
|
|
||||||
if self.config.get('experimental', {}).get('use_sell_signal'):
|
if self.config.get('experimental', {}).get('use_sell_signal'):
|
||||||
@ -463,7 +469,7 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \
|
|||||||
is_set_fullfilled_at_roi = self.config.get('experimental', {}).get('sell_fullfilled_at_roi')
|
is_set_fullfilled_at_roi = self.config.get('experimental', {}).get('sell_fullfilled_at_roi')
|
||||||
if is_set_fullfilled_at_roi:
|
if is_set_fullfilled_at_roi:
|
||||||
sell_rate = self.analyze.get_roi_rate(trade)
|
sell_rate = self.analyze.get_roi_rate(trade)
|
||||||
logger.info('trying to selling at roi rate %0.8f',sell_rate)
|
logger.info('trying to selling at roi rate %0.8f', sell_rate)
|
||||||
|
|
||||||
if self.config['ask_strategy']['use_book_order'] and not is_set_fullfilled_at_roi:
|
if self.config['ask_strategy']['use_book_order'] and not is_set_fullfilled_at_roi:
|
||||||
logger.info('Using order book for selling...')
|
logger.info('Using order book for selling...')
|
||||||
@ -472,13 +478,13 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \
|
|||||||
orderBook_min = self.config['ask_strategy']['book_order_min']
|
orderBook_min = self.config['ask_strategy']['book_order_min']
|
||||||
orderBook_max = self.config['ask_strategy']['book_order_max']
|
orderBook_max = self.config['ask_strategy']['book_order_max']
|
||||||
|
|
||||||
orderBook = exchange.get_order_book(trade.pair,orderBook_max)
|
orderBook = exchange.get_order_book(trade.pair, orderBook_max)
|
||||||
|
|
||||||
for i in range(orderBook_min, orderBook_max+1):
|
for i in range(orderBook_min, orderBook_max+1):
|
||||||
orderBook_rate = orderBook['asks'][i-1][0]
|
orderBook_rate = orderBook['asks'][i-1][0]
|
||||||
# if orderbook has higher rate (high profit),
|
# if orderbook has higher rate (high profit),
|
||||||
# use orderbook, otherwise just use bids rate
|
# use orderbook, otherwise just use bids rate
|
||||||
logger.info(' order book asks top %s: %0.8f',i,orderBook_rate)
|
logger.info(' order book asks top %s: %0.8f', i, orderBook_rate)
|
||||||
if (sell_rate < orderBook_rate):
|
if (sell_rate < orderBook_rate):
|
||||||
sell_rate = orderBook_rate
|
sell_rate = orderBook_rate
|
||||||
|
|
||||||
@ -528,7 +534,7 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \
|
|||||||
ordertime = arrow.get(order['datetime']).datetime
|
ordertime = arrow.get(order['datetime']).datetime
|
||||||
|
|
||||||
# Check if trade is still actually open
|
# Check if trade is still actually open
|
||||||
if (int(order['filled']) == 0) and (order['status'] == 'open'):
|
if (order['status'] == 'open'):
|
||||||
if order['side'] == 'buy' and ordertime < buy_timeoutthreashold:
|
if order['side'] == 'buy' and ordertime < buy_timeoutthreashold:
|
||||||
self.handle_timedout_limit_buy(trade, order)
|
self.handle_timedout_limit_buy(trade, order)
|
||||||
elif order['side'] == 'sell' and ordertime < sell_timeoutthreashold:
|
elif order['side'] == 'sell' and ordertime < sell_timeoutthreashold:
|
||||||
|
@ -98,6 +98,7 @@ def default_conf():
|
|||||||
"use_book_order": False,
|
"use_book_order": False,
|
||||||
"book_order_top": 6,
|
"book_order_top": 6,
|
||||||
"ask_last_balance": 0.0,
|
"ask_last_balance": 0.0,
|
||||||
|
"percent_from_top": 0.0
|
||||||
},
|
},
|
||||||
"ask_strategy": {
|
"ask_strategy": {
|
||||||
"use_book_order": False,
|
"use_book_order": False,
|
||||||
|
@ -499,7 +499,12 @@ def test_balance_fully_ask_side(mocker) -> None:
|
|||||||
"""
|
"""
|
||||||
Test get_target_bid() method
|
Test get_target_bid() method
|
||||||
"""
|
"""
|
||||||
param = {'use_book_order': False, 'book_order_top': 6, 'ask_last_balance': 0.0}
|
param = {
|
||||||
|
'use_book_order': False,
|
||||||
|
'book_order_top': 6,
|
||||||
|
'ask_last_balance': 0.0,
|
||||||
|
'percent_from_top': 0
|
||||||
|
}
|
||||||
freqtrade = get_patched_freqtradebot(mocker, {'bid_strategy': param})
|
freqtrade = get_patched_freqtradebot(mocker, {'bid_strategy': param})
|
||||||
|
|
||||||
assert freqtrade.get_target_bid('ETH/BTC') >= 0.07
|
assert freqtrade.get_target_bid('ETH/BTC') >= 0.07
|
||||||
@ -509,7 +514,12 @@ def test_balance_fully_last_side(mocker) -> None:
|
|||||||
"""
|
"""
|
||||||
Test get_target_bid() method
|
Test get_target_bid() method
|
||||||
"""
|
"""
|
||||||
param = {'use_book_order': False, 'book_order_top': 6, 'ask_last_balance': 0.0}
|
param = {
|
||||||
|
'use_book_order': False,
|
||||||
|
'book_order_top': 6,
|
||||||
|
'ask_last_balance': 0.0,
|
||||||
|
'percent_from_top': 0
|
||||||
|
}
|
||||||
freqtrade = get_patched_freqtradebot(mocker, {'bid_strategy': param})
|
freqtrade = get_patched_freqtradebot(mocker, {'bid_strategy': param})
|
||||||
|
|
||||||
assert freqtrade.get_target_bid('ETH/BTC') >= 0.07
|
assert freqtrade.get_target_bid('ETH/BTC') >= 0.07
|
||||||
@ -519,7 +529,12 @@ def test_balance_bigger_last_ask(mocker) -> None:
|
|||||||
"""
|
"""
|
||||||
Test get_target_bid() method
|
Test get_target_bid() method
|
||||||
"""
|
"""
|
||||||
param = {'use_book_order': False, 'book_order_top': 6, 'ask_last_balance': 0.0}
|
param = {
|
||||||
|
'use_book_order': False,
|
||||||
|
'book_order_top': 6,
|
||||||
|
'ask_last_balance': 0.0,
|
||||||
|
'percent_from_top': 0.00
|
||||||
|
}
|
||||||
freqtrade = get_patched_freqtradebot(mocker, {'bid_strategy': param})
|
freqtrade = get_patched_freqtradebot(mocker, {'bid_strategy': param})
|
||||||
|
|
||||||
assert freqtrade.get_target_bid('ETH/BTC') >= 0.07
|
assert freqtrade.get_target_bid('ETH/BTC') >= 0.07
|
||||||
|
Loading…
Reference in New Issue
Block a user