コード例 #1
0
        /// <summary>
        /// Run every 10 seconds, gets data from the API and puts it into the database.
        /// </summary>
        public static void TimerElapsed(object sender, ElapsedEventArgs e)
        {
            LastInsert = ApiReader.GetUnixTime();

            TickerResult       ticker  = APR.GetTickerResult(currency);       // Gets the ticker for the specified currency
            TradeHistoryResult history = APR.GetTradeHistoryResult(currency); // Gets the trade history for the specified currency

            Console.Write("Got price " + ticker.lastPrice + " at time " + LastInsert + "... ");

            double volAsk = 0;
            double volBid = 0;

            foreach (HistoricalTrade trade in history.trades)
            {
                if (trade.IsBid)
                {
                    volBid += trade.Amount;
                }
                else
                {
                    volAsk += trade.Amount;
                }
            }

            //DatabaseRow row = new DatabaseRow(
            //    LastInsert,
            //    ticker.lastPrice,
            //    volBid,
            //    volAsk);
            //DBC.InsertIntoDatabase(row);

            //Console.WriteLine("Inserted.");
            Console.WriteLine("Skipping insertion, no longer implemented in C#. Speak to me if you'd like me to reimplement this, it shouldn't take too long.");
        }
コード例 #2
0
        public void TradingLib_ApiReader_GetHistoryTest()
        {
            TradeHistoryResult THR = APR.GetTradeHistoryResult(new CurrencyPair(0, 1));             // Get result for currency pair USD/BTC

            double sumBid = 0;
            double sumAsk = 0;

            foreach (HistoricalTrade trade in THR.trades) // Iterate through each trade
            {
                if (trade.IsBid)                          // If it's a bid
                {
                    sumBid += trade.Amount;               // Add the amount to sumBid
                }
                else                                      // Else it's an ask
                {
                    sumAsk += trade.Amount;               // Add the amount to sumAsk
                }
            }

            Assert.AreEqual(THR.sumAsk(), sumAsk);             // Check calculated ask is the same as sumAsk
            Assert.AreEqual(THR.sumBid(), sumBid);             // Check calculated bid is the same as sumBid
        }