private void UpdateDgv(CommonLab.Depth d) { if (dataGridView1.Rows.Count != 10) { for (int i = 0; i < 10; i++) { dataGridView1.Rows.Add(); } } for (int i = 0; i < 10; i++) { if (i < 5) { dataGridView1.Rows[i].DefaultCellStyle.ForeColor = Color.Red; dataGridView1.Rows[i].Cells[0].Value = "卖" + (5 - i).ToString(); if (d.Asks.Count > 4) { dataGridView1.Rows[i].Cells[1].Value = d.Asks[4 - i].Price.ToString(); dataGridView1.Rows[i].Cells[2].Value = d.Asks[4 - i].Amount.ToString(); } } else { dataGridView1.Rows[i].DefaultCellStyle.ForeColor = Color.Green; dataGridView1.Rows[i].Cells[0].Value = "买" + (i - 4).ToString(); if (d.Bids.Count > 4) { dataGridView1.Rows[i].Cells[1].Value = d.Bids[i - 5].Price.ToString(); dataGridView1.Rows[i].Cells[2].Value = d.Bids[i - 5].Amount.ToString(); } } } }
private void Exchange_DepthEvent(object sender, CommonLab.Depth d, CommonLab.EventTypes et, CommonLab.TradePair tp) { try { StringBuilder sb = new StringBuilder(); sb.Append(DateTime.Now.ToString() + ": " + d.ToString(5)); if (textBox1.InvokeRequired) { UpdateConsole uc = new UpdateConsole(UpdateConsoleMthod); textBox1.Invoke(uc, new object[] { (object)Color.Blue, (object)sb.ToString() }); } else { UpdateConsoleMthod(Color.Blue, sb.ToString()); } } catch { } }
private void Value_DepthEvent(object sender, CommonLab.Depth d, CommonLab.EventTypes et, CommonLab.TradePair tp) { if (!this.Tp.Compare(tp)) { return; } double msecs = (DateTime.Now.TimeOfDay.TotalMilliseconds - _StartMilliseconds) / 1000; try { _TimeSeries[((IExchanges)sender).Name].SeriesPoints.Add(new SeriesPoint(msecs, d.Asks[0].Price)); if (_ChartXy != null && msecs > 1000) { _ChartXy.AxisX.MinValue = msecs - 1000; } } catch { } }
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); } } }
private static void Exchange_DepthEvent(object sender, CommonLab.Depth d, CommonLab.EventTypes et, CommonLab.TradePair tp) { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(DateTime.Now.ToString() + " de:{0},{1}", d.ExchangeTimeStamp, d.ToString(5)); }