santiment / sanpy

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

call metric contract_interacting_addresses_count #147

Closed lhcsnelm closed 2 years ago

lhcsnelm commented 2 years ago

errors: [{'locations': [{'column': 9, 'line': 3}], 'message': '[e9204349-22a9-4215-9d5c-a28a1463351a] Can\'t fetch contract_interacting_addresses_count for project with slug celsius, Reason: "The metric \'contract_interacting_addresses_count\' must have at least one of the following fields in the selector: contractAddress"', 'path': ['query_0', 'timeseriesData']}]

san.get("{}/{}".format("contract_interacting_addresses_count", slug), contractAddress=contract_address, from_date=from_date, to_date="utc_now", interval=interval )

What is the proper format?

IvanIvanoff commented 2 years ago

This metric requires a contract address and not a slug in order to work.

@spiderjako please finish your PR https://github.com/santiment/sanpy/pull/149 that allows using custom selectors and share an example how to use this metric. You can find an example and description of the metric here: https://github.com/santiment/sanbase2/pull/3113

Meanwhile, a workaround would be to execute the graphql query directly like this:

from san.graphql import execute_gql

query = f"""{{
  getMetric(metric:"contract_transactions_count") {{
    timeseriesData(
      selector: {{contractAddress: "0x00000000219ab540356cBB839Cbe05303d7705Fa"}}
      from:"utc_now-60d"
      to:"utc_now-50d"
      interval: "1d"
    ) {{
      value
      datetime
    }}
  }}
}}"""

execute_gql(query)
IvanIvanoff commented 2 years ago

This can now be better handled with sanpy version 0.11.1. The above shared example with custom execute_gql call can now be replaced with:

import san
san.get(
  "contract_transactions_count",
  selector={"contractAddress": "0x00000000219ab540356cBB839Cbe05303d7705Fa"},
  from_date="utc_now-60d",
  to_date="utc_now",
  interval="1d"
)
datetime                    value
2022-08-28 00:00:00+00:00   54.0
2022-08-29 00:00:00+00:00  165.0
2022-08-30 00:00:00+00:00  347.0
2022-08-31 00:00:00+00:00   83.0
2022-09-01 00:00:00+00:00  979.0
...                          ...
2022-10-23 00:00:00+00:00   96.0
2022-10-24 00:00:00+00:00  128.0
2022-10-25 00:00:00+00:00  309.0
2022-10-26 00:00:00+00:00  133.0
2022-10-27 00:00:00+00:00  156.0