Ethereum: Historical bitcoin data in JSON
For now, the only API interface that supports Historical Data on Bitcoin is [blockchain.info] ( However, this API interface uses only USD as a default currency and does not provide the possibility of operating data other than USD.
Challenge
Considering the limitations of currently available API interfaces, it is necessary to create a custom solution that meets the requirements. In this article, we will examine the possibilities of creating an API based on JSON for Historical Bitcoins on Ethereum.
Requirements
To develop an API -based eThereum interface for Bitcoin historical data, the following requirements must be met:
1.
- Monetary support : API must support many currencies, including USD, EUR, GBP and others.
- Historical data format : API should return the historical Bitcoins prices in the standard JSON format.
Application
To meet these requirements, we can create a non -standard API interface using node.js and express.js, which is a popular JavaScript structure to build internet applications. Here is a review of the proposed solution at a high level:
Step 1: Define the data model
We will design a simple data model for storing historical Bitcoin prices on Ethereum. This includes columns of the date, time stamp, open price, close prices and volume.
`Javascript
const datamodel = {
ID: "Eth-bitcoin-historical-data",
Table: ["Data", "Time Marker", "Open_Price", "Close_Price", "Tom"],
diagram: {
"Data": {Type: 'String'},
"Time marker": {Type: 'String'},
"Open_PRICE": {Type: 'Number'},
"Close_price": {type: 'number'},
"Tom": {Type: "Integer"}
}
};
Step 2: Create API end points
We will create four end points for Bitcoin historical data:
Get /Historical-Data ': returns a list of all historical data points.
- Get /Historical-Data /: Date
: returns one historic data point for a given date.
- Get /Historical-Data /: Timestamp
: returns one historic data point for a given time tag.
- Post /Historical-Data ‘: creates a new historical point.
“ Javascript
Const Express = requires (“Express”);
const app = express ();
app .use (expression.json ());
// Get /Historical-Data
App.Get (‘/Historical-Data’, (req, res) => {
Const Data = req.qury.date;
// Implement logic to recover all historical data points for a given date
res.json (DataModel);
});
// Get/Historical-Data/: Data
App.Get (‘/Historical-Data/: Date’, (req, res) => {
Const Data = req.params.date;
// Implement logic to recover one historic data point for a given date
const datapoint = datamodel.find ((d) => d.date === date);
if (! DataPoint) {
res.status (404).
} otherwise {
res.json (datapoint);
}
});
// Get/Historical-Data/: Timestamp
App.Get (‘/Historical-Data/: Timestamp’, (req, res) => {
Const Timestamp = req.params.timestamp;
// Implement logic to download one historic data point for a given time stamp
const datapoint = datamodel.find ((d) => d .timestamp === Timestamp);
if (! DataPoint) {
res.status (404).
} otherwise {
res.json (datapoint);
}
});
// Post /Data Historical
app .st (‘/Historical-Data’, (req, res) => {
Const Data = req.body;
// Implement logic to create a new historical data point
Const Newatapoint = DataModel.push ({{
Date: Data.Date,
Open_price: data.open_price,
close_price: data.close_price,
volume: Data.volume,
});
if (! NewdodaPoint) {
Res.status (404).