Beispiel #1
0
        public void Sumarize_Join()
        {
            var trade = new SellTrade()
            {
                Date = DateTime.UtcNow,
                From = new Quantity()
                {
                    Coin  = ECoin.ETH,
                    Value = 10
                },
                To = new Quantity()
                {
                    Coin  = ECoin.BTC,
                    Value = 0.5M
                },
                Fees = new Quantity[]
                {
                    new Quantity()
                    {
                        Coin  = ECoin.BTC,
                        Value = 0.5M
                    },
                    new Quantity()
                    {
                        Coin  = ECoin.ETH,
                        Value = 0.1M
                    }
                }
            };

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

            CollectionAssert.AreEqual(new Quantity[]
            {
                new Quantity()
                {
                    Coin  = ECoin.BTC,
                    Value = 0.505M
                }
            },
                                      trade.SumarizeFees(ECoin.ETH));
        }
Beispiel #2
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));
                }
            }
        }