diff --git a/fooltrader/api/esapi/esapi.py b/fooltrader/api/esapi/esapi.py index f9387ed..f4eaf3b 100644 --- a/fooltrader/api/esapi/esapi.py +++ b/fooltrader/api/esapi/esapi.py @@ -71,18 +71,27 @@ def es_get_user_statistic(main_chain='eos', security_id='cryptocurrency_contract return es_resp_to_payload(resp) -def es_get_accounts(main_chain='eos', user_id=None,from_idx=0, size=100, order='total'): - index = get_cryptocurrency_user_statistic_index(main_chain=main_chain) - - s = Search(using=es_client, index=index, doc_type='doc') \ - .filter('term', securityId=security_id) +def es_get_accounts(main_chain='eos', user_id=None, start_vol=None, end_vol=None, from_idx=0, size=100, + order='totalEos'): + index = '{}_account'.format(main_chain) - s = s.sort({order: {"order": "desc"}}) + if user_id: + s = Search(using=es_client, index=index, doc_type='doc') \ + .filter('term', userId=user_id) + elif start_vol and end_vol: + range = {order: {'gte': start_vol, 'lt': end_vol}} + s = Search(using=es_client, index=index, doc_type='doc') \ + .filter('range', **range) + s = s.sort({order: {"order": "desc"}}) + else: + s = Search(using=es_client, index=index, doc_type='doc') + s = s.sort({order: {"order": "desc"}}) resp = s[from_idx:from_idx + size].execute() return es_resp_to_payload(resp) + def es_get_kdata(security_item, exchange=None, the_date=None, start_date=None, end_date=None, level='day', fields=None, from_idx=0, size=500, csv=False): """ diff --git a/fooltrader/datasource/eos_account.py b/fooltrader/datasource/eos_account.py index 09eceda..3900887 100644 --- a/fooltrader/datasource/eos_account.py +++ b/fooltrader/datasource/eos_account.py @@ -21,6 +21,9 @@ es_index_mapping("eos_account", EosAccount) +def eos_acount_update_to_es(): + pass + def eos_account_to_es(): account = db.accounts count = account.count() @@ -54,7 +57,8 @@ def eos_account_to_es(): "stackedEos": stackedEos, "totalEos": totalEos, "unstackingEos": unstackingEos, - "timestamp": to_time_str(createTime) + "timestamp": to_time_str(createTime), + "updateTimestamp": to_time_str(datetime.now()) } eos_account = EosAccount(meta={'id': json_item['id'], 'index': "eos_account"}) fill_doc_type(eos_account, json_item) diff --git a/fooltrader/domain/data/es_quote.py b/fooltrader/domain/data/es_quote.py index 518b99e..5336a6e 100644 --- a/fooltrader/domain/data/es_quote.py +++ b/fooltrader/domain/data/es_quote.py @@ -167,7 +167,8 @@ class Meta: class EosAccount(BaseDocType): id = Keyword() - timestamp = Keyword() + timestamp = Date() + updateTimestamp = Date() userId = Keyword() liquidEos = Float() stackedEos = Float() diff --git a/fooltrader/rest/controller/tech.py b/fooltrader/rest/controller/tech.py index c252f6d..0e35398 100644 --- a/fooltrader/rest/controller/tech.py +++ b/fooltrader/rest/controller/tech.py @@ -58,3 +58,20 @@ def get_user_statistic(main_chain, user_id): end_date=end_date, from_idx=int(from_idx), size=int(size)) return success(result) + + +@app.route('/tech/account/', defaults={'user_id': None}, methods=['GET']) +@app.route('/tech/account//', methods=['GET']) +def get_accounts(main_chain, user_id): + start_vol = request.args.get('start_vol') + end_vol = request.args.get('end_vol') + + from_idx = request.args.get('from_idx', 0) + size = request.args.get('size', 100) + order = request.args.get('order', 'totalEos') + + result = esapi.es_get_accounts(main_chain=main_chain, user_id=user_id, + start_vol=int(start_vol), + end_vol=int(end_vol), from_idx=int(from_idx), size=int(size), order=order) + + return success(result)