Exemple #1
0
        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);
                }
            }
        }
Exemple #2
0
 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));
 }