Refactor get_best_pair to persistence
This commit is contained in:
parent
f20f5cebbe
commit
ab117527c9
@ -421,6 +421,15 @@ class Trade(_DECL_BASE):
|
|||||||
for pair, rate, count in pair_rates
|
for pair, rate, count in pair_rates
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_best_pair():
|
||||||
|
best_pair = Trade.session.query(
|
||||||
|
Trade.pair, func.sum(Trade.close_profit).label('profit_sum')
|
||||||
|
).filter(Trade.is_open.is_(False)) \
|
||||||
|
.group_by(Trade.pair) \
|
||||||
|
.order_by(desc('profit_sum')).first()
|
||||||
|
return best_pair
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_open_trades() -> List[Any]:
|
def get_open_trades() -> List[Any]:
|
||||||
"""
|
"""
|
||||||
|
@ -225,11 +225,7 @@ class RPC:
|
|||||||
)
|
)
|
||||||
profit_all_perc.append(profit_percent)
|
profit_all_perc.append(profit_percent)
|
||||||
|
|
||||||
best_pair = Trade.session.query(
|
best_pair = Trade.get_best_pair()
|
||||||
Trade.pair, sql.func.sum(Trade.close_profit).label('profit_sum')
|
|
||||||
).filter(Trade.is_open.is_(False)) \
|
|
||||||
.group_by(Trade.pair) \
|
|
||||||
.order_by(sql.text('profit_sum DESC')).first()
|
|
||||||
|
|
||||||
if not best_pair:
|
if not best_pair:
|
||||||
raise RPCException('no closed trade')
|
raise RPCException('no closed trade')
|
||||||
|
@ -859,3 +859,16 @@ def test_get_overall_performance(fee):
|
|||||||
assert 'pair' in res[0]
|
assert 'pair' in res[0]
|
||||||
assert 'profit' in res[0]
|
assert 'profit' in res[0]
|
||||||
assert 'count' in res[0]
|
assert 'count' in res[0]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
|
def test_get_best_pair(fee):
|
||||||
|
|
||||||
|
res = Trade.get_best_pair()
|
||||||
|
assert res is None
|
||||||
|
|
||||||
|
create_mock_trades(fee)
|
||||||
|
res = Trade.get_best_pair()
|
||||||
|
assert len(res) == 2
|
||||||
|
assert res[0] == 'ETC/BTC'
|
||||||
|
assert res[1] == 0.005
|
||||||
|
Loading…
Reference in New Issue
Block a user