コード例 #1
0
        public void GetTrades(SharedData shared, CurrencyPair pair, string url, string jsonPath, string csvPath, out long since)
        {
            var latestTrades = GetNewTrades(shared, url, pair);

            if (latestTrades == null)
            {
                since = shared.Since;
                return;
            }

            var currentTrades = new FileInfo(jsonPath).Exists ?
                                shared.Data.Deserialise <List <Trade> >(File.ReadAllText(jsonPath)) : null;

            if (currentTrades == null)
            {
                File.AppendAllLines(csvPath, latestTrades.Select(x => x.ToString()).ToArray());
                shared.Data.WriteTrades(latestTrades, jsonPath);
                shared.Log.AddLogEvent("Trades Saved To: ", jsonPath);
            }
            else
            {
                var lastTrdTime = currentTrades.Last().UnixTime;

                var newTrds = latestTrades.Where(x => x.UnixTime > lastTrdTime).OrderBy(x => x.UnixTime);

                if (newTrds.Any())
                {
                    currentTrades.AddRange(newTrds);
                    shared.Data.OverWriteExistingTrades(currentTrades, jsonPath);
                    File.AppendAllLines(csvPath, newTrds.Select(x => x.ToString()).ToArray());
                    shared.Log.AddLogEvent("Trades Saved To: ", jsonPath);
                }
            }

            since = latestTrades.Last().LastTradeId;
            shared.Log.AddLogEvent("Number of new trds added: ", latestTrades.Count.ToString());
        }