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)); }
static void Trade() { while (true) { if ((DateTime.Now - StartTime).TotalMinutes < CacheMinuts) { Thread.Sleep(1000); continue; } try { if (DateTime.Now.Hour == 8) { Console.WriteLine("时间到了,看看效果吧"); Console.ReadKey(); return; } string raw = ""; CommonLab.Depth d = exchange.GetDepth(exchange.GetLocalTradingPairString(tp), out raw); Console.WriteLine(d.ToString(10)); double bprice = d.CaculateDepth(CommonLab.OrderType.ORDER_TYPE_BUY, ba); double sprice = d.CaculateDepth(CommonLab.OrderType.ORDER_TYPE_SELL, aa); double diff = sprice - bprice; // if (diff > 0.00000005) { //Console.WriteLine("买单价格:{0} 卖单价格:{1} 差价:{2}", bprice, sprice, diff.ToString("F8")); } else { bprice -= 0.00000005; sprice += 0.00000005; } if (exchange.CancelAllOrders()) { continue; } account = exchange.GetAccount(out raw); if (sa == null) { sa = account.Clone(); } double cansellamount = account.Balances[tp.FromSymbol].available; double canbuyamout = account.Balances[tp.ToSymbol].available / sprice; canbuyamout = Math.Min(canbuyamout, ba); cansellamount = Math.Min(cansellamount, aa); Console.WriteLine("buy:{0} sell:{1} ,diff:{2} account c-sell:{3} c-buy:{4}", bprice, sprice, diff.ToString("F8"), cansellamount, canbuyamout); double sltc, nltc, cp; sltc = sa.Balances[tp.FromSymbol].balance + sa.Balances[tp.ToSymbol].balance / d.Asks[0].Price; nltc = account.Balances[tp.FromSymbol].balance + account.Balances[tp.ToSymbol].balance / d.Asks[0].Price; cp = 100 * nltc / sltc; double sbtc, nbtc, bcp; sbtc = sa.Balances[tp.ToSymbol].balance + sa.Balances[tp.FromSymbol].balance * d.Bids[0].Price; nbtc = account.Balances[tp.ToSymbol].balance + account.Balances[tp.FromSymbol].balance * d.Bids[0].Price; bcp = 100 * nbtc / sbtc; Console.WriteLine("sLTC:{0} nLTC:{1} diff:{2}% sBTC:{3} nBTC:{4} diff:{2}% ", sltc, nltc, cp.ToString("f4"), sbtc, nbtc, bcp.ToString("f4")); string sorder, border; if (Bull && cansellamount > 0.01) { sorder = exchange.Sell(tp.FromSymbol + "_" + tp.ToSymbol, sprice, cansellamount); } if (Bear && canbuyamout > 0.01) { border = exchange.Buy(tp.FromSymbol + "_" + tp.ToSymbol, bprice, canbuyamout); } Thread.Sleep(1500); } catch (Exception e) { Console.WriteLine(e.Message); Thread.Sleep(3000); } } }