-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retrieve and parse BTC price from CoinDesk
- Loading branch information
1 parent
8908d0f
commit 0aac0c3
Showing
3 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,53 @@ | ||
open System.Net.Http | ||
open FSharp.Data | ||
|
||
type CoindDeskProvider = JsonProvider<""" | ||
{ | ||
"time": { | ||
"updated": "Feb 25, 2024 12:27:26 UTC", | ||
"updatedISO": "2024-02-25T12:27:26+00:00", | ||
"updateduk": "Feb 25, 2024 at 12:27 GMT" | ||
}, | ||
"disclaimer":"This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org", | ||
"chartName":"Bitcoin", | ||
"bpi": { | ||
"USD": { | ||
"code": "USD", | ||
"symbol": "$", | ||
"rate": "51,636.062", | ||
"description": "United States Dollar", | ||
"rate_float": 51636.0621 | ||
}, | ||
"GBP": { | ||
"code": "GBP", | ||
"symbol": "£", | ||
"rate": "40,725.672", | ||
"description": "British Pound Sterling", | ||
"rate_float": 40725.672 | ||
}, | ||
"EUR": { | ||
"code":"EUR", | ||
"symbol": "€", | ||
"rate":"47,654.25", | ||
"description": "Euro", | ||
"rate_float": 47654.2504 | ||
} | ||
} | ||
} | ||
"""> | ||
|
||
let webClient = new HttpClient() | ||
|
||
let address = "https://example.com" | ||
let address = "https://api.coindesk.com/v1/bpi/currentprice.json" | ||
|
||
printfn "Retrieving contents of %s\n" address | ||
printfn "Retrieving contents of %s ...\n" address | ||
|
||
let contents = | ||
webClient.GetStringAsync address | ||
|> Async.AwaitTask | ||
|> Async.RunSynchronously | ||
|
||
printfn "%s" contents | ||
|
||
let json = CoindDeskProvider.Parse contents | ||
|
||
printfn "BTC price is %.2f USD" json.Bpi.Usd.Rate |