Add trading-volume to api schema

This commit is contained in:
Matthias 2022-06-18 16:53:25 +02:00
parent 474e6705e6
commit 0168343b76
5 changed files with 23 additions and 7 deletions

View File

@ -1363,8 +1363,7 @@ class Trade(_DECL_BASE, LocalTrade):
trading_volume = Order.query.with_entities( trading_volume = Order.query.with_entities(
func.sum(Order.cost).label('volume') func.sum(Order.cost).label('volume')
).filter( ).filter(
(Order.order_filled_date >= start_date) Order.order_filled_date >= start_date,
& (Order.status == 'closed') Order.status == 'closed'
) \ ).scalar()
.scalar()
return trading_volume return trading_volume

View File

@ -107,6 +107,7 @@ class Profit(BaseModel):
profit_factor: float profit_factor: float
max_drawdown: float max_drawdown: float
max_drawdown_abs: float max_drawdown_abs: float
trading_volume: Optional[float]
class SellReason(BaseModel): class SellReason(BaseModel):

View File

@ -29,6 +29,7 @@ def mock_order_1(is_short: bool):
'average': 0.123, 'average': 0.123,
'amount': 123.0, 'amount': 123.0,
'filled': 123.0, 'filled': 123.0,
'cost': 15.129,
'remaining': 0.0, 'remaining': 0.0,
} }
@ -65,6 +66,7 @@ def mock_order_2(is_short: bool):
'price': 0.123, 'price': 0.123,
'amount': 123.0, 'amount': 123.0,
'filled': 123.0, 'filled': 123.0,
'cost': 15.129,
'remaining': 0.0, 'remaining': 0.0,
} }
@ -79,6 +81,7 @@ def mock_order_2_sell(is_short: bool):
'price': 0.128, 'price': 0.128,
'amount': 123.0, 'amount': 123.0,
'filled': 123.0, 'filled': 123.0,
'cost': 15.129,
'remaining': 0.0, 'remaining': 0.0,
} }
@ -126,6 +129,7 @@ def mock_order_3(is_short: bool):
'price': 0.05, 'price': 0.05,
'amount': 123.0, 'amount': 123.0,
'filled': 123.0, 'filled': 123.0,
'cost': 15.129,
'remaining': 0.0, 'remaining': 0.0,
} }
@ -141,6 +145,7 @@ def mock_order_3_sell(is_short: bool):
'average': 0.06, 'average': 0.06,
'amount': 123.0, 'amount': 123.0,
'filled': 123.0, 'filled': 123.0,
'cost': 15.129,
'remaining': 0.0, 'remaining': 0.0,
} }
@ -186,6 +191,7 @@ def mock_order_4(is_short: bool):
'price': 0.123, 'price': 0.123,
'amount': 123.0, 'amount': 123.0,
'filled': 0.0, 'filled': 0.0,
'cost': 15.129,
'remaining': 123.0, 'remaining': 123.0,
} }
@ -225,6 +231,7 @@ def mock_order_5(is_short: bool):
'price': 0.123, 'price': 0.123,
'amount': 123.0, 'amount': 123.0,
'filled': 123.0, 'filled': 123.0,
'cost': 15.129,
'remaining': 0.0, 'remaining': 0.0,
} }
@ -239,6 +246,7 @@ def mock_order_5_stoploss(is_short: bool):
'price': 0.123, 'price': 0.123,
'amount': 123.0, 'amount': 123.0,
'filled': 0.0, 'filled': 0.0,
'cost': 0.0,
'remaining': 123.0, 'remaining': 123.0,
} }
@ -281,6 +289,7 @@ def mock_order_6(is_short: bool):
'price': 0.15, 'price': 0.15,
'amount': 2.0, 'amount': 2.0,
'filled': 2.0, 'filled': 2.0,
'cost': 0.3,
'remaining': 0.0, 'remaining': 0.0,
} }
@ -295,6 +304,7 @@ def mock_order_6_sell(is_short: bool):
'price': 0.15 if is_short else 0.20, 'price': 0.15 if is_short else 0.20,
'amount': 2.0, 'amount': 2.0,
'filled': 0.0, 'filled': 0.0,
'cost': 0.0,
'remaining': 2.0, 'remaining': 2.0,
} }
@ -337,6 +347,7 @@ def short_order():
'price': 0.123, 'price': 0.123,
'amount': 123.0, 'amount': 123.0,
'filled': 123.0, 'filled': 123.0,
'cost': 15.129,
'remaining': 0.0, 'remaining': 0.0,
} }
@ -351,6 +362,7 @@ def exit_short_order():
'price': 0.128, 'price': 0.128,
'amount': 123.0, 'amount': 123.0,
'filled': 123.0, 'filled': 123.0,
'cost': 15.744,
'remaining': 0.0, 'remaining': 0.0,
} }
@ -424,6 +436,7 @@ def leverage_order():
'amount': 123.0, 'amount': 123.0,
'filled': 123.0, 'filled': 123.0,
'remaining': 0.0, 'remaining': 0.0,
'cost': 15.129,
'leverage': 5.0 'leverage': 5.0
} }
@ -439,6 +452,7 @@ def leverage_order_sell():
'amount': 123.0, 'amount': 123.0,
'filled': 123.0, 'filled': 123.0,
'remaining': 0.0, 'remaining': 0.0,
'cost': 15.744,
'leverage': 5.0 'leverage': 5.0
} }

View File

@ -725,7 +725,7 @@ def test_api_edge_disabled(botclient, mocker, ticker, fee, markets):
'profit_closed_percent_mean': -0.75, 'profit_closed_ratio_sum': -0.015, 'profit_closed_percent_mean': -0.75, 'profit_closed_ratio_sum': -0.015,
'profit_closed_percent_sum': -1.5, 'profit_closed_ratio': -6.739057628404269e-06, 'profit_closed_percent_sum': -1.5, 'profit_closed_ratio': -6.739057628404269e-06,
'profit_closed_percent': -0.0, 'winning_trades': 0, 'losing_trades': 2, 'profit_closed_percent': -0.0, 'winning_trades': 0, 'losing_trades': 2,
'profit_factor': 0.0, 'profit_factor': 0.0, 'trading_volume': 91.074,
} }
), ),
( (
@ -740,7 +740,7 @@ def test_api_edge_disabled(botclient, mocker, ticker, fee, markets):
'profit_closed_percent_mean': 0.75, 'profit_closed_ratio_sum': 0.015, 'profit_closed_percent_mean': 0.75, 'profit_closed_ratio_sum': 0.015,
'profit_closed_percent_sum': 1.5, 'profit_closed_ratio': 7.391275897987988e-07, 'profit_closed_percent_sum': 1.5, 'profit_closed_ratio': 7.391275897987988e-07,
'profit_closed_percent': 0.0, 'winning_trades': 2, 'losing_trades': 0, 'profit_closed_percent': 0.0, 'winning_trades': 2, 'losing_trades': 0,
'profit_factor': None, 'profit_factor': None, 'trading_volume': 91.074,
} }
), ),
( (
@ -755,7 +755,7 @@ def test_api_edge_disabled(botclient, mocker, ticker, fee, markets):
'profit_closed_percent_mean': 0.25, 'profit_closed_ratio_sum': 0.005, 'profit_closed_percent_mean': 0.25, 'profit_closed_ratio_sum': 0.005,
'profit_closed_percent_sum': 0.5, 'profit_closed_ratio': -5.429078808526421e-06, 'profit_closed_percent_sum': 0.5, 'profit_closed_ratio': -5.429078808526421e-06,
'profit_closed_percent': -0.0, 'winning_trades': 1, 'losing_trades': 1, 'profit_closed_percent': -0.0, 'winning_trades': 1, 'losing_trades': 1,
'profit_factor': 0.02775724835771106, 'profit_factor': 0.02775724835771106, 'trading_volume': 91.074,
} }
) )
]) ])
@ -812,6 +812,7 @@ def test_api_profit(botclient, mocker, ticker, fee, markets, is_short, expected)
'profit_factor': expected['profit_factor'], 'profit_factor': expected['profit_factor'],
'max_drawdown': ANY, 'max_drawdown': ANY,
'max_drawdown_abs': ANY, 'max_drawdown_abs': ANY,
'trading_volume': expected['trading_volume'],
} }

View File

@ -2269,6 +2269,7 @@ def test_Trade_object_idem():
'get_exit_reason_performance', 'get_exit_reason_performance',
'get_enter_tag_performance', 'get_enter_tag_performance',
'get_mix_tag_performance', 'get_mix_tag_performance',
'get_trading_volume',
) )