duality-labs / hapi-indexer

A Node.js based indexer for the Duality Cosmos chain
1 stars 0 forks source link

fix: swap high and low values when token order is inverted #70

Closed dib542 closed 6 months ago

dib542 commented 6 months ago

Previously the price in ["open", "high", "low", "close"] tick index format (price = 1.0001^tickIndex) would not make sense if viewing a price timeseries where the tokens are in the reversed order from how they are stored in the database.

Example: excerpt from /timeseries/price/A/B

{
  "shape": [
    ["time_unix", ["open", "high", "low", "close"]]
  ],
  "data": [
    [1703705820, [-12080, -4829, -12080, -4829]]
  ]
}

reversed: /timeseries/price/B/A

{
  "shape": [
    ["time_unix", ["open", "high", "low", "close"]]
  ],
  "data": [
    [1703705820, [12080, 4829, 12080, 4829]]
  ]
}

This PR changes this behavior to give the correct high and low values with the token ratio viewed in both directions.