santiment / sanpy

Santiment API Python Client
MIT License
94 stars 29 forks source link

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

Closed Cortexelus closed 3 years ago

Cortexelus commented 3 years ago

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
spiderjako commented 3 years ago

@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