-
-
Save wklm/4aae757376cd3caa25f8cb893d69ab6c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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