Prerequisites: Bitcoin Computer with the latest software (run 21 Update to obtain) and some bitcoin (a few thousand Satoshi will do for this tutorial).
21 Marketplace: Example API call
The Marketplace
21 Inc has release the beta version of the 21 marketplace to complement The 21 Bitcoin Computer currently available on Amazon.com .The 21 Marketplace (beta) |
Below is a sample of how the new API calls can be access through the BC to and from the 21 Marketplace and supplier.
Example API Usage
With just a few lines of code and a bitcoin computer your blockchain application can access an API to perform a task or obtain some data for a tiny amount of bitcoin.
Here is an example to obtain bitoin's historical price:
First we make the call through the 21 BC using the following model.
Inline Model [
Value {
Value
]Value {
date (string, optional),
value (number, optional)
}Call and Result
The only parameter here is to define the currency code formatted as ISO-4217 in this case "USD"
Values{
Values{
currecny_code = "USD"
}
$ 21 buy "https://mkt.21.co/bitcoin/price?currency_code=USD" --maxprice 2000 # Output: # { # "price":415.521 # }
Output{
price = "415.521"
}
Range Restricted Call
Here the call is made with a date range between 1/1/2015 and 1/15/2015.
The date is formatted as "YYYY-MM-DD" and we also need to specify the ISO currency code as we did in the previous example.
Values{
start_date = "2015-01-01"
end_date = "2015-01-15"
currecny_code = "USD"
currecny_code = "USD"
}
$ 21 buy "https://mkt.21.co/bitcoin/historical_prices?start_date=2015-01-01&end_date=2015-01-15¤cy_code=USD" --maxprice 2000
Result
We receive this return (JSON):
# Output: # { # "historical_prices":[ # { # "date":"2015-01-01", # "value":313.9247 # }, # { # "date":"2015-01-02", # "value":314.5916 # }, ... # { # "date":"2015-01-14", # "value":177.2795 # }, # { # "date":"2015-01-15", # "value":210.4636 # } # ] # }
In this case we have a JSON structure of: Output{historical_prices:[{date,value}]}
Output{
historical_prices:[
{
date = "2015-01-01"
historical_prices:[
{
date = "2015-01-01"
value = "313.9247"
}
}}
{
date = "2015-01-02"
date = "2015-01-02"
value = "314.5916"
}
}
{
date = "2015-01-14"
date = "2015-01-14"
value = "177.2795"
}
}
{
date = "2015-01-15"
date = "2015-01-15"
value = "210.4636"
}]
}]
That's it. Very similiar to making a web service call with JSON. This is one simple example. There are many API's already available on the 21 Marketplace.
For more in depth information on 21, the Bitcoin Computer, or the 21 Marketplace visit 21 Inc and check out the article we reported on May 5th.
For more in depth information on 21, the Bitcoin Computer, or the 21 Marketplace visit 21 Inc and check out the article we reported on May 5th.
Story by dinbits
Banner image by dinbits.com staff
The opinions expressed by authors of articles linked, referenced, or published on dinbits.com do not necessarily express, nor are endorsed by, the opinions the of dinbits.com or its affiliates.
Post a Comment