Org Babel has a wide selection of supported programming languages. But F# was still missing even though it's well suited for Org spreadsheets by the use of strongly typed access to connected information via type providers. So I started an implementation of Org Babel F# support.
In the following use case I adapted an Emacs Lisp implementation for querying the Kraken cryptocurrency exchange. I also used Org Babel Shell to install and use Paket: a dependency manager for .NET.
The source file for this document can be found here: kraken-fsharp.org
Use curl to download the Paket cli tool:
curl -L -z paket.exe -o paket.exe \ https://github.com/fsprojects/Paket/releases/download/5.0.0/paket.exe
Reference FSharp.Data in the
source https://nuget.org/api/v2 nuget FSharp.Data
Install the NuGet dependencies into the packages folder using:
mono paket.exe install
Access The Kraken Ticker Restservice
Instead of manually parsing the Kraken JSON API we let the compiler do
the job by using the JSON Type Provider. This Org Babel source block
ticker will evaluate to a result block also named
wich can be referenced from within an Org Table formula.
#r @"packages/FSharp.Data/lib/net45/FSharp.Data.dll" open FSharp.Data type Kraken = JsonProvider<"https://api.kraken.com/0/public/Ticker?pair=ETHEUR,XBTEUR"> let ticker = Kraken.GetSample() [float <| ticker.Result.Xethzeur.C.; float <| ticker.Result.Xxbtzeur.C.]
Access the ticker result within an Org Table
The result can now be referenced in the following Org Table
using the formula
@2$3 = remote(kraken, @1$1);%.2f for Ethereum
@3$3 = remote(kraken, @1$2);%.2f for Bitcoin.
|Coin||Units||Unit Price €||Current Value €||Fraction|