static void Main(string[] args) { EBinanceExchange exchange = new EBinanceExchange("EspHWtI5WbB3FVUoywxqpE9SkawJKQcrb3q2vu54b428uGdNdIyZlESi29DIBS4n", "BT5OJjq1IQuVmfp8yInJMfiy8aMBdFbRIHSQoB8QyRMucbBQmjWPdI1Plzdz54o3", "rqno1092", "caojia"); CommonLab.TradePair elfbtc = new CommonLab.TradePair("elf", "btc"); CommonLab.TradePair elfeth = new CommonLab.TradePair("elf", "eth"); CommonLab.TradePair ethbtc = new CommonLab.TradePair("eth", "btc"); exchange.Subscribe(elfbtc, CommonLab.SubscribeTypes.RESTAPI); exchange.Subscribe(elfeth, CommonLab.SubscribeTypes.RESTAPI); exchange.Subscribe(ethbtc, CommonLab.SubscribeTypes.RESTAPI); while (true) { string raw; CommonLab.Ticker elfbtcticker = exchange.GetTicker(exchange.GetLocalTradingPairString(elfbtc), out raw); CommonLab.Ticker elfethticker = exchange.GetTicker(exchange.GetLocalTradingPairString(elfeth), out raw); CommonLab.Ticker ethbtcticker = exchange.GetTicker(exchange.GetLocalTradingPairString(ethbtc), out raw); double elf = 1 / elfbtcticker.Sell; double eth = elfethticker.Buy * elf; double btc = eth * ethbtcticker.Sell; string s = $"1 btc change to elf {elf} changeto eth {eth} to btc={btc}"; Console.WriteLine(s); elf = 1 / elfbtcticker.Sell * 0.999; eth = elfethticker.Buy * elf * 0.999; btc = eth * ethbtcticker.Sell * 0.999; Console.BackgroundColor = ConsoleColor.Red; s = $"1 btc change to elf {elf} changeto eth {eth} to btc={btc}"; Console.WriteLine(s); Console.BackgroundColor = ConsoleColor.Black; System.Threading.Thread.Sleep(1000); } }
static private void CheckAccount() { foreach (KeyValuePair <string, IExchanges> e in Exchanges) { string raw; var a = new CommonLab.Account(); try { a = e.Value.GetAccount(out raw); } catch (Exception err) { Console.WriteLine(err.Message + " exchange:" + e.Key + " GetAccount faile"); } if (e.Value.Name == "Bitstamp") { CommonLab.Ticker btcusdticker = e.Value.GetTicker(e.Value.GetLocalTradingPairString(new CommonLab.TradePair("btc", "usd")), out raw); btcusdrate = btcusdticker.Buy; btccnyrate = btcusdrate * 6.5; } if (a != null) { foreach (KeyValuePair <string, CommonLab.Balance> item in a.Balances) { if (item.Value.balance > 0) { Console.WriteLine(e.Key + " has " + item.Key + " balance:" + item.Value.balance.ToString()); if (item.Key.ToLower() == "btc") { Console.WriteLine("raw btc waiting for exchange..."); rawbtc += item.Value.balance; } else { CommonLab.TradePair tp = new CommonLab.TradePair(item.Key, "btc"); try { CommonLab.Ticker t = e.Value.GetTicker(e.Value.GetLocalTradingPairString(tp), out raw); ebtc += item.Value.balance * t.Last; Console.WriteLine("ebtc equals:" + (item.Value.balance * t.Buy) + " btc"); } catch (Exception ee) { Console.WriteLine(ee.Message); } } } } } } Console.WriteLine("-------------------------------"); Console.WriteLine("rawbtc:" + rawbtc + " ebtc:" + ebtc); Console.WriteLine("total btc:" + (rawbtc + ebtc)); Console.WriteLine("equls cny:" + ((rawbtc + ebtc) * btccnyrate)); }
private void Value_TickerEvent(object sender, CommonLab.Ticker t, CommonLab.EventTypes et, CommonLab.TradePair tp) { if (!this.Tp.Compare(tp)) { return; } double msecs = DateTime.Now.TimeOfDay.TotalMilliseconds - _StartMilliseconds; _TimeSeries[((IExchanges)sender).Name].SeriesPoints.Add(new SeriesPoint(msecs, t.Buy)); }
public void LoadHisData(DateTime t) { string json = ""; using (StreamReader sr = new StreamReader(@"HisData\" + Symbol + ".config")) { json = sr.ReadToEnd(); } List <CommonLab.Ticker> tickers = Newtonsoft.Json.JsonConvert.DeserializeObject <List <CommonLab.Ticker> >(json); CommonLab.Ticker ticker = tickers.Where(item => item.ExchangeTimeStamp > CommonLab.TimerHelper.GetTimeStampMilliSeconds(t)).OrderBy(i => i.ExchangeTimeStamp).ToArray()[0]; HisTicker = new BATicker(ticker); }
private void Exchange_TickerEvent(object sender, CommonLab.Ticker t, CommonLab.EventTypes et, CommonLab.TradePair tp) { StringBuilder sb = new StringBuilder(); sb.Append(DateTime.Now.ToString() + tp.FromSymbol + "/" + tp.ToSymbol + ": " + t.ToString()); if (textBox1.InvokeRequired) { UpdateConsole uc = new UpdateConsole(UpdateConsoleMthod); textBox1.Invoke(uc, new object[] { (object)Color.Red, (object)sb.ToString() }); } else { UpdateConsoleMthod(Color.Blue, sb.ToString()); } }
private static void Exchange_TickerEvent(object sender, CommonLab.Ticker t, CommonLab.EventTypes et, CommonLab.TradePair tp) { Console.BackgroundColor = ConsoleColor.DarkBlue; if (t.Last > tradeCacheManage.Avg()) { Console.WriteLine("5mins Avg:{0},Last price:{1} BULL", tradeCacheManage.Avg(), t.Last); Bull = true; Bear = false; } else { Console.WriteLine("5mins Avg:{0},Last price:{1} BEAR", tradeCacheManage.Avg(), t.Last); Bull = false; Bear = true; } Console.BackgroundColor = ConsoleColor.Black; }
private static void ExporttoDisk(object obj) { KFCC.ExchangeInterface.IExchanges e = (KFCC.ExchangeInterface.IExchanges)obj; string year = exporttime.Year.ToString(); string month = exporttime.Month.ToString(); string day = exporttime.Day.ToString(); string path = @"raw/" + e.Name;// + @"/" + year + @"/" + month + @"/"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } foreach (KeyValuePair <string, KFCC.ExchangeInterface.SubscribeInterface> item in e.SubscribedTradingPairs) { string file = path + @"/" + item.Key + "/" + year + @"/" + month + @"/" + day + ".txt"; CommonLab.Log log = new CommonLab.Log(file); CommonLab.Ticker t = item.Value.TradeInfo.t.Clone(); //double ts= CommonLab.TimerHelper.GetTimeStamp(exporttime.AddSeconds(-exporttime.Second).ToUniversalTime()); t.ExchangeTimeStamp = ts; log.RawLog(t.ToOCHLString()); } }
private static void Exchange_TickerEvent(object sender, CommonLab.Ticker t, CommonLab.EventTypes et, CommonLab.TradePair tp) { Console.WriteLine(DateTime.Now.ToString() + " " + ((KFCC.ExchangeInterface.IExchanges)sender).Name + " tp:" + tp.ToString() + " tk:" + t.ToString()); }
private static void Exchange_TickerEvent(object sender, CommonLab.Ticker t, CommonLab.EventTypes et, CommonLab.TradePair tp) { Console.BackgroundColor = ConsoleColor.DarkBlue; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(DateTime.Now.ToString() + " te:{0},{1}", t.ExchangeTimeStamp, t.ToString()); }