Ethereum: Historically Bitcoin information JSON
Initially, however, the only application subscription that serves historical information about Bitcoin This application interface uses only USD default currency and does not provide the ability to serve non -UPO data.
Challenge
Due to the limits of the current application subscriptions, it is important to create a custom solution that meets the requirements. In this article, we explore the possibilities of creating a JSON -based application subscription for historical Bitcoin information from Ethereum.
Requirements
To develop an Ethereum -based application subscription, the following requirements must be met for historical bitco -information:
1
API parameters : API must have a parameter that allows you to obtain historical information in the JSON format.
- Currency Support : API must support multiple currencies such as USD, EUR, GBP and much more.
3
Historical Tieto
: API should return historical Bitcoin prices in the usual JSON format.
Suggestion
To meet these requirements, we can create a custom application interface with NODO.JS and Express.JS, which is a popular Javascript frame for the online application. Here is a high -quality review of the proposed solution:
Step 1: Set the data model
We are developing a simple data model to save historical bitcoin prices in Ethereum. This includes date, timestamp, open price, shutter price and volume.
`Javascript
Const Datamodel = {
ID: “Et-Bitcoin-Historical Data”,
Table: [‘Date’, ‘Timestamp’, ‘Open_Price’, ‘Close_Price’, ‘Volume’],
System: {
‘Date’: {type: ‘string’},
‘Timestamp’: {type: ‘string’},
‘Open_price’: {type: ‘number’},
‘Close_Price’: {type: ‘number’},
‘Volume’: {type: ‘whole number’}
}
};
`
2. Step: Create an API parameter
We create four historical Bitcoin information parameters:
- “Get /Historical-Data”: Returns a list of all historical data points.
Get /Historical-Data /: Date": Returns one historical data point to the date.
- Get /Historical-Data /: Timestamp
: Returns a particular timestamp of one historical information point.
- "Post /Historical-Data": Create a new historical information point.
Javascript
Const Express = Ask (‘Express’);
Const App = Express ();
App.use (Express.jon ());
// get /historical-data
App.get (‘/historical data’, (req, res) => {
Const date = req.query.date;
// present the logic to get all the historical data points of a particular date
Res.jon (Datamodel);
});
// get/historical-data/: date
App.Get (‘/Historical Data/: Date’, (Req, Res) => {
Const date = req.params.date;
// present the logic to get one historical information point for a specific date
Const dataapoint = dataamadel.find ((d) => d.date === date);
If (! Datopoint) {
Res.status (404) .send ({message: ‘data not found’});
} Else {
Res.jon (dataapoint);
}
});
// get/historical-data/: time stamp
App.get (‘/Historical Data/: Time Stamps’, (Req, Res) => {
Const Timestamp = req.params.themtamp;
// present the logic to get one historical information point for a specific time stamp
Const dataapoint = dataamadel.find ((d) => d.tiiestamp === Timestamp);
If (! Datopoint) {
Res.status (404) .send ({message: ‘data not found’});
} Else {
Res.jon (dataapoint);
}
});
// post /historical information
App.post (‘/Historical Information’, (Req, Res) => {
Const data = req.body;
// present the logic to create a new historical information point
Const newdatapoint = DataMadel.push ({
Date: Data.date,
Open_price: Data.open_price,
Close_price: Data.close_price,
Volume: Data.lumume,
});
If (! NewDatapoint) {
Res. States (404).