コード例 #1
0
ファイル: Program.cs プロジェクト: sempers/binance-to-delta
        public static BinanceAirdropRecord Parse(string input)
        {
            var en  = new CultureInfo("en-EN");
            var res = input.Split(";");
            var obj = new BinanceAirdropRecord();

            obj.Date   = DateTime.Parse(res[0] + "Z").ToLocalTime();
            obj.Amount = double.Parse(res[1], en);
            obj.Market = res[2];
            return(obj);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: sempers/binance-to-delta
        static void Main(string[] args)
        {
            Console.WriteLine("Hello");
            var deposits    = new List <BinanceDepositRecord>();
            var withdrawals = new List <BinanceWithdrawalRecord>();
            var orders      = new List <BinanceOrderRecord>();
            var outList     = new List <string>();
            var deltas      = new List <DeltaRecord>();

            //1.deposits
            foreach (var line in File.ReadAllLines($@"{PATH}\DepositHistory.csv").ToList().Skip(1))
            {
                var rec = new BinanceDepositRecord(line);
                deposits.Add(rec);
                deltas.Add(rec.ToDelta());
            }

            //2.withdrawals
            foreach (var line in File.ReadAllLines($@"{PATH}\WithdrawalHistory.csv").ToList().Skip(1))
            {
                var rec = new BinanceWithdrawalRecord(line);
                withdrawals.Add(rec);
                deltas.Add(rec.ToDelta());
            }

            //3.orders
            foreach (var line in File.ReadAllLines($@"{PATH}\trades.csv").ToList().Skip(1))
            {
                var rec = BinanceOrderRecord.Parse(line);
                orders.Add(rec);
            }
            var gorders = new List <BinanceOrderRecord>();
            var groups  = from o in orders group o by(o.Market, o.Date, o.Type) into g select g;

            foreach (var group in groups)
            {
                var grouped = orders.Where(o => o.Date == group.Key.Date && o.Type == group.Key.Type && o.Market == group.Key.Market).ToList();
                if (grouped.Count > 0)
                {
                    var groupResult = new BinanceOrderRecord
                    {
                        Date        = grouped[0].Date,
                        FeeCurrency = grouped[0].FeeCurrency,
                        Type        = grouped[0].Type,
                        Fee         = grouped.Sum(o => o.Fee),
                        Market      = grouped[0].Market,
                        OrderAmount = grouped.Sum(o => o.OrderAmount),
                        OrderPrice  = grouped.Average(o => o.OrderPrice),
                        Total       = grouped.Sum(o => o.Total)
                    };
                    gorders.Add(groupResult);
                }
            }
            foreach (var o in gorders)
            {
                var delta = o.ToDelta();
                if (delta != null)
                {
                    deltas.Add(delta);
                }
            }
            //4.conversions
            foreach (var line in File.ReadAllLines($@"{PATH}\conversions.csv").ToList().Skip(1))
            {
                if (line.StartsWith("//"))
                {
                    continue;
                }
                var rec   = BinanceConversionRecord.Parse(line);
                var delta = rec.ToDelta();
                if (delta != null)
                {
                    deltas.Add(delta);
                }
            }
            //5.airdrops
            foreach (var line in File.ReadAllLines($@"{PATH}\airdrops.csv").ToList().Skip(1))
            {
                if (line.StartsWith("//"))
                {
                    continue;
                }
                var rec   = BinanceAirdropRecord.Parse(line);
                var delta = rec.ToDelta();
                if (delta != null)
                {
                    deltas.Add(delta);
                }
            }

            outList = deltas.OrderBy(d => d.Date).Select(d => d.ToString()).ToList();
            outList.Insert(0, "\"Date\",\"Type\",\"Exchange\",\"Base amount\",\"Base currency\",\"Quote amount\",\"Quote currency\",\"Fee\",\"Fee currency\",\"Costs/Proceeds\",\"Costs/Proceeds currency\",\"Sync holdings\",\"Sent/Received from\",\"Sent to\",\"Notes\"");
            File.WriteAllLines($@"{PATH}\out\out.csv", outList);
            Console.WriteLine("OK");
        }