santiment/sanpy

batch.get transform kwarg broken; string formatting issue; temporary hack solution

Cortexelus opened this issue · 1 comments

When building a query, how do we set the transform kwarg?

For example, if I want a moving average

I would use this graphql query:

{
  getMetric(metric: "price_usd") {
    timeseriesData(
      slug: "ethereum"
      from: "2021-05-01T00:00:00Z"
      to: "2021-06-01T00:00:00Z"
      includeIncompleteData: false
      interval: "30m"
      aggregation: AVG
      transform: {type: "moving_average", moving_average_base: 100}) {
        datetime
        value
    }
  }
}

However, in sanpy Batch.get doesn't seem to be reading the transform kwarg.

batch = Batch()
batch.get(
    "price_usd/ethereum",
    from_date="2021-05-01T00:00:00Z",
    to_date="2021-06-03T00:00:00Z",
    interval="30m",
    aggregation="AVG",
    transform="{type: \"moving_average\", moving_average_base: 100}"
)
result = batch.execute()
result

Seems like a string formatting issue, because this totally hacky method of building the graphql query works as expected

batch = Batch()
batch.get(
    "price_usd/ethereum",
    from_date="2021-05-01T00:00:00Z",
    to_date="2021-06-03T00:00:00Z",
    interval="30m",
    aggregation="AVG \n  transform: {type: \"moving_average\", moving_average_base: 100}"
)
result = batch.execute()
result

@Cortexelus Thanks for pointing out the issue, you can now give the transform argument, as described in the README now:
https://github.com/santiment/sanpy/blob/master/README.md#full-list-of-metrics-for-a-single-project