trades history RPC
This commit is contained in:
parent
2915917680
commit
0a14d5ec46
@ -173,7 +173,8 @@ class ApiServer(RPC):
|
|||||||
view_func=self._show_config, methods=['GET'])
|
view_func=self._show_config, methods=['GET'])
|
||||||
self.app.add_url_rule(f'{BASE_URI}/ping', 'ping',
|
self.app.add_url_rule(f'{BASE_URI}/ping', 'ping',
|
||||||
view_func=self._ping, methods=['GET'])
|
view_func=self._ping, methods=['GET'])
|
||||||
|
self.app.add_url_rule(f'{BASE_URI}/trades', 'trades',
|
||||||
|
view_func=self._trades, methods=['GET'])
|
||||||
# Combined actions and infos
|
# Combined actions and infos
|
||||||
self.app.add_url_rule(f'{BASE_URI}/blacklist', 'blacklist', view_func=self._blacklist,
|
self.app.add_url_rule(f'{BASE_URI}/blacklist', 'blacklist', view_func=self._blacklist,
|
||||||
methods=['GET', 'POST'])
|
methods=['GET', 'POST'])
|
||||||
@ -357,6 +358,19 @@ class ApiServer(RPC):
|
|||||||
results = self._rpc_balance(self._config['stake_currency'],
|
results = self._rpc_balance(self._config['stake_currency'],
|
||||||
self._config.get('fiat_display_currency', ''))
|
self._config.get('fiat_display_currency', ''))
|
||||||
return self.rest_dump(results)
|
return self.rest_dump(results)
|
||||||
|
|
||||||
|
@require_login
|
||||||
|
@rpc_catch_errors
|
||||||
|
def _trades(self):
|
||||||
|
"""
|
||||||
|
Handler for /trades.
|
||||||
|
|
||||||
|
Returns the X last trades in json format
|
||||||
|
"""
|
||||||
|
last_trades_number = request.args.get('last_trades_number', 0)
|
||||||
|
last_trades_number = int(last_trades_number)
|
||||||
|
results = self._rpc_trade_history(last_trades_number)
|
||||||
|
return self.rest_dump(results)
|
||||||
|
|
||||||
@require_login
|
@require_login
|
||||||
@rpc_catch_errors
|
@rpc_catch_errors
|
||||||
|
@ -226,6 +226,53 @@ class RPC:
|
|||||||
for key, value in profit_days.items()
|
for key, value in profit_days.items()
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def _rpc_trade_history(
|
||||||
|
self, last_trades_number: int) -> List[List[Any]]:
|
||||||
|
""" Returns the X last trades """
|
||||||
|
if last_trades_number > 0:
|
||||||
|
trades = Trade.get_trades().order_by(Trade.id.desc()).limit(last_trades_number)
|
||||||
|
else:
|
||||||
|
trades = Trade.get_trades().order_by(Trade.id.desc()).all()
|
||||||
|
|
||||||
|
output = []
|
||||||
|
|
||||||
|
for trade in trades:
|
||||||
|
output.append({
|
||||||
|
'id': trade.id,
|
||||||
|
'pair': trade.pair,
|
||||||
|
'exchange': trade.exchange,
|
||||||
|
'is_open': trade.is_open if trade.is_open is not None else 0,
|
||||||
|
'open_rate': trade.open_rate,
|
||||||
|
'close_rate': trade.close_rate,
|
||||||
|
'fee_open': trade.fee_open,
|
||||||
|
'fee_close': trade.fee_close,
|
||||||
|
'open_rate_requested': trade.open_rate_requested,
|
||||||
|
'open_trade_price': trade.open_trade_price,
|
||||||
|
'close_rate_requested': trade.close_rate_requested,
|
||||||
|
'close_profit': trade.close_profit,
|
||||||
|
'close_profit_abs': trade.close_profit_abs,
|
||||||
|
'stake_amount': trade.stake_amount,
|
||||||
|
'amount': trade.amount,
|
||||||
|
'open_date': trade.open_date,
|
||||||
|
'close_date': trade.close_date,
|
||||||
|
'open_order_id': trade.open_order_id,
|
||||||
|
'stop_loss': trade.stop_loss,
|
||||||
|
'stop_loss_pct': trade.stop_loss_pct,
|
||||||
|
'initial_stop_loss': trade.initial_stop_loss,
|
||||||
|
'initial_stop_loss_pct': trade.initial_stop_loss_pct,
|
||||||
|
'stoploss_order_id': trade.stoploss_order_id,
|
||||||
|
'stoploss_last_update': trade.stoploss_last_update,
|
||||||
|
'max_rate': trade.max_rate,
|
||||||
|
'min_rate': trade.min_rate,
|
||||||
|
'sell_reason': trade.sell_reason,
|
||||||
|
'strategy': trade.strategy,
|
||||||
|
'ticker_interval': trade.ticker_interval,
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
"trades" : output
|
||||||
|
}
|
||||||
|
|
||||||
def _rpc_trade_statistics(
|
def _rpc_trade_statistics(
|
||||||
self, stake_currency: str, fiat_display_currency: str) -> Dict[str, Any]:
|
self, stake_currency: str, fiat_display_currency: str) -> Dict[str, Any]:
|
||||||
""" Returns cumulative profit statistics """
|
""" Returns cumulative profit statistics """
|
||||||
|
@ -156,6 +156,13 @@ class FtRestClient():
|
|||||||
"""
|
"""
|
||||||
return self._get("show_config")
|
return self._get("show_config")
|
||||||
|
|
||||||
|
def history(self, number=None):
|
||||||
|
"""Return the amount of open trades.
|
||||||
|
|
||||||
|
:return: json object
|
||||||
|
"""
|
||||||
|
return self._get("trades", params={"last_trades_number": number} if number else 0)
|
||||||
|
|
||||||
def whitelist(self):
|
def whitelist(self):
|
||||||
"""Show the current whitelist.
|
"""Show the current whitelist.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user