Skip to content

Instantly share code, notes, and snippets.

@wklm wklm/p.fs
Created Nov 20, 2017

Embed
What would you like to do?
module Bittrex
open Asset
open Bittrex.Net
open Deedle
let internal rest = new BittrexClient()
let internal webSockets = new BittrexSocketClient()
let marketHistory (pair : AssetPair) =
async {
return rest.GetMarketHistoryAsync(pair.symbol).Result.Result
|> Array.map (fun r -> r.Timestamp => decimal r.Price)
|> series
}
let pairs =
async {
return rest.GetMarkets().Result
|> Array.map (fun x -> x.BaseCurrency, x.MarketCurrency)
|> Array.filter (fun (x, _) -> not <| x.Equals("USDT"))
|> Array.map (fun (x, y) -> sprintf "%s-%s" x y)
|> Array.map (fun pair -> initAssetPair pair Bittrex)
}
let internal subscribe (pair : AssetPair) (x : Objects.BittrexMarketSummary) =
async {
pair.price.Value <- x.Last |> decimal
pair.lastUpdate.Value <- x.TimeStamp
pair.longOrdersNumber.Value <- x.OpenBuyOrders
pair.shortOrdersNumber.Value <- x.OpenSellOrders
let! history = marketHistory pair
pair.marketHistory.Value <- history
printfn "%A" (pair.ToString())
}
let rec internal bittrexStream (pair : AssetPair) (consumer : 'a -> 'b) =
async {
let status = webSockets.SubscribeToMarketDeltaStream(pair.symbol, fun x -> consumer pair x)
if not status.Success then
do! Async.Sleep 60000
return! bittrexStream pair consumer
}
let init() =
pairs
|> Array.iter (fun pair -> bittrexStream pair subscribe |> Async.Start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.