Multiple processing Binance Websocket Flow Data with Ethereum
As a cryptocurrency enthusiast, you have probably experienced excitement to look at live market prices floating. In your case, you use unicorn_binance_websocket_api to disseminate price data to 100 crypts and two different deadlines simultaneously. To process this data and store rigid prices from different cryptocurrencies, you will need to take advantage of a little more complexity.
In this article, we will explore how to reach it using intelligent Ethereum contracts.
Prerequisite
Before you dive into the code, make sure you have:
- Wallet Ethereum : Configure an Ethereum portfolio (for example, metamask) and imports it to your favorite programming language.
- unicorn_binance_websocket_api
: Install and set up the API Websocket Unicorn Binance Unicorn to disseminate data to 100 crypts and two different deadlines.
Step 1: Set the data model
First of all, let’s define a basic data model that will store prices near different cryptocurrencies. Create a new contract using Solidey (Ethereum Programming Language).
`Solidity
Pragma solidity ^ 0.8,0;
Contracts Contracts {
STRUCT CRIPTODATA {
address token; // Crypto-Money token address
Horrodante Uint256; // exploration when data was received
UINT256 Price; // Cryptocurrency closure price
UINT256 TIMESTAMP2; // time time when the second data were received (optional)
}
Mapping (Address => Cryptodata Public Cabinets);
}
'
Step 2: Initialize the contract
Create a new contract instance and initialize -a with an empty card to store the prices of the fence.
Solidity
Pragma solidity ^ 0.8,0;
Contracts Contracts {
Private Closeprier _instance; // Contract
Public Function () Public Payable {
_Instance = roseputs ();
}
Mapping (Address => Cryptodata Public Cabinets);
}
'
Step 3: Subscribe to Binance Websocket
Use the "Subscribe" method of API Websocket Websocket Binance to establish a signature for price data. Be sure to correctly manage errors and exceptions.
Solidity
Pragma solidity ^ 0.8,0;
Contracts Contracts {
Private Closeprier _instance; // Contract
Public Function () Public Payable {
_Instance = roseputs ();
}
Mapping (Address => Cryptodata Public Cabinets);
NewPrice Event (Untrando Unt256 Award);
Subscribe Function () Public Payable {
// Subscribe to Binance Websocket for price data
Try (New Unicorn.binanceWebesockapi ("Your_api_Key", "Your_api_Secret"))) {
_instance.subscribe (
Address (this), // contract that was registered at the event
CLOSEPRICE.NEWPRICE, // Event Name
FUNCTION (Address Address, Price Uint256) PUBLIC {
Take the Newprice (token, award);
}
);
} Catch (error) {
Deliver the error;
}
}
// optional: define a maximum number of data points to store
SETMAXDATAPOINTS FUNCTION (UINT256 _MAXDATAPOINS) PUBLIC {
CLOSERIERS [msg.sender] .Closeprires = new Uint256 [_Maxdatapoints];
}
}
'
Step 4: Process the data
Create functions in your contract to process the price data received. For example, you can update a mapping or emission of events if necessary.
` Solidity
Pragma solidity ^ 0.8.