Example #1
0
        /// <summary>
        /// Converts double[,] containing trade history to TradeHistoryResult object
        /// </summary>
        /// <param name="input">Input as a double[,]</param>
        /// <returns>TradeHistoryResult of input</returns>
        TradeHistoryResult TradeHistoryArrayToTradeHistoryResult(double[,] input)
        {
            int unixTime = GetUnixTime();

            TradeHistoryResult THR = new TradeHistoryResult();     // Creates blank TradeHistoryResult

            for (int i = 0; i < input.Length / 4; i++)             // For each row in the input array
            {
                THR.trades.Add(new HistoricalTrade(
                                   Convert.ToUInt32(input[i, 0]),
                                   Convert.ToUInt32(input[i, 1] / 1000),
                                   input[i, 2],
                                   input[i, 2]));      // Append row's trade data to TradeHistoryResult
            }

            for (int i = THR.trades.Count - 1; i > 0; i--)            // Starts at 1 so there is at least a value
            {
                if (THR.trades[i].Time < unixTime - 100)
                {
                    THR.trades.RemoveAt(i);
                }
            }

            return(THR);
        }
Example #2
0
        /// <summary>
        /// Gets ticker info for currency pair from the API.
        /// </summary>
        /// <param name="currency">Currency pair to get data about</param>
        /// <returns>TradeHistoryResult containing last 120(?) trades</returns>
        public TradeHistoryResult GetTradeHistoryResult(CurrencyPair currency)
        {
            string rawData = DownloadString("https://api.bitfinex.com/v2/trades/" +
                                            currency.GetBitfinexCurrencyPair() +
                                            "/hist");                                 // Downloads raw data from API

            double[,] array = JsonConvert.DeserializeObject <double[, ]>(rawData);    // Converts raw data to double[,]

            TradeHistoryResult result = TradeHistoryArrayToTradeHistoryResult(array); // Converts array to TradeHistoryResult

            return(result);
        }