Esempio n. 1
0
        // where exchange like "BINANCE"
        // where symbol like "ETHUSDT"
        private void BuySellIndicatorTask(string exchange, string symbol)
        {
            //Console.WriteLine("DateTime,Exchange,Symbol,C60,C30,C15,C5,C1,Indicators,Bid,Ask");
            Console.WriteLine("DateTime,Exchange,Symbol,C60,C30,C5,C1,Indicators,Bid,Ask");

            string prevIndicators = ".........";
            string prevSignal = "";

            while (true)
            {
                var now = DateTime.Now;
                var timeString = now.ToString("yyyy-MM-dd HH:mm:ss");

                var c60 = CandlesMACD(exchange, symbol, 60);
                var c30 = CandlesMACD(exchange, symbol, 30);
                //var c15 = CandlesMACD(exchange, symbol, 15);
                var c5 = CandlesMACD(exchange, symbol, 5);
                var c1 = CandlesMACD(exchange, symbol, 1);

                // TODO: Also use spikes in "bar volume" to indicate significant bars (i.e. beginning/end of longer trends)
                //var indicators = GetIndicators(c1.Last(), c5.Last(), c15.Last(), c30.Last(), c60.Last());
                var indicators = GetIndicators(c1.Last(), c5.Last(), c30.Last(), c60.Last());
                var signal = GetSignal(indicators);

                var ticker = m_api[exchange].GetTicker(symbol);

                //Console.WriteLine("{0} [{1,-8} {2}]  |{3,6:0.00} |{4,6:0.00} |{5,6:0.00} |{6,6:0.00} |{7,6:0.00} |   {8}  {9}  b:{10} a:{11}", timeString, exchange, symbol, c60.Last(), c30.Last(), c15.Last(), c5.Last(), c1.Last(), indicators, signal, ticker.Bid, ticker.Ask);
                //Console.WriteLine("{0},{1},{2},{3:0.00},{4:0.00},{5:0.00},{6:0.00},{7:0.00},{8},{9},{10}", timeString, exchange, symbol, c60.Last(), c30.Last(), c15.Last(), c5.Last(), c1.Last(), indicators, ticker.Bid, ticker.Ask);
				Console.WriteLine("{0},{1},{2},{3:0.000},{4:0.000},{5:0.000},{6:0.000},{7},{8},{9},{10}", timeString, exchange, symbol, c60.Last(), c30.Last(), c5.Last(), c1.Last(), indicators, ticker.Bid, ticker.Ask, signal);

                // If the indicators have changed, publish a Prowl message
                if (signal != prevSignal && signal != "(no bias)")
                {
                    var shortTimeString = now.ToString("MMM-dd HH:mm:ss");
                    if (m_notify) m_prowl.Send(signal, string.Format("{0} {1}:{2}", shortTimeString, ticker.Bid, ticker.Ask));
                }

                prevIndicators = indicators;
                prevSignal = signal;
                Thread.Sleep(20000);
            }
        }
        private void ScalperTask(XSymbol xs, OrderSide initSide, decimal initPrice, decimal amount, decimal scalp)
        {
            Console.WriteLine("\n===== Starting Scalper  {0}   init_price:{1:0.00000000}  amount:{2}  scalp:{3:0.00000000} =====", xs, initPrice, amount, scalp);

            var api = m_api[xs.Exchange];

            string strategyId = "scalper";
            ExchangeOrderResult working;

            if (initSide == OrderSide.Sell)
            {
                working = m_om.PlaceOrder(api, xs.Symbol, initSide, initPrice + scalp, amount, strategyId);
            }
            else
            {
                working = m_om.PlaceOrder(api, xs.Symbol, initSide, initPrice - scalp, amount, strategyId);
            }
            Console.WriteLine("\n   NEW working order >>> {0} ", working.ToStr());

            int count = 0;

            while (true)
            {
                Thread.Sleep(m_testOnly ? 25000 : 15000);

                var t = api.GetTicker(xs.Symbol);

                //if (working.Result == ExchangeAPIOrderResult.Filled)
                // If our working order has been filled
                if (m_orders.Where(o => o.OrderId == working.OrderId).Count() == 0)
                {
                    var buySell  = working.IsBuy ? "BOT" : "SOLD";
                    var prowlEvt = string.Format("Fill {0} {1} {2:0.00000000}", working.Symbol, buySell, working.Price);
                    if (working.IsBuy)
                    {
                        working = m_om.PlaceOrder(api, xs.Symbol, OrderSide.Sell, initPrice + scalp, amount, strategyId);
                    }
                    else
                    {
                        working = m_om.PlaceOrder(api, xs.Symbol, OrderSide.Buy, initPrice - scalp, amount, strategyId);
                    }
                    Console.WriteLine("\n*** {0} ***\n   NEW working order >>> {1}", prowlEvt, working.ToStr());
                    m_prowl.Send(prowlEvt, working.ToMsgStr());
                }
                else if (Math.Abs(t.Last - initPrice) > 2 * scalp)  // if price breakout of range
                {
                    string dir = "up";
                    if (t.Last < initPrice)
                    {
                        dir = "down";
                    }
                    if (working.Side() == initSide)
                    {
                        m_om.Cancel(working);
                    }
                    initPrice = t.Last;
                    if (initSide == OrderSide.Sell)
                    {
                        working = m_om.PlaceOrder(api, xs.Symbol, initSide, initPrice + scalp, amount, strategyId);
                    }
                    else
                    {
                        working = m_om.PlaceOrder(api, xs.Symbol, initSide, initPrice - scalp, amount, strategyId);
                    }
                    Console.WriteLine("\n*** Price Breakout {0} {1} ***\n   NEW working order >>> {2} ", xs.Symbol, dir, working.ToStr());
                    //m_prowl.Send(string.Format("Breakout {0} {1}", working.Symbol, dir), working.ToMsgStr());
                }

                if (count % 4 == 0)
                {
                    Console.Write(".");
                }
                //if (count % 10 == 0) Console.WriteLine("{0}", working.ToStr());
            }
        }