Пример #1
0
        public void Sumarize_BuyFeeFrom()
        {
            var trade = new BuyTrade()
            {
                Date = DateTime.UtcNow,
                From = new Quantity()
                {
                    Coin  = ECoin.ETH,
                    Value = 10M
                },
                To = new Quantity()
                {
                    Coin  = ECoin.BTC,
                    Value = 0.5M
                },
                Fees = new Quantity[]
                {
                    new Quantity()
                    {
                        Coin  = ECoin.ETH,
                        Value = 0.1M
                    }
                }
            };

            Assert.AreEqual(trade.Price, 20M);

            CollectionAssert.AreEqual(new Quantity[]
            {
                new Quantity()
                {
                    Coin  = ECoin.BTC,
                    Value = 0.005M
                }
            },
                                      trade.SumarizeFees(trade.Fees[0].Coin));
        }
Пример #2
0
        public void Sumarize_BuyFeeTo()
        {
            var trade = new BuyTrade()
            {
                Date = DateTime.UtcNow,
                From = new Quantity()
                {
                    Coin  = ECoin.BTC,
                    Value = 0.0686M
                },
                To = new Quantity()
                {
                    Coin  = ECoin.XRP,
                    Value = 686.8M
                },
                Fees = new Quantity[]
                {
                    new Quantity()
                    {
                        Coin  = ECoin.XRP,
                        Value = 1.1M
                    }
                }
            };

            Assert.AreEqual(trade.Price, 0.0000998835177635410599883518M);

            CollectionAssert.AreEqual(new Quantity[]
            {
                new Quantity()
                {
                    Coin  = ECoin.BTC,
                    Value = 0.0001098718695398951659871870M
                }
            },
                                      trade.SumarizeFees(trade.Fees[0].Coin));
        }
Пример #3
0
        public IEnumerable <Trade> GetTrades(TradeDataSource dataSource, TradeData current)
        {
            var fetch = current.Data.GetEnumerator();

            if (!fetch.MoveNext())
            {
                yield break;
            }

            var header = fetch.Current.Select(u => u.ToString()).ToArray();

            var date    = Array.IndexOf(header, "Date(UTC)");
            var type    = Array.IndexOf(header, "Type");
            var asset   = Array.IndexOf(header, "Market");
            var amount  = Array.IndexOf(header, "Amount");
            var total   = Array.IndexOf(header, "Total");
            var fee     = Array.IndexOf(header, "Fee");
            var feeCoin = Array.IndexOf(header, "Fee Coin");

            if (date < 0 || type < 0 || asset < 0 || amount < 0 || fee < 0 || feeCoin < 0 || total < 0)
            {
                yield break;
            }

            var list = new List <Trade>();

            while (fetch.MoveNext())
            {
                var row = fetch.Current;

                if (row.Length < 8 || !ParseCoin(row[asset].ToString(), out var from, out var to))
                {
                    continue;
                }

                var dfee = decimal.Parse(row[fee].ToString(), CultureInfo.InvariantCulture);

                switch (row[type].ToString().ToUpperInvariant())
                {
                case "BUY":
                {
                    var trade = new BuyTrade()
                    {
                        Exchange = this,
                        From     = new Quantity()
                        {
                            Coin  = to,
                            Value = decimal.Parse(row[total].ToString(), CultureInfo.InvariantCulture)
                        },
                        To = new Quantity()
                        {
                            Coin  = from,
                            Value = decimal.Parse(row[amount].ToString(), CultureInfo.InvariantCulture)
                        },
                        Fees = dfee == 0 ? new Quantity[0] : new Quantity[]
                        {
                            new Quantity()
                            {
                                Coin  = ParseCoin(row[feeCoin].ToString()),
                                Value = dfee
                            }
                        },
                        Date = DateTime.ParseExact(row[date].ToString(), "yyyy-MM-dd H:mm:ss", CultureInfo.InvariantCulture)
                    };
                    yield return(trade);

                    break;
                }

                case "SELL":
                {
                    var trade = new SellTrade()
                    {
                        Exchange = this,
                        From     = new Quantity()
                        {
                            Coin  = from,
                            Value = decimal.Parse(row[amount].ToString(), CultureInfo.InvariantCulture)
                        },
                        To = new Quantity()
                        {
                            Coin  = to,
                            Value = decimal.Parse(row[total].ToString(), CultureInfo.InvariantCulture)
                        },
                        Fees = dfee == 0 ? new Quantity[0] : new Quantity[]
                        {
                            new Quantity()
                            {
                                Coin  = ParseCoin(row[feeCoin].ToString()),
                                Value = dfee
                            }
                        },
                        Date = DateTime.ParseExact(row[date].ToString(), "yyyy-MM-dd H:mm:ss", CultureInfo.InvariantCulture)
                    };
                    yield return(trade);

                    break;
                }

                default: throw new ArgumentException(nameof(type));
                }
            }
        }