-
Notifications
You must be signed in to change notification settings - Fork 45
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
base: master
Are you sure you want to change the base?
Conversation
Get volume data from more reasonable fields
@@ -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: may logically return duplicate data since not filtering by `is_maker == true` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The restriction below (L121) ensured that it does not return duplicates
Q('term', operation_history__op_object__fill_price__quote__asset_id__keyword=config.CORE_ASSET_ID)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The duplication is logical, because on every order match, two fill_order_operation
entries are stored, one for each side, and their fill_price
is exactly the same. So the fill_price__quote__asset_id
filter does not work as intended. The receives__asset_id
filter (my code) may work.
We should not filter by is_maker
here though. Actually we need the duplicate data. I'll update the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yea I remember... The explorer API that I am using for blocksights is a complete rewrite
def get_markets(from_date, to_date, base=None, quote=None):
...
s = s.extra(size=0)
s = s.source([])
s = s.filter(
Q('term', operation_type=4) &
Q('range', block_data__block_time={'gte': from_date, 'lte': to_date})
)
if base:
s = s.filter(
Q('term', operation_history__op_object__pays__asset_id=base)
)
if quote:
s = s.filter(
Q('term', operation_history__op_object__receives__asset_id=quote)
)
a = A(
"composite",
sources=[
{ "base_asset_id": { "terms" : { "field": "operation_history.op_object.pays.asset_id.keyword" } } },
{ "quote_asset_id": { "terms" : { "field": "operation_history.op_object.receives.asset_id.keyword" } } }
],
size=10000
).metric(
'base_volume', 'sum', field='operation_history.op_object.pays.amount'
).metric(
'quote_volume', 'sum', field='operation_history.op_object.receives.amount'
)
s.aggs.bucket(
'pairs',
a
)
response = s.execute()
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's correct then.
So I think the issue on blocksights is that we should not add amounts in different assets together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not add amounts in different assets together.
Should not sort by them either.
Get volume data from more reasonable fields.
By the way, since
get_markets
API is used byget_most_active_markets
and volume of different assets gets added up, there might still be issues.