Exemple #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="huobi"></param>
 /// <param name="market"></param>
 /// <param name="renderer"></param>
 public AlgoBase(IMarket huobi, HuobiMarket market, Rendering renderer)
 {
     m_huobi          = huobi;
     m_market         = market;
     m_lastOpenOrders = m_huobi.GetOpenOrders(m_market);
     m_startInfo      = m_huobi.GetAccountInfo();
     m_renderer       = renderer;
 }
Exemple #2
0
        /// <summary>
        /// </summary>
        public override void Update(DateTime now)
        {
            base.Update(now);

            CancelOpenOrders();

            HuobiAccountInfo   info    = m_huobi.GetAccountInfo();
            HuobiMarketSummary summary = m_huobi.GetMarketSummary(m_market);

            decimal midPrice = (summary.GetAskPrice(0) + summary.GetBidPrice(0)) * 0.5M;

            CalculateProfit(now, midPrice, info);

            decimal buyPrice  = MarketBase.NormalisePrice(summary.GetBidPrice(0));
            decimal sellPrice = MarketBase.NormalisePrice(summary.GetAskPrice(0));

            decimal amountCanBuy  = MarketBase.NormaliseAmount(info.available_cny_display / buyPrice);
            decimal amountCanSell = MarketBase.NormaliseAmount(info.available_btc_display);

            bool canBuy    = amountCanBuy >= Huobi.kMinAmount;
            bool canSell   = amountCanSell >= Huobi.kMinAmount;
            bool dontTrade = sellPrice <= buyPrice + kMinTradeThresh;


            if (!dontTrade)
            {
                if (canBuy)
                {
                    // we can action a buy!
                    HuobiOrderResult result = m_huobi.Buy(m_market, buyPrice, Huobi.kMinAmount);
                    Console.WriteLine("Buy " + Huobi.kMinAmount + "BTC at " + buyPrice);

                    m_renderer.AddMarker(true, false, buyPrice, now);
                }
                if (canSell)
                {
                    // we can action a buy!
                    HuobiOrderResult result = m_huobi.Sell(m_market, sellPrice, Huobi.kMinAmount);
                    Console.WriteLine("Sell " + Huobi.kMinAmount + "BTC at " + sellPrice);

                    m_renderer.AddMarker(false, false, sellPrice, now);
                }
            }

            m_lastOpenOrders.AddRange(m_huobi.GetOpenOrders(m_market));

            m_renderer.ReformatGraph();
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="now"></param>
        /// <param name="infoNow"></param>
        protected void CalculateProfit(DateTime now, decimal midPrice, HuobiAccountInfo infoNow)
        {
            //
            // total ROI
            //

            decimal totalBtcValueStart = m_startInfo.m_TotalCny / midPrice + m_startInfo.m_TotalBtc;
            decimal totalBtcValueNow   = infoNow.m_TotalCny / midPrice + infoNow.m_TotalBtc;

            decimal profitPercent = totalBtcValueStart > 0
                        ? 100 * (totalBtcValueNow - totalBtcValueStart) / totalBtcValueStart
                        : 0;

            Console.WriteLine("profit % = " + profitPercent);

            m_renderer.AddProfitDataPoints(profitPercent, now);
        }