How to get price data from defi on Solana

I’m trying to get real-time price data from pumpfun on the Solana network using bitquery api. However I’m met with this error, I’ve tried the examples on both v1 and v2, nothing seems to work:

{'errors': [{'message': 'Field does not exist on type. Please check your query.', 'locations': [{'line': 3, 'column': 3}], 'path': ['subscription', 'Solana'], 'extensions': {'code': 'undefinedFiel
d', 'typeName': 'Subscription', 'fieldName': 'Solana'}}], 'extensions': {'subId': 'sub-86eb1017250ec4e53cb633d4726f941eb6da5f08'}}                                                                  Traceback (most recent call last):
  File "/Users/dekahalane/Documents/GitHub/solana-trade-bot/bitquery_pump.py", line 109, in <module>
    tokenBNBprice = jsonResp['data']['solana']['tokenPrice'][0]['quotePrice']
                    ~~~~~~~~^^^^^^^^
KeyError: 'data'

here’s the link to the code ive tried:

and this:

 query getData($base0: String, $base1: String, $quote0: String){
  Solana{
    tokenPrice: dexTrades(
      baseCurrency: {is: $base0}
      quoteCurrency: {is: $quote0}
    ) {
      quotePrice
    }
    busdPrice: dexTrades(
      baseCurrency: {is: $base1}
      quoteCurrency: {is: $quote0}
    ) {
      quotePrice
    }
  }
}

params = {
  "base0"  : token_list["MILF"],
  "base1"  : token_list["PO"],
  "quote0" : token_list["SOL"]
}

json     = {"query"     : query, "variables": params}
headers  = {"X-API-KEY" : API_KEY}

response = requests.post(BASE_URL, json = json, headers = headers)
if response.status_code == 200:
  jsonResp = response.json()

Traceback:

{'errors': [{'message': 'Field does not exist on type. Please check your query.', 'locations': [{'line': 3, 'column': 3}], 'path': ['query getData', 'Solana'], 'extensions': {'code': 'undefinedField', 'typeName': 'Query', 'fieldName': 'Solana'}}, {'message': 'Variable $base0 is declared by getData but not used', 'locations': [{'line': 2, 'column': 2}], 'path': ['query getData'], 'extensions': {'code': 'variableNotUsed', 'variableName': 'base0'}}, {'message': 'Variable $base1 is declared by getData but not used', 'locations': [{'line': 2, 'column': 2}], 'path': ['query getData'], 'extensions': {'code': 'variableNotUsed', 'variableName': 'base1'}}, {'message': 'Variable $quote0 is declared by getData but not used', 'locations': [{'line': 2, 'column': 2}], 'path': ['query getData'], 'extensions': {'code': 'variableNotUsed', 'variableName': 'quote0'}}]}

Hey, you can try out this query Price of a pump fun token - Blockchain Data API .

But I will suggest you to use Mint Address instead Currency Symbol because there might me many tokens with the same Symbol.

One more thing to keep in mind, subscription is realtime but if there isn’t any trade happening for a certain currency then you will not see any results. So you should use the ‘query’ keyword instead and get the last trade for that currency and get price from that in this case.

Hi @cypherrr :wave:,

It looks like the error is due to the Solana field not being recognized in the query; This might mean that the field is either unavailable or named differently. I would suggest reviewing the query structure and ensuring; that the fields you’re calling match the available data for Solana. You may want to test with other queries to see if the data can be retrieved differently…