Support limiting analyzed history

This commit is contained in:
Matthias 2020-06-15 07:53:23 +02:00
parent 9dfbc1a7ff
commit a38b33cd9c
2 changed files with 15 additions and 6 deletions

View File

@ -26,15 +26,15 @@ logger = logging.getLogger(__name__)
BASE_URI = "/api/v1"
class ArrowJSONEncoder(JSONEncoder):
class FTJSONEncoder(JSONEncoder):
def default(self, obj):
try:
if isinstance(obj, Arrow):
return obj.for_json()
elif isinstance(obj, date):
return obj.strftime("%Y-%m-%d")
elif isinstance(obj, datetime):
return obj.strftime(DATETIME_PRINT_FORMAT)
elif isinstance(obj, date):
return obj.strftime("%Y-%m-%d")
iterable = iter(obj)
except TypeError:
pass
@ -108,7 +108,7 @@ class ApiServer(RPC):
'jwt_secret_key', 'super-secret')
self.jwt = JWTManager(self.app)
self.app.json_encoder = ArrowJSONEncoder
self.app.json_encoder = FTJSONEncoder
self.app.teardown_appcontext(shutdown_session)
@ -508,9 +508,16 @@ class ApiServer(RPC):
def _analysed_history(self):
"""
Handler for /pair_history.
Takes the following get arguments:
get:
parameters:
- pair: Pair
- timeframe: Timeframe to get data for (should be aligned to strategy.timeframe)
- limit: Limit return length to the latest X candles
"""
pair = request.args.get("pair")
timeframe = request.args.get("timeframe")
limit = request.args.get("limit")
results = self._rpc_analysed_history(pair, timeframe)
results = self._rpc_analysed_history(pair, timeframe, limit)
return self.rest_dump(results)

View File

@ -654,9 +654,11 @@ class RPC:
raise RPCException('Edge is not enabled.')
return self._freqtrade.edge.accepted_pairs()
def _rpc_analysed_history(self, pair, timeframe):
def _rpc_analysed_history(self, pair, timeframe, limit):
data, last_analyzed = self._freqtrade.dataprovider.get_analyzed_dataframe(pair, timeframe)
if limit:
data = data.iloc[:-limit]
return {
'columns': data.columns,
'data': data.values.tolist(),