Blockchain Data

node v10.23.1
version: 1.0.0
endpointsharetweet
const Web3Data = require("web3data-js@0.6.1") // Create the Web3Data instances passing in your API Key (Get one! -> amberdata.io/onboarding) const w3d = new Web3Data(process.env.API_KEY) const BASE = 'eth' const QUOTE = 'usd' // Here we can watch for certain blockchain events and then make decisions based on these events // Initiate the websocket connection w3d.connect() /* Token Transfers */ // Define the token that we want to make decisions against const KYBER_TOKEN = '0xdd974d5c2e2928dea5f71b9825b8b646686bd200' // Get historical token transfers and historical token prices to run correlation tests. Based on historical token transfers we can possibly determine how a token transfer might effect price and factor in amount of tokens transfered as well as time of day of the transfer. Then place logic to execute transfer of the token if it passes certain parameters const histTokenTransfers = w3d.token.getTransfers(KYBER_TOKEN) // Now that we have an idea of the corelation between token transfers and token prices we can now watch for token transfers and set some parameters for when we might want to make decisions against this data. For instance, if the amount of tokens transfered is above some threshold const THRESHOLD = 1000 // Subscribes to all token transfer events w3d.on({eventName: 'token_transfer'}, tokenTransfer => { // Execute a trade if the amount above some perdetermined threshold if(tokenTransfer.amount > THRESHOLD) { // triggerSignal(pair, amount) console.log('Execute Trade') } // Log the token transfer data console.log(tokenTransfer) }) /* Functions */ // Look for hist // Watch for events such as 'mint' and 'burn' and execute trade // Get the human readable text signature of the event const getTextSig = async (hashSig) => w3d.signature.getSignature(hashSig).then( data => data.length > 0 ? data[0].textSignature : '') w3d.on({eventName:'address:logs', filters: {address: KYBER_TOKEN} }, async data => { const triggerSignal = false // Each log contains topics which tells us details about the event that was triggered // We'll use another one of our endpoints const hashSig = data.topics[0].slice(0, 10) const textSignature = await getTextSig(hashSig) // Check to see if it is a mint event if(textSignature.toLowerCase().includes('mint')) { // Check amount minted triggerSignal = true } else if(textSignature.toLowerCase().includes('burn')) { // Check amount burned triggerSignal = true } if(triggerSignal) { // triggerSignal(pair, amount) } }) /* Pending Transactions */ // We may want to watch for pending transactions as there are times when there could be a large pending transaction that could effect the price. Therefore we could trigger a signal expecting that once this pending transaction gets confirmed it will effect the price of that blockchain's token const VALUE_THRESHOLD = 1000000000000000000 // wei w3d.on({eventName:'pending_transactions'}, (pndingTxn) => { if(pndingTxn.value > VALUE_THRESHOLD) { // triggerSignal('eth_usd', amount) } })
Loading…

no comments

    sign in to comment