// Load the CURRENCY_PAIRS file as a ZCurrencyPairMap (one for each exchange) public static IDictionary <CryptoExch, ZCurrencyPairMap> LoadCurrencyPairs() { Dictionary <CryptoExch, ZCurrencyPairMap> result = new Dictionary <CryptoExch, ZCurrencyPairMap>(); try { string pathname = Folders.system_path("CURRENCY_PAIRS.DF.csv"); using (var f = new StreamReader(pathname)) { string line; // Skip first line of file (column headers) f.ReadLine(); // Read currency pair information from file while ((line = f.ReadLine()) != null) { //"Exchange,Symbol,ExchangeSymbol,ExchangeLeft,ExchangeRight" var split = line.Split(','); var exch = Crypto.GetExch(split[0]); var zcp = new ZCurrencyPair(split[1], split[2], split[3], split[4]); if (!result.ContainsKey(exch)) { result.Add(exch, new ZCurrencyPairMap()); } result[exch].Add(zcp); } } } catch (Exception ex) { ErrorMessage("Crypto::LoadCurrencyPairs=> {0}", ex.Message); } return(result); }
static void CreateCurrencyPairFile() { string pathname = Folders.system_path("CURRENCY_PAIRS.TXT"); using (var f = new StreamWriter(pathname)) { f.WriteLine("Exchange,Symbol,ExchangeSymbol,ExchangeLeft,ExchangeRight"); foreach (var exchange in Crypto.Exchanges.Values) { var symbols = exchange.SymbolList; foreach (var s in symbols) { var exch = Crypto.GetExch(exchange.Name); var zcp = ZCurrencyPair.FromSymbol(s, exch); if (zcp == null) { continue; } cout("{0},{1}", exch, zcp); f.WriteLine(string.Format("{0},{1}", exch, zcp)); } cout("--------------------------------------------------------------------"); } cout("\nCurrency pairs output to file: '{0}'", pathname); } }
private CurrencyPair GetCurPair(string pair) { //var cp = ZCurrencyPair.GetLeftRight(pair, CryptoExch.POLONIEX); var zcp = ZCurrencyPair.FromSymbol(pair, CryptoExch.POLONIEX); Clients.Poloniex.CurrencyPair curpair = new CurrencyPair(currency_name: zcp.Right, coin_name: zcp.Left); // NOTICE these are in reverse order (currency, coin) return(curpair); }
public override void SubscribeOrderBookUpdates(ZCurrencyPair pair, bool subscribe) { // GDAX: WORKS!!! StartWebSocket(null); string symbol = pair.GDAXSymbol; // TODO: args should use this GDAXSymbol property string[] args = { @"""type"":""subscribe""", @"""product_ids"":[""btc-usd""]", @"""channels"":[""level2""]" }; SubscribeWebSocket(args); }
// Return a dictionary that maps each Binance currency-pair symbol (string) to a ZCurrencyPair object public static Dictionary <string, ZCurrencyPair> GetBinancePairs() { Dictionary <string, ZCurrencyPair> result = new Dictionary <string, ZCurrencyPair>(); foreach (var s in binance.SymbolList) { result.Add(s, ZCurrencyPair.FromSymbol(s, CryptoExch.BINANCE)); } return(result); }
public override void SubscribeOrderUpdates(ZCurrencyPair pair, bool subscribe) { if (subscribe) { m_subscribedPairs.Add(pair); } else { m_subscribedPairs.Remove(pair); } }
public static void SubscribeTradeUpdates(ZCurrencyPair pair, bool subscribe = true) { foreach (var exchange in Exchanges.Values) { if (exchange.HasPair(pair)) { dout("Crypto::SubscribeTradeUpdates=> {0}", exchange.Name); exchange.SubscribeTradeUpdates(pair, subscribe); } } }
// Given an updated set of exchange-specific symbols, update the CurrencyPairs map protected void UpdateCurrencyPairsFromSymbols() { //SupportedSymbols = new Dictionary<string, ZCurrencyPair>(); CurrencyPairs.Clear(); foreach (var s in m_symbolList) { var exch = Crypto.GetExch(Name); var pair = ZCurrencyPair.FromSymbol(s, exch); CurrencyPairs.Add(pair); } }
public override void SubscribeTradeUpdates(ZCurrencyPair pair, bool subscribe) { if (subscribe) { SubscribeChannel("trades", pair.BitfinexSymbol); } else { UnsubscribeChannel("trades", pair.BitfinexSymbol); } }
public CryptoExchange(string name) { Name = name; Exch = Crypto.GetExch(name); Exchange = Crypto.Exchanges[Exch]; var symbols = Exchange.GetSymbolList(false); foreach (var s in symbols) { var pair = ZCurrencyPair.FromSymbol(s, Exch); m_pairs[pair.Symbol] = pair; // Use the OneChain format symbol (ex: "BTC_USD") } }
public static void GetSymbolsOnMultipleExchanges() { var dict = new Dictionary <string, List <ZCurrencyPair> >(); //var exchanges = new string[] { "BINANCE", "BITFINEX", "BITSTAMP", "HITBTC", "GEMINI", "ITBIT", "BITTREX", "GDAX", "POLONIEX" }; var exchanges = new string[] { "BINANCE", "BITFINEX", "BITSTAMP", "HITBTC", "GEMINI", "ITBIT", "BITTREX", "POLONIEX" }; foreach (var e in exchanges) { cout("\n---{0}---", e); var exchEnum = (CryptoExch)Enum.Parse(typeof(CryptoExch), e); var exch = Exchanges[exchEnum]; foreach (var s in exch.SymbolList) { var zcp = ZCurrencyPair.FromSymbol(s, exchEnum); //cout(zcp.Symbol); Console.Write("{0}, ", zcp.Symbol); if (dict.ContainsKey(zcp.Symbol)) { dict[zcp.Symbol].Add(zcp); } else { dict[zcp.Symbol] = new List <ZCurrencyPair>() { zcp }; } } Console.WriteLine(); } cout("\n"); foreach (var s in dict.Keys) { int n = dict[s].Count(); if (n >= 4) { decimal maxbid = decimal.MinValue; decimal minask = decimal.MaxValue; cout("---{0} ({1})", s, n); foreach (var zcp in dict[s]) { /*var ticker = Exchanges[zcp.Exchange].GetTicker(zcp.ExchangeSymbol); * cout("{0} {1}", zcp.Exchange.ToString(), ticker.ToString()); * if (ticker.Bid > maxbid) maxbid = ticker.Bid; * if (ticker.Ask < minask) minask = ticker.Ask;*/ } cout("b:{0} a:{1} {2}\n", maxbid, minask, maxbid > minask ? (maxbid - minask).ToString() : ""); } } return; }
// We'll cache this translation of pair (string) to GDAX ProductPair object for faster performance public Clients.GDAX.ProductType GetProductPair(string pair) { Clients.GDAX.ProductType productPair; if (m_productPairs.TryGetValue(pair, out productPair)) { return(productPair); } var zcp = ZCurrencyPair.FromSymbol(pair, CryptoExch.GDAX); string strEnum = zcp.ExchangeSpecificLeft + zcp.ExchangeSpecificRight; //var li = ZCurrencyPair.GetLeftRight(pair, CryptoExch.GDAX); //string strEnum = li[0] + li[1]; //string strEnum = ""; productPair = (Clients.GDAX.ProductType)Enum.Parse(typeof(Clients.GDAX.ProductType), strEnum, ignoreCase: true); m_productPairs[pair] = productPair; return(productPair); }
public virtual void SubscribeTradeUpdates(ZCurrencyPair pair, bool subscribe) { ErrorMessage("BaseExchange::SubscribeTradeUpdates=> Exchange {0} does not support SubscribeTradeUpdates", this.Name); }
public override void SubscribeOrderBookUpdates(ZCurrencyPair pair, bool subscribe) { StartWebSocket(); SubscribeWebSocket(); }
public override void SubscribeTickerUpdates(ZCurrencyPair pair, bool subscribe) { }
public override void SubscribeOrderBookUpdates(ZCurrencyPair pair, bool subscribe) { StartWebSocket(new string[] { pair.GeminiSymbol }); SubscribeWebSocket(); }
public bool HasPair(ZCurrencyPair pair) { return(CurrencyPairs != null && CurrencyPairs.ContainsValue(pair)); }