Esempio n. 1
0
        public HMA_RESULT Engine(BinanceApiClient client)
        {
            HMA_RESULT hma = new HMA_RESULT(ENUM_TREND.NO_TREND, 0.0m);

            if (!client.GetServerConnection())
            {
                return(hma);                               // server disconnected
            }
            var candles = client.GetCandleStick(m_Symbol, m_TimeInterval);

            if (candles == null)
            {
                return(hma);                 // candle sticks is null
            }
            try
            {
                hma = m_Hma.iHMA(candles, 1, true);
                if (hma.Trend == ENUM_TREND.NO_TREND)
                {
                    //CloseOrder(client);
                    m_NewOrder = null;
                    return(hma); // No Signal
                }
                if (hma.Trend == ENUM_TREND.UP_TREND)
                {
                    int result = CloseOrder(client, "SELL");
                    if (result == 1)
                    {
                        return(hma);             // Buy Order Existing
                    }
                    m_NewOrder = client.PostNewOrder(m_Symbol, m_Quantity, 0.0m, OrderSide.BUY, OrderType.MARKET);
                }
                else if (hma.Trend == ENUM_TREND.DOWN_TREND)
                {
                    int result = CloseOrder(client, "BUY");
                    if (result == 1)
                    {
                        return(hma);             // SELL Order Existing
                    }
                    m_NewOrder = client.PostNewOrder(m_Symbol, m_Quantity, 0.0m, OrderSide.SELL, OrderType.MARKET);
                }
                return(hma); // Sumit Order
            }
            catch (Exception e)
            {
                throw e;
            }
        }