コード例 #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
ファイル: ProgramTests.cs プロジェクト: b28/BitcoinTradingBot
        /// <summary>
        /// Checks TimerElapsed() functions correctly. Currently non-functional, use the python price updater instead.
        /// </summary>
        //[TestMethod()]
        public void PriceUpdater_TimerElapsedTest()
        {
            int timeOfInsert = ApiReader.GetUnixTime();

            Program.APR = new ApiReader();                                                               // Initialises ApiReader
            Program.DBC = new DatabaseConnector();                                                       // Initialises DatabaseConnector

            Program.currency = new CurrencyPair(2, 1);                                                   // Creates new currency pair of ETH/BTC

            Program.TimerElapsed(null, null);                                                            // Runs TimerElapsed

            List <DatabaseRow> values = Program.DBC.SelectAllFromDatabase();                             // Selects every row from the database

            bool hasBeenFound = false;                                                                   // False until found

            foreach (DatabaseRow row in values)                                                          // Iterates through every row
            {
                if (Convert.ToInt32(row.data[0]) == Program.LastInsert)                                  // If the row is the values previously inserted
                {
                    hasBeenFound = true;                                                                 // Test is passed
                    string        sql     = "DELETE FROM prices WHERE date=" + Program.LastInsert + ";"; // Create sql to delete the row
                    SQLiteCommand command = new SQLiteCommand(sql, Program.DBC.connection);              // Create the command
                    command.ExecuteNonQuery();                                                           // Execute the command
                }
            }

            Assert.AreEqual(timeOfInsert, Program.LastInsert);
            Assert.IsTrue(hasBeenFound);
        }