Skip to content

Commit

Permalink
eos account api
Browse files Browse the repository at this point in the history
  • Loading branch information
foolcage committed Aug 9, 2018
1 parent 9f21315 commit 86f32f8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
21 changes: 15 additions & 6 deletions fooltrader/api/esapi/esapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
6 changes: 5 additions & 1 deletion fooltrader/datasource/eos_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion fooltrader/domain/data/es_quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ class Meta:

class EosAccount(BaseDocType):
id = Keyword()
timestamp = Keyword()
timestamp = Date()
updateTimestamp = Date()
userId = Keyword()
liquidEos = Float()
stackedEos = Float()
Expand Down
17 changes: 17 additions & 0 deletions fooltrader/rest/controller/tech.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<main_chain>', defaults={'user_id': None}, methods=['GET'])
@app.route('/tech/account/<main_chain>/<user_id>', 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)

0 comments on commit 86f32f8

Please sign in to comment.