It’s very easy to use our API with F# (F Sharp) language as well. We provide simple examples of using our API with F# (F Sharp) and we believe that it will help to start working with our API very quick.

Installation

First, you should download f_sharp_bundle.zip. In this archive, you will find three files:

  • Program.fs
  • Download.fs
  • EOD.csv

The two text files contain the F# (F-Sharp) code that downloads data from the EODHD API. The file Download.fs must be above Program.fs in the Visual Studio solution, as the order of files matters in F#, differently from other languages like C#.

The CSV file contains a list of tickers to be downloaded. It is an example of the kind of file that is read by the F# program.

For testing purposes, you can use this API Key:

api_token=demo

Works with AAPL.US only.

Prerequisites

The user will have to install the packages Deedle and FSharp.Data from Nuget.

Register & Get Data

Code

The full code of Program.fs

open Deedle

[<EntryPoint>]
let main argv =

let dropboxRoot = “C:\\” // or whenever your Dropbox folder is

// File with list of tickers of stocks to be downloaded
let eODAssetsPath = dropboxRoot + @”\Dropbox\EODData\EOD.csv”

// Alternatively delete the ‘let dropBoxRoot = …’ line and set the value of eODAssetsPath to the location where you saved EOD.csv.

// Data stored in this folder
let storageDataPath = dropboxRoot + @”\Dropbox\EODDAta\”

// Tickers to be downloaded from EOD Historical Data
// The CSV file in eODAssetsPath contains a column labeled Ticker with
// the tickers of the stocks to be downloaded from EOD Historical Data
let eODTickers : string seq =
Frame.ReadCsv(eODAssetsPath, hasHeaders=true, inferTypes=false)
|> Frame.getCol “Ticker”
|> Series.dropMissing
|> Series.filterValues (fun x -> x <> “”)
|> Series.values

Seq.iter (Download.downloadFromEOD storageDataPath) eODTickers

printfn “%A” argv
0 // return an integer exit code

The full code of Download.fs

[<RequireQualifiedAccess>]
module Download

open FSharp.Data

open Deedle

/// Downloads data from EOD Historical Data for one stock.
let downloadFromEOD (storageDataPath: string) (symbol: string) : unit =

// Token for the EOD Historical Data service
let apiToken = “99999999999999” // insert your EOD token here

let endStr = “?api_token=” + apiToken + “&period=d&order=d”

printfn “Downloading symbol %s” symbol

let url = @”http://eodhd.com/api/eod/” + symbol + endStr

let df =
Http.RequestString(url)
|> DeedleFuncs.Frame.stringToTSDF

let path = storageDataPath + symbol + “.csv”

FrameExtensions.SaveCsv(df, path, includeRowKeys=true, keyNames=[“Date”])

Register & Get Data

Thanks for this code to Fernando Saldanha. Fernando Saldanha has a Ph.D. in Economics from Massachusetts Institute of Technology (1982). He worked many years in the U.S. and Brazilian financial markets and is now happily retired. His hobby is writing financial software with F#.

Tagged: