Token Price Tracker is a server implemented in golang that tracks and updates multiple token prices on a deployed smart contract.
The contract is currently deployed on the Goerli testnet here. It stores prices of multiple tokens that are updated every minute. Token price is updated only if the difference in the on-chain and market price is more than 2%.
The golang server updates the prices of tokens by pulling that information from the Coingecko API. If the price difference is more than 2% the server will send new transactions to the contract that override current pending transactions in the mempool, because by that time they would be deprecated. All blockchain related functionality is done through the Go-Ethereum library. The server does not use any kind of permanent storage and all history information is fetched from the contract logs.
Adding a new token to be tracked is done by adding its Coingecko ID in the symbols array of the Config.go file.
var Symbols = []string{
"ethereum",
"bitcoin",
"tether",
"litecoin",
"decentraland",
"ravencoin",
}-
API endpoint for retrieving the price history of a token in the specified timestamp period.
example:
api/history?symbol=ravencoin&from=0&to=2663405165 -
API endpoint for retrieving the on-chain and market current prices for the specified token.
example:
api/price?symbol=ravencoin -
Web Socket subscription for on-chain price change events.
- Create a .env file and fill the information specified in the .env.dev file.
- Run the make file. It will generate the relevant abi and bin files from the smart contract.