Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes get_markets and get_daily_volume #80

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions services/bitshares_elasticsearch_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_markets(self, from_date, to_date, base=None, quote=None):
"query": {
"bool": {
"filter": [
{ "term": { "operation_type": 4 } },
{ "term": { "operation_type": 4 } }, # NOTE: two fill_order_operation entries for each match, one for each side
{
"range": {
"block_data.block_time": {
Expand All @@ -45,21 +45,23 @@ def get_markets(self, from_date, to_date, base=None, quote=None):
"composite" : {
"size": 10000, # TODO use a generator function instead of a big size, see https://github.com/elastic/elasticsearch-dsl-py/blob/master/examples/composite_agg.py#L21
"sources" : [
{ "base": { "terms" : { "field": "operation_history.op_object.fill_price.base.asset_id.keyword" } } },
{ "quote": { "terms" : { "field": "operation_history.op_object.fill_price.quote.asset_id.keyword" } } }
{ "base": { "terms" : { "field": "operation_history.op_object.pays.asset_id.keyword" } } },
{ "quote": { "terms" : { "field": "operation_history.op_object.receives.asset_id.keyword" } } }
]
},
"aggs": {
"volume": { "sum" : { "field" : "operation_history.op_object.fill_price.quote.amount" } }
"volume": { "sum" : { "field" : "operation_history.op_object.receives.amount" } }
# NOTE: perhaps better return both `pays.amount` and `receives.amount` (in different fields but not add them together),
# because it does not make much sense to return only `receives.amount` when filtering by `pays.asset_id`.
}
}
}
}

if base:
query['query']['bool']['filter'].append({ "term": { "operation_history.op_object.fill_price.base.asset_id.keyword": base } })
query['query']['bool']['filter'].append({ "term": { "operation_history.op_object.pays.asset_id.keyword": base } })
if quote:
query['query']['bool']['filter'].append({ "term": { "operation_history.op_object.fill_price.quote.asset_id.keyword": quote } })
query['query']['bool']['filter'].append({ "term": { "operation_history.op_object.receives.asset_id.keyword": quote } })

client = connections.get_connection('operations')
response = client.search(index="bitshares-*", body=query)
Expand Down Expand Up @@ -124,11 +126,11 @@ def get_daily_volume(self, from_date, to_date):
s = s.query('bool', filter = [
Q('term', operation_type=4),
Q('range', block_data__block_time={'gte': from_date, 'lte': to_date}),
Q('term', operation_history__op_object__fill_price__quote__asset_id__keyword=config.CORE_ASSET_ID)
Q('term', operation_history__op_object__receives__asset_id__keyword=config.CORE_ASSET_ID)
])

a = A('date_histogram', field='block_data.block_time', interval='1d', format='yyyy-MM-dd') \
.metric('volume', 'sum', field='operation_history.op_object.fill_price.quote.amount')
.metric('volume', 'sum', field='operation_history.op_object.receives.amount')
s.aggs.bucket('volume_over_time', a)

response = s.execute()
Expand Down