0

We are trying to make token trading dex history but so far we havent found anything to make it, yes we have found different apis that that we planned to buy but trading history was slow af. Is there any way to connect to PanckakeSwap to solidity and get token history data

something like that

enter image description here

2 Answers 2

2

You should try Bitquery DexTradesByTokens API to get the trading history.

Try this API, which gives you trading history for ETH-WBNB pair - https://ide.bitquery.io/Retrieve-price-data-from-PancakeSwap-BSC_1

Below is the API example:

query MyQuery {
  EVM(dataset: archive, network: bsc) {
    DEXTradeByTokens(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
      where: {Trade: {Currency: {SmartContract: {is: "0x2170Ed0880ac9A755fd29B2688956BD959F933F8"}}, Side: {Currency: {SmartContract: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}}}, Dex: {ProtocolFamily: {is: "PancakeSwap"}}}}
    ) {
      Block {
        Time
      }
      Trade {
        Amount
        Buyer
        Seller
        Currency {
          SmartContract
          Name
          Symbol
        }
        Dex {
          ProtocolName
          ProtocolFamily
          SmartContract
        }
        Seller
        PriceAgainstSellCurrency: Price
        PriceInUSD
        Side {
          Amount
          Buyer
          Seller
          Currency {
            Name
            SmartContract
            Symbol
          }
        }
      }
    }
  }
}

Response will look like this:

{
  "EVM": {
    "DEXTradeByTokens": [
      {
        "Block": {
          "Time": "2024-05-15T18:06:41Z"
        },
        "Trade": {
          "Amount": "0.100468713573701377",
          "Buyer": "0x1a0a18ac4becddbd6389559687d1a73d8927e416",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a"
          },
          "PriceAgainstSellCurrency": 5.134549757905406,
          "PriceInUSD": 2984.124855452965,
          "Seller": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a",
          "Side": {
            "Amount": "0.515861608956915901",
            "Buyer": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x1a0a18ac4becddbd6389559687d1a73d8927e416"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T18:06:23Z"
        },
        "Trade": {
          "Amount": "0.000693794747833519",
          "Buyer": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          },
          "PriceAgainstSellCurrency": 5.133734436990693,
          "PriceInUSD": 2983.6510029203223,
          "Seller": "0x13f4ea83d0bd40e75c8222255bc855a974568dd4",
          "Side": {
            "Amount": "0.003561757989156211",
            "Buyer": "0x13f4ea83d0bd40e75c8222255bc855a974568dd4",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T18:06:17Z"
        },
        "Trade": {
          "Amount": "0.001992836085354134",
          "Buyer": "0x4a1ba2718bf1c8e6f24f7ebadbaa4dea07d03204",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          },
          "PriceAgainstSellCurrency": 5.134756208104682,
          "PriceInUSD": 2984.244841274531,
          "Seller": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
          "Side": {
            "Amount": "0.010232727461007173",
            "Buyer": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x4a1ba2718bf1c8e6f24f7ebadbaa4dea07d03204"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T18:05:59Z"
        },
        "Trade": {
          "Amount": "0.173178576659838400",
          "Buyer": "0xae7fcef300495de4afda82c1a369fa312b0ed9b8",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          },
          "PriceAgainstSellCurrency": 5.134064600533192,
          "PriceInUSD": 2980.1581072804843,
          "Seller": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
          "Side": {
            "Amount": "0.889110000000000000",
            "Buyer": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0xae7fcef300495de4afda82c1a369fa312b0ed9b8"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T18:05:53Z"
        },
        "Trade": {
          "Amount": "0.005843057461405827",
          "Buyer": "0x0656fd85364d03b103ceeda192fb2d3906a6ac15",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a"
          },
          "PriceAgainstSellCurrency": 5.1342983015577035,
          "PriceInUSD": 2980.293763151041,
          "Seller": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a",
          "Side": {
            "Amount": "0.030000000000000000",
            "Buyer": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x0656fd85364d03b103ceeda192fb2d3906a6ac15"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T18:05:17Z"
        },
        "Trade": {
          "Amount": "0.005792991545208980",
          "Buyer": "0xf081470f5c6fbccf48cc4e5b82dd926409dcdd67",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          },
          "PriceAgainstSellCurrency": 5.133358087600529,
          "PriceInUSD": 2979.7479994209234,
          "Seller": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
          "Side": {
            "Amount": "0.029737500000000000",
            "Buyer": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0xf081470f5c6fbccf48cc4e5b82dd926409dcdd67"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T18:05:02Z"
        },
        "Trade": {
          "Amount": "0.005987777831084031",
          "Buyer": "0x002162b2aee2dd657fb131b28cc34dee6797b66f",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a"
          },
          "PriceAgainstSellCurrency": 5.134270319851578,
          "PriceInUSD": 2980.2775206775127,
          "Seller": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a",
          "Side": {
            "Amount": "0.030742870000000000",
            "Buyer": "0x7d05c84581f0c41ad80ddf677a510360bae09a5a",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x002162b2aee2dd657fb131b28cc34dee6797b66f"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T18:04:59Z"
        },
        "Trade": {
          "Amount": "0.000871527398720700",
          "Buyer": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          },
          "PriceAgainstSellCurrency": 5.132312045415051,
          "PriceInUSD": 2979.140805834133,
          "Seller": "0x41bec5b2510cbfca527c6effa0ca7db3cc0016fc",
          "Side": {
            "Amount": "0.004472950566363495",
            "Buyer": "0x41bec5b2510cbfca527c6effa0ca7db3cc0016fc",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T18:04:59Z"
        },
        "Trade": {
          "Amount": "1.186079662224430557",
          "Buyer": "0xed9e3f98bbed560e66b89aac922e29d4596a9642",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0xd0e226f674bbf064f54ab47f42473ff80db98cba"
          },
          "PriceAgainstSellCurrency": 5.134627217981166,
          "PriceInUSD": 2980.4846884747885,
          "Seller": "0xd0e226f674bbf064f54ab47f42473ff80db98cba",
          "Side": {
            "Amount": "6.090076916351469568",
            "Buyer": "0xd0e226f674bbf064f54ab47f42473ff80db98cba",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0xed9e3f98bbed560e66b89aac922e29d4596a9642"
          }
        }
      },
      {
        "Block": {
          "Time": "2024-05-15T18:04:35Z"
        },
        "Trade": {
          "Amount": "0.000008418296310097",
          "Buyer": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e",
          "Currency": {
            "Name": "Ethereum Token",
            "SmartContract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
            "Symbol": "ETH"
          },
          "Dex": {
            "ProtocolFamily": "PancakeSwap",
            "ProtocolName": "pancake_swap_v3",
            "SmartContract": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          },
          "PriceAgainstSellCurrency": 5.132315517580798,
          "PriceInUSD": 2979.1428213138174,
          "Seller": "0x41bec5b2510cbfca527c6effa0ca7db3cc0016fc",
          "Side": {
            "Amount": "0.000043205352783904",
            "Buyer": "0x41bec5b2510cbfca527c6effa0ca7db3cc0016fc",
            "Currency": {
              "Name": "Wrapped BNB",
              "SmartContract": "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
              "Symbol": "WBNB"
            },
            "Seller": "0x62fcb3c1794fb95bd8b1a97f6ad5d8a7e4943a1e"
          }
        }
      }
    ]
  }
}
0

When a token is swapped on pancakeswap, a Swap() event is emitted. (https://bscscan.com/address/0x531febfeb9a61d948c384acfbe6dcc51057aea7e#code#L483). If you know which pair you want to build an history for, just query an archive node for all the swap events for that specific pair and build your history from there

2
  • Do you maybe know what would I need to query on the node to get that info?
    – Luc
    Commented Nov 9, 2022 at 14:06
  • @Luc you would ask for events (logs). You have to have access to a node that is willing to give you the information you want. Binance's public nodes recently disabled the ability to ask for events (logs) Commented Nov 30, 2022 at 22:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.