Market history plugin incorrectly calculates OHLCV values
Query to consider:
curl -s --data '{"jsonrpc":"2.0", "method":"market_history_api.get_market_history", "params":{"bucket_seconds":86400,"start":"2018-01-01T00:00:00","end":"2018-01-02T00:00:00"}, "id":1}' https://api.hive.blog | jq
Result:
{
"jsonrpc": "2.0",
"result": {
"buckets": [
{
"id": 793307,
"open": "2018-01-01T00:00:00",
"seconds": 86400,
"hive": {
"high": 1,
"low": 5,
"open": 25650,
"close": 1691,
"volume": 111698586
},
"non_hive": {
"high": 1,
"low": 1,
"open": 10192,
"close": 801,
"volume": 46183343
}
}
]
},
"id": 1
}
Returned OHLCV values are obviously incorrect (it's enough to say that high
value is the lowest one). It's because of incorrect implementation of market_history_plugin_impl::on_post_apply_operation
:
b.hive.volume += op.open_pays.amount;
b.hive.close = op.open_pays.amount;
b.non_hive.volume += op.current_pays.amount;
b.non_hive.close = op.current_pays.amount;
Amount
property should be only used to update the volume
, for everything else we need to calculate real price of traded assets.
Incorrect code affects at least get_ticker
(latest
price) and get_market_history
APIs. When fixed, it should be possible to use get_market_history
to draw candlestick charts for internal market.