private void UpdateRawinSec() { while (true) { Cache[exchangebitstamp.Name].ecahe[exchangebitstamp.GetLocalTradingPairString(ltc_btc)].tl.Add(exchangebitstamp.SubscribedTradingPairs[exchangebitstamp.GetLocalTradingPairString(ltc_btc)].TradeInfo.t); Cache[exchangeokex.Name].ecahe[exchangeokex.GetLocalTradingPairString(ltc_btc)].tl.Add(exchangeokex.SubscribedTradingPairs[exchangeokex.GetLocalTradingPairString(ltc_btc)].TradeInfo.t); Cache[exchangehuobi.Name].ecahe[exchangehuobi.GetLocalTradingPairString(ltc_btc)].tl.Add(exchangehuobi.SubscribedTradingPairs[exchangehuobi.GetLocalTradingPairString(ltc_btc)].TradeInfo.t); Thread.Sleep(1000); } }
private void E_DepthEvent(object sender, CommonLab.Depth d, CommonLab.EventTypes et, CommonLab.TradePair tp) { string tradingpair = ""; if (comboBox1.InvokeRequired) { GetComboxText gt = new GetComboxText(GetCtext); tradingpair = comboBox1.Invoke(gt).ToString(); } if (exchange.GetLocalTradingPairString(tp, (CommonLab.SubscribeTypes)et) != tradingpair) { return; } if (dataGridView1.InvokeRequired) { UpdateDataGDV upd = new UpdateDataGDV(UpdateDgv); dataGridView1.Invoke(upd, new object[] { (object)d }); } else { UpdateDgv(d); } }
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); } } }