diff --git a/services/bitshares_elasticsearch_client.py b/services/bitshares_elasticsearch_client.py index a296ffc..d2f6924 100644 --- a/services/bitshares_elasticsearch_client.py +++ b/services/bitshares_elasticsearch_client.py @@ -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": { @@ -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) @@ -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()