def get_btc_and_eth_candles(): candles = {} candles[jh.key(exchanges.SANDBOX, 'BTCUSDT')] = { 'exchange': exchanges.SANDBOX, 'symbol': 'BTCUSDT', 'candles': fake_range_candle_from_range_prices(range(101, 200)) } candles[jh.key(exchanges.SANDBOX, 'ETHUSDT')] = { 'exchange': exchanges.SANDBOX, 'symbol': 'ETHUSDT', 'candles': fake_range_candle_from_range_prices(range(1, 100)) } return candles
def test_modifying_stop_loss_after_part_of_position_is_already_reduced_with_stop_loss( ): set_up([ (exchanges.SANDBOX, 'BTC-USDT', timeframes.MINUTE_1, 'Test14'), ]) generated_candles = fake_range_candle_from_range_prices( list(range(1, 10)) + list(range(10, 1, -1))) candles = {} key = jh.key(exchanges.SANDBOX, 'BTC-USDT') candles[key] = { 'exchange': exchanges.SANDBOX, 'symbol': 'BTC-USDT', 'candles': generated_candles } backtest_mode.run('2019-04-01', '2019-04-02', candles) assert len(store.completed_trades.trades) == 1 t1: CompletedTrade = store.completed_trades.trades[0] assert t1.type == 'long' assert t1.entry_price == 7 assert t1.exit_price == (4 * 2 + 6) / 3 assert t1.take_profit_at == 13 assert t1.stop_loss_at == (4 * 2 + 6) / 3 assert t1.qty == 1.5 assert t1.fee == 0
def get_downtrend_candles(): candles = {} candles[jh.key(exchanges.SANDBOX, 'BTC-USDT')] = { 'exchange': exchanges.SANDBOX, 'symbol': 'BTC-USDT', 'candles': fake_range_candle_from_range_prices(range(100, 10, -1)) } return candles
def get_btc_candles(): return { jh.key(exchanges.SANDBOX, 'BTC-USDT'): { 'exchange': exchanges.SANDBOX, 'symbol': 'BTC-USDT', 'candles': fake_range_candle_from_range_prices(range(1, 100)), } }
def test_sma(): close_prices = [22.27, 22.19, 22.08, 22.17, 22.18, 22.13, 22.23, 22.43, 22.24, 22.29] candles = fake_range_candle_from_range_prices(close_prices) single = ta.sma(candles, 10) seq = ta.sma(candles, 10, sequential=True) assert round(single, 2) == 22.22 assert len(seq) == len(candles) assert seq[-1] == single assert np.isnan(ta.sma(candles, 30))
def get_btc_candles(): """ :return: """ candles = {} candles[jh.key(exchanges.SANDBOX, 'BTCUSD')] = { 'exchange': exchanges.SANDBOX, 'symbol': 'BTCUSD', 'candles': fake_range_candle_from_range_prices(range(1, 100)) } return candles
def test_ema(): close_prices = [ 204.23, 205.01, 196.9, 197.33, 198.7, 199.86, 202.23, 200.3, 212.3, 210.82603059, 220.84, 218.99, 212.71, 211.01, 213.19, 212.99724894, 212.67760477, 209.85, 187.2, 184.15, 176.99, 175.9, 178.99, 150.96, 133.85, 138.18, 126.32, 125.23, 114.79, 118.73, 110.74409879, 111.72, 124.04, 118.52, 113.64, 119.65, 117.11129288, 109.23, 110.77, 102.65, 91.99 ] candles = fake_range_candle_from_range_prices(close_prices) single = ta.ema(candles, 8) seq = ta.ema(candles, 8, sequential=True) assert round(single, 3) == 108.546 assert len(seq) == len(candles) assert seq[-1] == single assert np.isnan(ta.ema(candles, 400))