2020-12-09 19:26:11 +00:00
|
|
|
from datetime import datetime, timedelta, timezone
|
|
|
|
|
2020-09-07 04:39:48 +00:00
|
|
|
from freqtrade.persistence.models import Order, Trade
|
|
|
|
|
|
|
|
|
2020-09-10 05:40:19 +00:00
|
|
|
MOCK_TRADE_COUNT = 6
|
|
|
|
|
|
|
|
|
2020-09-07 04:48:34 +00:00
|
|
|
def mock_order_1():
|
|
|
|
return {
|
|
|
|
'id': '1234',
|
|
|
|
'symbol': 'ETH/BTC',
|
|
|
|
'status': 'closed',
|
|
|
|
'side': 'buy',
|
|
|
|
'type': 'limit',
|
|
|
|
'price': 0.123,
|
2022-02-03 18:41:45 +00:00
|
|
|
'average': 0.123,
|
2020-09-07 04:48:34 +00:00
|
|
|
'amount': 123.0,
|
|
|
|
'filled': 123.0,
|
|
|
|
'remaining': 0.0,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-07 04:39:48 +00:00
|
|
|
def mock_trade_1(fee):
|
|
|
|
trade = Trade(
|
|
|
|
pair='ETH/BTC',
|
|
|
|
stake_amount=0.001,
|
|
|
|
amount=123.0,
|
|
|
|
amount_requested=123.0,
|
|
|
|
fee_open=fee.return_value,
|
|
|
|
fee_close=fee.return_value,
|
2021-02-10 18:33:39 +00:00
|
|
|
is_open=True,
|
2021-03-13 14:46:20 +00:00
|
|
|
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=17),
|
2020-09-07 04:39:48 +00:00
|
|
|
open_rate=0.123,
|
2021-04-20 10:54:22 +00:00
|
|
|
exchange='binance',
|
2020-09-07 04:39:48 +00:00
|
|
|
open_order_id='dry_run_buy_12345',
|
2021-08-26 05:25:53 +00:00
|
|
|
strategy='StrategyTestV2',
|
2021-01-01 18:38:28 +00:00
|
|
|
timeframe=5,
|
2020-09-07 04:39:48 +00:00
|
|
|
)
|
2020-09-07 04:48:34 +00:00
|
|
|
o = Order.parse_from_ccxt_object(mock_order_1(), 'ETH/BTC', 'buy')
|
|
|
|
trade.orders.append(o)
|
|
|
|
return trade
|
|
|
|
|
|
|
|
|
|
|
|
def mock_order_2():
|
|
|
|
return {
|
|
|
|
'id': '1235',
|
|
|
|
'symbol': 'ETC/BTC',
|
2020-09-07 04:39:48 +00:00
|
|
|
'status': 'closed',
|
|
|
|
'side': 'buy',
|
2020-09-07 04:48:34 +00:00
|
|
|
'type': 'limit',
|
2020-09-07 04:39:48 +00:00
|
|
|
'price': 0.123,
|
|
|
|
'amount': 123.0,
|
|
|
|
'filled': 123.0,
|
|
|
|
'remaining': 0.0,
|
2020-09-07 04:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def mock_order_2_sell():
|
|
|
|
return {
|
|
|
|
'id': '12366',
|
|
|
|
'symbol': 'ETC/BTC',
|
|
|
|
'status': 'closed',
|
|
|
|
'side': 'sell',
|
|
|
|
'type': 'limit',
|
|
|
|
'price': 0.128,
|
|
|
|
'amount': 123.0,
|
|
|
|
'filled': 123.0,
|
|
|
|
'remaining': 0.0,
|
|
|
|
}
|
2020-09-07 04:39:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def mock_trade_2(fee):
|
|
|
|
"""
|
|
|
|
Closed trade...
|
|
|
|
"""
|
|
|
|
trade = Trade(
|
|
|
|
pair='ETC/BTC',
|
|
|
|
stake_amount=0.001,
|
|
|
|
amount=123.0,
|
|
|
|
amount_requested=123.0,
|
|
|
|
fee_open=fee.return_value,
|
|
|
|
fee_close=fee.return_value,
|
|
|
|
open_rate=0.123,
|
|
|
|
close_rate=0.128,
|
|
|
|
close_profit=0.005,
|
2021-02-17 18:50:10 +00:00
|
|
|
close_profit_abs=0.000584127,
|
2021-04-20 10:54:22 +00:00
|
|
|
exchange='binance',
|
2020-09-07 04:39:48 +00:00
|
|
|
is_open=False,
|
|
|
|
open_order_id='dry_run_sell_12345',
|
2021-08-26 05:25:53 +00:00
|
|
|
strategy='StrategyTestV2',
|
2021-01-01 18:38:28 +00:00
|
|
|
timeframe=5,
|
2021-10-28 18:39:42 +00:00
|
|
|
buy_tag='TEST1',
|
2020-12-09 19:26:11 +00:00
|
|
|
sell_reason='sell_signal',
|
|
|
|
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=20),
|
2021-03-09 18:29:00 +00:00
|
|
|
close_date=datetime.now(tz=timezone.utc) - timedelta(minutes=2),
|
2020-09-07 04:39:48 +00:00
|
|
|
)
|
2020-09-10 05:40:19 +00:00
|
|
|
o = Order.parse_from_ccxt_object(mock_order_2(), 'ETC/BTC', 'buy')
|
2020-09-07 04:48:34 +00:00
|
|
|
trade.orders.append(o)
|
2020-09-10 05:40:19 +00:00
|
|
|
o = Order.parse_from_ccxt_object(mock_order_2_sell(), 'ETC/BTC', 'sell')
|
2020-09-07 04:48:34 +00:00
|
|
|
trade.orders.append(o)
|
|
|
|
return trade
|
|
|
|
|
|
|
|
|
|
|
|
def mock_order_3():
|
|
|
|
return {
|
|
|
|
'id': '41231a12a',
|
|
|
|
'symbol': 'XRP/BTC',
|
2020-09-07 04:39:48 +00:00
|
|
|
'status': 'closed',
|
|
|
|
'side': 'buy',
|
2020-09-07 04:48:34 +00:00
|
|
|
'type': 'limit',
|
|
|
|
'price': 0.05,
|
2020-09-07 04:39:48 +00:00
|
|
|
'amount': 123.0,
|
|
|
|
'filled': 123.0,
|
|
|
|
'remaining': 0.0,
|
2020-09-07 04:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def mock_order_3_sell():
|
|
|
|
return {
|
|
|
|
'id': '41231a666a',
|
|
|
|
'symbol': 'XRP/BTC',
|
2020-09-07 04:39:48 +00:00
|
|
|
'status': 'closed',
|
2020-09-07 05:41:58 +00:00
|
|
|
'side': 'sell',
|
|
|
|
'type': 'stop_loss_limit',
|
2020-09-07 04:48:34 +00:00
|
|
|
'price': 0.06,
|
2020-09-07 05:41:58 +00:00
|
|
|
'average': 0.06,
|
2020-09-07 04:39:48 +00:00
|
|
|
'amount': 123.0,
|
|
|
|
'filled': 123.0,
|
|
|
|
'remaining': 0.0,
|
2020-09-07 04:48:34 +00:00
|
|
|
}
|
2020-09-07 04:39:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def mock_trade_3(fee):
|
|
|
|
"""
|
|
|
|
Closed trade
|
|
|
|
"""
|
|
|
|
trade = Trade(
|
|
|
|
pair='XRP/BTC',
|
|
|
|
stake_amount=0.001,
|
|
|
|
amount=123.0,
|
2021-01-01 18:38:28 +00:00
|
|
|
amount_requested=123.0,
|
2020-09-07 04:39:48 +00:00
|
|
|
fee_open=fee.return_value,
|
|
|
|
fee_close=fee.return_value,
|
|
|
|
open_rate=0.05,
|
|
|
|
close_rate=0.06,
|
|
|
|
close_profit=0.01,
|
2021-02-17 18:50:10 +00:00
|
|
|
close_profit_abs=0.000155,
|
2021-04-20 10:54:22 +00:00
|
|
|
exchange='binance',
|
2020-09-07 04:39:48 +00:00
|
|
|
is_open=False,
|
2021-08-26 05:25:53 +00:00
|
|
|
strategy='StrategyTestV2',
|
2021-01-01 18:38:28 +00:00
|
|
|
timeframe=5,
|
2020-12-09 19:26:11 +00:00
|
|
|
sell_reason='roi',
|
|
|
|
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=20),
|
|
|
|
close_date=datetime.now(tz=timezone.utc),
|
2020-09-07 04:39:48 +00:00
|
|
|
)
|
2020-09-10 05:40:19 +00:00
|
|
|
o = Order.parse_from_ccxt_object(mock_order_3(), 'XRP/BTC', 'buy')
|
2020-09-07 04:39:48 +00:00
|
|
|
trade.orders.append(o)
|
2020-09-10 05:40:19 +00:00
|
|
|
o = Order.parse_from_ccxt_object(mock_order_3_sell(), 'XRP/BTC', 'sell')
|
2020-09-07 04:39:48 +00:00
|
|
|
trade.orders.append(o)
|
|
|
|
return trade
|
|
|
|
|
|
|
|
|
2020-09-07 04:48:34 +00:00
|
|
|
def mock_order_4():
|
|
|
|
return {
|
|
|
|
'id': 'prod_buy_12345',
|
|
|
|
'symbol': 'ETC/BTC',
|
|
|
|
'status': 'open',
|
|
|
|
'side': 'buy',
|
|
|
|
'type': 'limit',
|
|
|
|
'price': 0.123,
|
|
|
|
'amount': 123.0,
|
|
|
|
'filled': 0.0,
|
|
|
|
'remaining': 123.0,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-07 04:39:48 +00:00
|
|
|
def mock_trade_4(fee):
|
|
|
|
"""
|
|
|
|
Simulate prod entry
|
|
|
|
"""
|
|
|
|
trade = Trade(
|
|
|
|
pair='ETC/BTC',
|
|
|
|
stake_amount=0.001,
|
|
|
|
amount=123.0,
|
|
|
|
amount_requested=124.0,
|
|
|
|
fee_open=fee.return_value,
|
|
|
|
fee_close=fee.return_value,
|
2021-03-13 14:46:20 +00:00
|
|
|
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=14),
|
2021-02-10 18:33:39 +00:00
|
|
|
is_open=True,
|
2020-09-07 04:39:48 +00:00
|
|
|
open_rate=0.123,
|
2021-04-20 10:54:22 +00:00
|
|
|
exchange='binance',
|
2020-09-07 04:39:48 +00:00
|
|
|
open_order_id='prod_buy_12345',
|
2021-08-26 05:25:53 +00:00
|
|
|
strategy='StrategyTestV2',
|
2021-01-01 18:38:28 +00:00
|
|
|
timeframe=5,
|
2020-09-07 04:39:48 +00:00
|
|
|
)
|
2020-09-10 05:40:19 +00:00
|
|
|
o = Order.parse_from_ccxt_object(mock_order_4(), 'ETC/BTC', 'buy')
|
2020-09-07 04:39:48 +00:00
|
|
|
trade.orders.append(o)
|
2020-09-07 04:48:34 +00:00
|
|
|
return trade
|
2020-09-09 05:01:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
def mock_order_5():
|
|
|
|
return {
|
|
|
|
'id': 'prod_buy_3455',
|
|
|
|
'symbol': 'XRP/BTC',
|
|
|
|
'status': 'closed',
|
|
|
|
'side': 'buy',
|
|
|
|
'type': 'limit',
|
|
|
|
'price': 0.123,
|
|
|
|
'amount': 123.0,
|
|
|
|
'filled': 123.0,
|
|
|
|
'remaining': 0.0,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def mock_order_5_stoploss():
|
|
|
|
return {
|
|
|
|
'id': 'prod_stoploss_3455',
|
|
|
|
'symbol': 'XRP/BTC',
|
|
|
|
'status': 'open',
|
|
|
|
'side': 'sell',
|
|
|
|
'type': 'stop_loss_limit',
|
|
|
|
'price': 0.123,
|
|
|
|
'amount': 123.0,
|
|
|
|
'filled': 0.0,
|
|
|
|
'remaining': 123.0,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def mock_trade_5(fee):
|
|
|
|
"""
|
|
|
|
Simulate prod entry with stoploss
|
|
|
|
"""
|
|
|
|
trade = Trade(
|
|
|
|
pair='XRP/BTC',
|
|
|
|
stake_amount=0.001,
|
|
|
|
amount=123.0,
|
|
|
|
amount_requested=124.0,
|
|
|
|
fee_open=fee.return_value,
|
|
|
|
fee_close=fee.return_value,
|
2021-03-13 14:46:20 +00:00
|
|
|
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=12),
|
2021-02-10 18:33:39 +00:00
|
|
|
is_open=True,
|
2020-09-09 05:01:43 +00:00
|
|
|
open_rate=0.123,
|
2021-04-20 10:54:22 +00:00
|
|
|
exchange='binance',
|
2020-09-09 05:01:43 +00:00
|
|
|
strategy='SampleStrategy',
|
2021-10-28 18:39:42 +00:00
|
|
|
buy_tag='TEST1',
|
2021-04-07 15:10:20 +00:00
|
|
|
stoploss_order_id='prod_stoploss_3455',
|
|
|
|
timeframe=5,
|
2020-09-09 05:01:43 +00:00
|
|
|
)
|
2020-09-10 05:40:19 +00:00
|
|
|
o = Order.parse_from_ccxt_object(mock_order_5(), 'XRP/BTC', 'buy')
|
|
|
|
trade.orders.append(o)
|
|
|
|
o = Order.parse_from_ccxt_object(mock_order_5_stoploss(), 'XRP/BTC', 'stoploss')
|
|
|
|
trade.orders.append(o)
|
|
|
|
return trade
|
|
|
|
|
|
|
|
|
|
|
|
def mock_order_6():
|
|
|
|
return {
|
|
|
|
'id': 'prod_buy_6',
|
|
|
|
'symbol': 'LTC/BTC',
|
|
|
|
'status': 'closed',
|
|
|
|
'side': 'buy',
|
|
|
|
'type': 'limit',
|
|
|
|
'price': 0.15,
|
|
|
|
'amount': 2.0,
|
|
|
|
'filled': 2.0,
|
|
|
|
'remaining': 0.0,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def mock_order_6_sell():
|
|
|
|
return {
|
|
|
|
'id': 'prod_sell_6',
|
|
|
|
'symbol': 'LTC/BTC',
|
|
|
|
'status': 'open',
|
|
|
|
'side': 'sell',
|
|
|
|
'type': 'limit',
|
|
|
|
'price': 0.20,
|
|
|
|
'amount': 2.0,
|
|
|
|
'filled': 0.0,
|
|
|
|
'remaining': 2.0,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def mock_trade_6(fee):
|
|
|
|
"""
|
|
|
|
Simulate prod entry with open sell order
|
|
|
|
"""
|
|
|
|
trade = Trade(
|
|
|
|
pair='LTC/BTC',
|
|
|
|
stake_amount=0.001,
|
|
|
|
amount=2.0,
|
|
|
|
amount_requested=2.0,
|
2021-03-13 14:46:20 +00:00
|
|
|
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=5),
|
2020-09-10 05:40:19 +00:00
|
|
|
fee_open=fee.return_value,
|
|
|
|
fee_close=fee.return_value,
|
2021-02-10 18:33:39 +00:00
|
|
|
is_open=True,
|
2020-09-10 05:40:19 +00:00
|
|
|
open_rate=0.15,
|
2021-04-20 10:54:22 +00:00
|
|
|
exchange='binance',
|
2020-09-10 05:40:19 +00:00
|
|
|
strategy='SampleStrategy',
|
2021-10-28 18:39:42 +00:00
|
|
|
buy_tag='TEST2',
|
2020-09-10 05:40:19 +00:00
|
|
|
open_order_id="prod_sell_6",
|
2021-04-07 15:10:20 +00:00
|
|
|
timeframe=5,
|
2020-09-10 05:40:19 +00:00
|
|
|
)
|
|
|
|
o = Order.parse_from_ccxt_object(mock_order_6(), 'LTC/BTC', 'buy')
|
2020-09-09 05:01:43 +00:00
|
|
|
trade.orders.append(o)
|
2020-09-10 06:03:26 +00:00
|
|
|
o = Order.parse_from_ccxt_object(mock_order_6_sell(), 'LTC/BTC', 'sell')
|
2020-09-09 05:01:43 +00:00
|
|
|
trade.orders.append(o)
|
|
|
|
return trade
|