Skip to content

Instantly share code, notes, and snippets.

@wklm
Created November 20, 2017 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wklm/4aae757376cd3caa25f8cb893d69ab6c to your computer and use it in GitHub Desktop.
Save wklm/4aae757376cd3caa25f8cb893d69ab6c to your computer and use it in GitHub Desktop.
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