Exemple #1
0
        public int Run(string[] args)
        {
            Stopwatch w = Stopwatch.StartNew();

            // bear market
            //startDate = new DateTime(2017, 6, 11, 17, 0, 0, DateTimeKind.Utc);
            //endDate = new DateTime(2017, 7, 18, 0, 0, 0, DateTimeKind.Utc);
            startDate = new DateTime(2017, 1, 3, 0, 0, 0, DateTimeKind.Utc);
            endDate   = new DateTime(2017, 1, 7, 0, 0, 0, DateTimeKind.Utc);

            byte[] tradeData = TraderFileReader.GetBytesFromBinFiles(@"../../data/btcusd", startDate, endDate);
            tradeReader = new TradeReaderMemory(tradeData);

            if (csv.Count != 0)
            {
                using (StreamWriter csvWriter = new StreamWriter(@"../../data.csv"))
                {
                    csvWriter.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14}",
                                        "StartCashFlow", "UnitsToBuy", "Interval", "BuyThresholdPercent", "SellThresholdPercent",
                                        "BuyReverseThresholdPercent", "BuyFalseReverseThresholdPercent", "SellReverseThresholdPercent",
                                        "Spend", "Profit", "SpendProfitDiff", "ItemCount", "Buys", "Sells", "CashFlow");
                    csv.Sort((k1, k2) => k2.Key.CompareTo(k1.Key));
                    Logger.Info("Max: {0}", csv[0].Value);
                    foreach (var kv in csv)
                    {
                        csvWriter.WriteLine(kv.Value);
                    }
                }
            }

            w.Stop();
            Logger.Info("Total time: {0}", w.Elapsed);
            return(0);
        }
Exemple #2
0
        /// <summary>
        /// Export exchange data to csv and then to optimized bin files
        /// </summary>
        /// <param name="api">Exchange api, null to just convert existing csv files</param>
        /// <param name="marketSymbol">Market symbol to export</param>
        /// <param name="basePath">Base path to export to, should not contain symbol, symbol will be appended</param>
        /// <param name="sinceDateTime">Start date to begin export at</param>
        /// <param name="callback">Callback if api is not null to notify of progress</param>
        public static void ExportExchangeTrades(IExchangeAPI api, string marketSymbol, string basePath, DateTime sinceDateTime, Action <long> callback = null)
        {
            basePath = Path.Combine(basePath, marketSymbol);
            Directory.CreateDirectory(basePath);
            sinceDateTime = sinceDateTime.ToUniversalTime();
            if (api != null)
            {
                long         count     = 0;
                int          lastYear  = -1;
                int          lastMonth = -1;
                StreamWriter writer    = null;
                bool innerCallback(List <ExchangeTrade> trades)
                {
                    foreach (ExchangeTrade trade in trades)
                    {
                        if (trade.DateTime.Year != lastYear || trade.DateTime.Month != lastMonth)
                        {
                            if (writer != null)
                            {
                                writer.Close();
                            }
                            lastYear  = trade.DateTime.Year;
                            lastMonth = trade.DateTime.Month;
                            writer    = new StreamWriter(basePath + trade.DateTime.Year + "-" + trade.DateTime.Month.ToString("00") + ".csv");
                        }
                        writer.WriteLine("{0},{1},{2}", CryptoUtility.UnixTimestampFromDateTimeSeconds(trade.DateTime), trade.Price, trade.Amount);
                        if (++count % 100 == 0)
                        {
                            callback?.Invoke(count);
                        }
                    }
                    return(true);
                }

                //api.GetHistoricalTradesAsync(innerCallback, marketSymbol, sinceDateTime).Sync();
                writer.Close();
                callback?.Invoke(count);
            }
            TraderFileReader.ConvertCSVFilesToBinFiles(basePath);
        }