예제 #1
0
        public void UpdateCCex(string apikey = null)
        {
            Dictionary<string, CCexPair> ccPairs = JsonControl.DownloadSerializedApi<Dictionary<string, CCexPair>>(
                _client.GetStreamAsync("https://c-cex.com/t/prices.json").Result);
            CCexVolume ccVolumes = JsonControl.DownloadSerializedApi<CCexVolume>(
                _client.GetStreamAsync("https://c-cex.com/t/s.html?a=lastvolumes&h=24").Result);

            Parallel.ForEach(ListOfCoins, c => Parallel.For(0, ccPairs.Count, _po, i =>
            {
                string market = ccPairs.Keys.ElementAt(i);
                string[] splitPair = market.Split('-');
                if (splitPair[1] == "btc" && splitPair[0] == c.TagName.ToLowerInvariant())
                {
                    CCexPair ccPair = ccPairs.Values.ElementAt(i);
                    double priceToUse;
                    switch (_bidRecentAsk)
                    {
                        case 0:
                            priceToUse = ccPair.Buy;
                            break;
                        case 1:
                            priceToUse = ccPair.Lastprice;
                            break;
                        case 2:
                            priceToUse = ccPair.Sell;
                            break;
                        default:
                            priceToUse = ccPair.Buy;
                            break;
                    }

                    ParallelOptions optionsVolumeLoop = new ParallelOptions
                    {
                        CancellationToken = new CancellationTokenSource().Token,
                    };
                    double volumeToUse = 0;
                    Parallel.ForEach(ccVolumes.Returns, optionsVolumeLoop, ccVolume =>
                    {
                        if (ccVolume.ContainsKey("volume_btc") && ccVolume.ContainsKey("volume_" + splitPair[0]) &&
                            Double.TryParse(ccVolume["volume_btc"], NumberStyles.Any, CultureInfo.InvariantCulture,
                                out volumeToUse))
                        {
                            optionsVolumeLoop.CancellationToken.ThrowIfCancellationRequested();
                        }
                    });

                    Coin.Exchange ccExchange = new Coin.Exchange
                    {
                        ExchangeName = "C-Cex",
                        BtcVolume = volumeToUse,
                        BtcPrice = priceToUse,
                        BuyOrders = new List<Coin.Exchange.Order>(),
                        SellOrders = new List<Coin.Exchange.Order>(),
                    };

                    if (_getOrderDepth && !string.IsNullOrWhiteSpace(apikey))
                    {
                        CCexOrders ccOrders = JsonControl.DownloadSerializedApi<CCexOrders>(
                            _client.GetStreamAsync("https://c-cex.com/t/r.html?key=" +
                                                   apikey + "&a=orderlist&self=0&pair=" + market).Result);

                        foreach (KeyValuePair<uint, CCexOrders.CCexOrder> newOrder in ccOrders.Return)
                        {
                            bool found = false;
                            foreach (Coin.Exchange.Order buyOrder in ccExchange.BuyOrders)
                            {
                                if (buyOrder.BtcPrice == newOrder.Value.Price)
                                {
                                    buyOrder.BtcVolume += newOrder.Value.Amount*newOrder.Value.Price;
                                    buyOrder.CoinVolume += newOrder.Value.Amount;
                                    found = true;
                                    break;
                                }
                            }

                            if (!found)
                            {
                                foreach (Coin.Exchange.Order sellOrder in ccExchange.SellOrders)
                                {
                                    if (sellOrder.BtcPrice == newOrder.Value.Price)
                                    {
                                        sellOrder.BtcVolume += newOrder.Value.Amount * newOrder.Value.Price;
                                        sellOrder.CoinVolume += newOrder.Value.Amount;
                                        found = true;
                                        break;
                                    }
                                }
                            }

                            if (!found)
                            {
                                Coin.Exchange.Order order = new Coin.Exchange.Order
                                {
                                    BtcPrice = newOrder.Value.Price,
                                    BtcVolume = newOrder.Value.Price * newOrder.Value.Amount,
                                    CoinVolume = newOrder.Value.Amount
                                };

                                switch (newOrder.Value.Type)
                                {
                                    case "sell":
                                        ccExchange.SellOrders.Add(order);
                                        break;
                                    case "buy":
                                        ccExchange.BuyOrders.Add(order);
                                        break;
                                }
                            }
                        }
                    }

                    if (c.HasImplementedMarketApi)
                    {
                        c.Exchanges.Add(ccExchange);
                        c.TotalExchange.BtcVolume += ccExchange.BtcVolume;
                    }
                    else
                    {
                        c.Exchanges = new List<Coin.Exchange> {ccExchange};
                        c.TotalExchange.BtcVolume = ccExchange.BtcVolume;
                        c.HasImplementedMarketApi = true;
                    }

                    _po.CancellationToken.ThrowIfCancellationRequested();
                }
            }));
        }
예제 #2
0
        public void UpdateComkort()
        {
            ComkortPairs com = JsonControl.DownloadSerializedApi<ComkortPairs>(
                _client.GetStreamAsync("https://api.comkort.com/v1/public/market/summary").Result);

            Parallel.ForEach(ListOfCoins, c => Parallel.ForEach(com.Markets, _po, comCoin =>
            {
                /*foreach (Coin c in List)
                {
                    foreach (KeyValuePair<string, Comkort.Pair> comCoin in com.Markets)
                    {*/
                        if (comCoin.Value.CurrencyCode == "BTC" && comCoin.Value.ItemCode == c.TagName)
                        {
                            double priceToUse;
                            switch (_bidRecentAsk)
                            {
                                case 0:
                                    priceToUse = comCoin.Value.BuyOrders != null
                                        && comCoin.Value.BuyOrders.Any()
                                        ? comCoin.Value.BuyOrders[0].Price
                                        : comCoin.Value.LastPrice;
                                    break;
                                case 1:
                                    priceToUse = comCoin.Value.LastPrice;
                                    break;
                                case 2:
                                    priceToUse = comCoin.Value.SellOrders != null
                                        && comCoin.Value.SellOrders.Any()
                                        ? comCoin.Value.SellOrders[0].Price
                                        : comCoin.Value.LastPrice;
                                    break;
                                default:
                                    priceToUse = comCoin.Value.BuyOrders != null 
                                        && comCoin.Value.BuyOrders.Any()
                                        ? comCoin.Value.BuyOrders[0].Price
                                        : comCoin.Value.LastPrice;
                                    break;
                            }

                            Coin.Exchange comExchange = new Coin.Exchange
                            {
                                ExchangeName = "Comkort",
                                BtcPrice = priceToUse,
                                BtcVolume = (comCoin.Value.CurrencyVolume),
                                BuyOrders = new List<Coin.Exchange.Order>(),
                                SellOrders = new List<Coin.Exchange.Order>()
                            };

                            if (_getOrderDepth)
                            {
                                ComkortOrders comOrders = JsonControl.DownloadSerializedApi<ComkortOrders>(
                                    _client.GetStreamAsync("https://api.comkort.com/v1/public/order/list?market_alias="
                                                           + comCoin.Value.ItemCode + "_BTC").Result);
                                foreach (ComkortOrders.Orders.Order newOrder in comOrders.OrderData.Buy)
                                {
                                    double price, volume, coinVolume;
                                    if (Double.TryParse(newOrder.Price, NumberStyles.Float,
                                        CultureInfo.InvariantCulture, out price) &&
                                        Double.TryParse(newOrder.TotalPrice, NumberStyles.Float,
                                            CultureInfo.InvariantCulture, out volume) &&
                                        Double.TryParse(newOrder.Amount, NumberStyles.Float,
                                            CultureInfo.InvariantCulture, out coinVolume))
                                    {
                                        Coin.Exchange.Order order = new Coin.Exchange.Order
                                        {
                                            BtcPrice = price,
                                            BtcVolume = volume,
                                            CoinVolume = coinVolume
                                        };
                                        comExchange.BuyOrders.Add(order);
                                    }
                                }

                                foreach (ComkortOrders.Orders.Order newOrder in comOrders.OrderData.Sell)
                                {
                                    double price, volume, coinVolume;
                                    if (Double.TryParse(newOrder.Price, NumberStyles.Float,
                                        CultureInfo.InvariantCulture, out price) &&
                                        Double.TryParse(newOrder.TotalPrice, NumberStyles.Float,
                                            CultureInfo.InvariantCulture, out volume) &&
                                        Double.TryParse(newOrder.Amount, NumberStyles.Float,
                                            CultureInfo.InvariantCulture, out coinVolume))
                                    {
                                        Coin.Exchange.Order order = new Coin.Exchange.Order
                                        {
                                            BtcPrice = price,
                                            BtcVolume = volume,
                                            CoinVolume = coinVolume
                                        };
                                        comExchange.SellOrders.Add(order);
                                    }
                                }
                            }

                            if (c.HasImplementedMarketApi)
                            {
                                c.Exchanges.Add(comExchange);
                                c.TotalExchange.BtcVolume += comExchange.BtcVolume;
                            }
                            else
                            {
                                c.Exchanges = new List<Coin.Exchange> {comExchange};
                                c.TotalExchange.BtcVolume = comExchange.BtcVolume;
                                c.HasImplementedMarketApi = true;
                            }

                            _po.CancellationToken.ThrowIfCancellationRequested();
                        }
                    //}
                }));
        }
예제 #3
0
        public void UpdateAllCoin()
        {
            AllCoinPairs ac = JsonControl.DownloadSerializedApi<AllCoinPairs>(
                _client.GetStreamAsync("https://www.allcoin.com/api2/pairs").Result);

            Parallel.ForEach(ListOfCoins, c => Parallel.ForEach(ac.Data, _po, acCoin =>
            {
                String[] splitMarket = acCoin.Key.Split('_');
                if (splitMarket[1] == "BTC" && splitMarket[0] == c.TagName)
                {
                    double volume, price;
                    bool hasOrder;

                    switch (_bidRecentAsk)
                    {
                        case 0:
                            hasOrder = Double.TryParse(acCoin.Value.TopBid, NumberStyles.Float,
                                CultureInfo.InvariantCulture, out price);
                            break;
                        case 1:
                            hasOrder = Double.TryParse(acCoin.Value.TradePrice, NumberStyles.Float,
                                CultureInfo.InvariantCulture, out price);
                            break;
                        case 2:
                            hasOrder = Double.TryParse(acCoin.Value.TopAsk, NumberStyles.Float,
                                CultureInfo.InvariantCulture, out price);
                            break;
                        default:
                            hasOrder = Double.TryParse(acCoin.Value.TopBid, NumberStyles.Float,
                                CultureInfo.InvariantCulture, out price);
                            break;
                    }

                    if (Double.TryParse(acCoin.Value.Volume24HBtc, NumberStyles.Float,
                        CultureInfo.InvariantCulture, out volume))
                    {
                        Coin.Exchange acExchange = new Coin.Exchange
                        {
                            ExchangeName = "AllCoin",
                            BtcVolume = volume,
                            BtcPrice = price,
                            BuyOrders = new List<Coin.Exchange.Order>(),
                            SellOrders = new List<Coin.Exchange.Order>()
                        };

                        if (_getOrderDepth && hasOrder)
                        {
                            AllCoinOrders acOrders = JsonControl.DownloadSerializedApi<AllCoinOrders>(
                                _client.GetStreamAsync("https://www.allcoin.com/api2/depth/"
                                                       + acCoin.Key).Result);
                            foreach (KeyValuePair<string, double> newOrder in acOrders.Data.Buy)
                            {
                                double orderPrice;
                                if (double.TryParse(newOrder.Key, NumberStyles.Float,
                                    CultureInfo.InvariantCulture, out orderPrice))
                                {
                                    Coin.Exchange.Order order = new Coin.Exchange.Order
                                    {
                                        BtcPrice = orderPrice,
                                        BtcVolume = orderPrice*newOrder.Value,
                                        CoinVolume = newOrder.Value
                                    };
                                    acExchange.BuyOrders.Add(order);
                                }
                            }

                            foreach (KeyValuePair<string, double> newOrder in acOrders.Data.Sell)
                            {
                                double orderPrice;
                                if (double.TryParse(newOrder.Key, NumberStyles.Float,
                                    CultureInfo.InvariantCulture, out orderPrice))
                                {
                                    Coin.Exchange.Order order = new Coin.Exchange.Order
                                    {
                                        BtcPrice = orderPrice,
                                        BtcVolume = orderPrice*newOrder.Value,
                                        CoinVolume = newOrder.Value
                                    };
                                    acExchange.SellOrders.Add(order);
                                }
                            }
                        }
                        

                        if (acCoin.Value.Status != "1" || acCoin.Value.WalletStatus != "1")
                        {
                            acExchange.IsFrozen = true;
                        }

                        if (c.HasImplementedMarketApi)
                        {
                            c.Exchanges.Add(acExchange);
                            c.TotalExchange.BtcVolume += acExchange.BtcVolume;
                        }
                        else
                        {
                            c.Exchanges = new List<Coin.Exchange> {acExchange};
                            c.TotalExchange.BtcVolume = acExchange.BtcVolume;
                            c.HasImplementedMarketApi = true;
                        }
                    }

                    _po.CancellationToken.ThrowIfCancellationRequested();
                }
            }));
        }
예제 #4
0
        public void UpdateAllCrypt()
        {
            Cryptsy ac = JsonControl.DownloadSerializedApi<Cryptsy>(
                _client.GetStreamAsync("https://www.allcrypt.com/api?method=marketdatav2").Result);

            Parallel.ForEach(ListOfCoins, c => Parallel.ForEach(ac.Returns.Markets, _po, acCoin =>
            {
                if (acCoin.Value.SecondaryCode == "BTC" && ((acCoin.Value.PrimaryCode == c.TagName)
                    || (acCoin.Value.PrimaryCode == "STR" && c.TagName == "STAR")))
                {
                    double priceToUse;
                    switch (_bidRecentAsk)
                    {
                        case 0:
                            priceToUse = acCoin.Value.BuyOrders != null
                                && acCoin.Value.BuyOrders.Any()
                                ? acCoin.Value.BuyOrders[0].Price
                                : acCoin.Value.LastTradePrice;
                            break;
                        case 1:
                            priceToUse = acCoin.Value.LastTradePrice;
                            break;
                        case 2:
                            priceToUse = acCoin.Value.SellOrders != null
                                && acCoin.Value.SellOrders.Any()
                                ? acCoin.Value.SellOrders[0].Price
                                : acCoin.Value.LastTradePrice;
                            break;
                        default:
                            priceToUse = acCoin.Value.BuyOrders != null
                                && acCoin.Value.BuyOrders.Any()
                                ? acCoin.Value.BuyOrders[0].Price
                                : acCoin.Value.LastTradePrice;
                            break;
                    }

                    Coin.Exchange acExchange = new Coin.Exchange
                    {
                        ExchangeName = "AllCrypt",
                        BtcPrice = priceToUse,
                        BtcVolume = (acCoin.Value.Volume * priceToUse),
                        BuyOrders = new List<Coin.Exchange.Order>(),
                        SellOrders = new List<Coin.Exchange.Order>()
                    };

                    if (_getOrderDepth)
                    {
                        if (acCoin.Value.BuyOrders != null && acCoin.Value.BuyOrders.Any())
                        {
                            foreach (Cryptsy.Return.Market.Order newOrder in acCoin.Value.BuyOrders)
                            {
                                Coin.Exchange.Order order = new Coin.Exchange.Order
                                {
                                    BtcPrice = newOrder.Price,
                                    BtcVolume = newOrder.Total,
                                    CoinVolume = newOrder.Quantity
                                };
                                acExchange.BuyOrders.Add(order);
                            }
                        }

                        if (acCoin.Value.SellOrders != null && acCoin.Value.SellOrders.Any())
                        {
                            foreach (Cryptsy.Return.Market.Order newOrder in acCoin.Value.SellOrders)
                            {
                                Coin.Exchange.Order order = new Coin.Exchange.Order
                                {
                                    BtcPrice = newOrder.Price,
                                    BtcVolume = newOrder.Total,
                                    CoinVolume = newOrder.Quantity
                                };
                                acExchange.SellOrders.Add(order);
                            }
                        }
                    }

                    if (c.HasImplementedMarketApi)
                    {
                        c.Exchanges.Add(acExchange);
                        c.TotalExchange.BtcVolume += acExchange.BtcVolume;
                    }
                    else
                    {
                        c.Exchanges = new List<Coin.Exchange> { acExchange };
                        c.TotalExchange.BtcVolume = acExchange.BtcVolume;
                        c.HasImplementedMarketApi = true;
                    }

                    _po.CancellationToken.ThrowIfCancellationRequested();
                }
            }));
        }
예제 #5
0
        public void UpdateBittrex()
        {
            BittrexPairs bt = JsonControl.DownloadSerializedApi<BittrexPairs>(
                _client.GetStreamAsync("http://bittrex.com/api/v1.1/public/getmarketsummaries").Result);

            Parallel.ForEach(ListOfCoins, c => Parallel.ForEach(bt.Results, _po, btCoin =>
            {
                String[] splitMarket = btCoin.MarketName.Split('-');
                if (splitMarket[0] == "BTC" && splitMarket[1] == c.TagName)
                {
                    double priceToUse;
                    switch (_bidRecentAsk)
                    {
                        case 0:
                            priceToUse = btCoin.Bid;
                            break;
                        case 1:
                            priceToUse = btCoin.Last;
                            break;
                        case 2:
                            priceToUse = btCoin.Ask;
                            break;
                        default:
                            priceToUse = btCoin.Bid;
                            break;
                    }

                    Coin.Exchange btExchange = new Coin.Exchange
                    {
                        ExchangeName = "Bittrex",
                        BtcPrice = priceToUse,
                        BtcVolume = btCoin.BaseVolume,
                        BuyOrders = new List<Coin.Exchange.Order>(),
                        SellOrders = new List<Coin.Exchange.Order>()
                    };

                    if (_getOrderDepth && int.Parse(btCoin.OpenBuyOrders) > 0 && int.Parse(btCoin.OpenSellOrders) > 0)
                    {
                        BittrexOrders btOrders = JsonControl.DownloadSerializedApi<BittrexOrders>(
                            _client.GetStreamAsync("https://bittrex.com/api/v1.1/public/getorderbook?market="
                                                   + btCoin.MarketName + "&type=both&depth=50 ").Result);

                        if (btOrders.Success)
                        {
                            foreach (BittrexOrders.Results.Order result in btOrders.Result.Buy)
                            {
                                Coin.Exchange.Order order = new Coin.Exchange.Order
                                {
                                    BtcPrice = result.Rate,
                                    BtcVolume = result.Quantity*result.Rate,
                                    CoinVolume = result.Quantity
                                };
                                btExchange.BuyOrders.Add(order);
                            }

                            foreach (BittrexOrders.Results.Order result in btOrders.Result.Sell)
                            {
                                Coin.Exchange.Order order = new Coin.Exchange.Order
                                {
                                    BtcPrice = result.Rate,
                                    BtcVolume = result.Quantity*result.Rate,
                                    CoinVolume = result.Quantity
                                };
                                btExchange.SellOrders.Add(order);
                            }
                        }
                    }
                    
                    
                    if (c.HasImplementedMarketApi)
                    {
                        c.Exchanges.Add(btExchange);
                        c.TotalExchange.BtcVolume += btExchange.BtcVolume;
                    }
                    else
                    {
                        c.Exchanges = new List<Coin.Exchange> {btExchange};
                        c.TotalExchange.BtcVolume = btExchange.BtcVolume;
                        c.HasImplementedMarketApi = true;
                    }

                    _po.CancellationToken.ThrowIfCancellationRequested();
                }
            }));
        }
예제 #6
0
        public void UpdatePoloniex()
        {
            Dictionary<string, PoloniexPairs> pol = JsonControl.DownloadSerializedApi<Dictionary<string, PoloniexPairs>>(
                _client.GetStreamAsync("http://poloniex.com/public?command=returnTicker").Result);

            Parallel.ForEach(ListOfCoins, c => Parallel.ForEach(pol, _po, polCoin =>
            {
                String[] splitMarket = polCoin.Key.Split('_');
                if (splitMarket[0] == "BTC" && splitMarket[1] == c.TagName)
                {
                    double priceToUse;
                    switch (_bidRecentAsk)
                    {
                        case 0:
                            priceToUse = polCoin.Value.HighestBid;
                            break;
                        case 1:
                            priceToUse = polCoin.Value.Last;
                            break;
                        case 2:
                            priceToUse = polCoin.Value.LowestAsk;
                            break;
                        default:
                            priceToUse = polCoin.Value.HighestBid;
                            break;
                    }

                    Coin.Exchange polExchange = new Coin.Exchange
                    {
                        ExchangeName = "Poloniex",
                        BtcPrice = priceToUse,
                        BtcVolume = polCoin.Value.BaseVolume,
                        BuyOrders = new List<Coin.Exchange.Order>(),
                        SellOrders = new List<Coin.Exchange.Order>()
                    };

                    if (_getOrderDepth)
                    {
                        PoloniexOrders polOrders = JsonControl.DownloadSerializedApi<PoloniexOrders>(
                            _client.GetStreamAsync("https://poloniex.com/public?command=returnOrderBook&currencyPair="
                                                   + polCoin.Key + "&depth=100").Result);

                        if (polOrders.Bids != null && polOrders.Bids.Any())
                        {
                            foreach (double[] newOrder in polOrders.Bids)
                            {
                                Coin.Exchange.Order order = new Coin.Exchange.Order
                                {
                                    BtcPrice = newOrder[0],
                                    BtcVolume = newOrder[0]*newOrder[1],
                                    CoinVolume = newOrder[1]
                                };
                                polExchange.BuyOrders.Add(order);
                            }
                        }

                        if (polOrders.Asks != null && polOrders.Asks.Any())
                        {
                            foreach (double[] newOrder in polOrders.Asks)
                            {
                                Coin.Exchange.Order order = new Coin.Exchange.Order
                                {
                                    BtcPrice = newOrder[0],
                                    BtcVolume = newOrder[0]*newOrder[1],
                                    CoinVolume = newOrder[1]
                                };
                                polExchange.SellOrders.Add(order);
                            }
                        }
                    }

                    if (polCoin.Value.IsFrozen == "1")
                    {
                        polExchange.IsFrozen = true;
                    }

                    if (c.HasImplementedMarketApi)
                    {
                        c.Exchanges.Add(polExchange);
                        c.TotalExchange.BtcVolume += polExchange.BtcVolume;
                    }
                    else
                    {
                        c.Exchanges = new List<Coin.Exchange> {polExchange};
                        c.TotalExchange.BtcVolume = polExchange.BtcVolume;
                        c.HasImplementedMarketApi = true;
                    }

                    _po.CancellationToken.ThrowIfCancellationRequested();
                }
            }));
        }
예제 #7
0
        public void UpdateMintPal()
        {
            MintPalPairs mp = JsonControl.DownloadSerializedApi<MintPalPairs>(
                _client.GetStreamAsync("https://api.mintpal.com/v2/market/summary/BTC").Result);
            Exception errorOrders = null;

            Parallel.ForEach(ListOfCoins, c => Parallel.ForEach(mp.Data, _po, mpCoin =>
            {
                if (mpCoin.Exchange == "BTC" && mpCoin.Code == c.TagName)
                {
                    double priceToUse;
                    switch (_bidRecentAsk)
                    {
                        case 0:
                            priceToUse = mpCoin.TopBid;
                            break;
                        case 1:
                            priceToUse = mpCoin.LastPrice;
                            break;
                        case 2:
                            priceToUse = mpCoin.TopAsk;
                            break;
                        default:
                            priceToUse = mpCoin.TopBid;
                            break;
                    }

                    Coin.Exchange mpExchange = new Coin.Exchange
                    {
                        ExchangeName = "MintPal",
                        BtcPrice = priceToUse,
                        BtcVolume = mpCoin.Last24HVol,
                        BuyOrders = new List<Coin.Exchange.Order>(),
                        SellOrders = new List<Coin.Exchange.Order>()
                    };

                    if (_getOrderDepth)
                    {
                        try
                        {
                            MintPalOrders mpOrders;
                            mpOrders = JsonControl.DownloadSerializedApi<MintPalOrders>(
                                _client.GetStreamAsync("https://api.mintpal.com/v2/market/orders/"
                                                       + mpCoin.Code + "/BTC/ALL").Result);

                            foreach (MintPalOrders.Datas data in mpOrders.Data)
                            {
                                foreach (MintPalOrders.Datas.Order newOrder in data.Orders)
                                {
                                    double price, volume, coinVolume;
                                    if (Double.TryParse(newOrder.Price, NumberStyles.Float,
                                        CultureInfo.InvariantCulture, out price) &&
                                        Double.TryParse(newOrder.Total, NumberStyles.Float,
                                            CultureInfo.InvariantCulture, out volume) &&
                                        Double.TryParse(newOrder.Amount, NumberStyles.Float,
                                            CultureInfo.InvariantCulture, out coinVolume))
                                    {
                                        Coin.Exchange.Order order = new Coin.Exchange.Order
                                        {
                                            BtcPrice = price,
                                            BtcVolume = volume,
                                            CoinVolume = coinVolume
                                        };

                                        switch (data.Type)
                                        {
                                            case "buy":
                                                mpExchange.BuyOrders.Add(order);
                                                break;
                                            case "sell":
                                                mpExchange.SellOrders.Add(order);
                                                break;
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            errorOrders = e;
                        }
                    }
                    
                    if (c.HasImplementedMarketApi)
                    {
                        c.Exchanges.Add(mpExchange);
                        c.TotalExchange.BtcVolume += mpExchange.BtcVolume;
                    }
                    else
                    {
                        c.Exchanges = new List<Coin.Exchange> {mpExchange};
                        c.TotalExchange.BtcVolume = mpExchange.BtcVolume;
                        c.HasImplementedMarketApi = true;
                    }

                    _po.CancellationToken.ThrowIfCancellationRequested();
                }
            }));

            if (errorOrders != null)
            {
                throw new Exception("Error while trying to get order data from Mintpal. MP doesn't like a flood of requests.", errorOrders);
            }
        }
예제 #8
0
        public void UpdateAtomicTrade()
        {
            List<AtomicTradePair> atPairs = JsonControl.DownloadSerializedApi<List<AtomicTradePair>>(
                _client.GetStreamAsync("https://www.atomic-trade.com/SimpleAPI?a=marketsv2").Result);

            Parallel.ForEach(ListOfCoins, c => Parallel.ForEach(atPairs, _po, atCoin =>
            {
            /*foreach (Coin c in List)
            {
                foreach (var atCoin in atPairs)
                {*/
                    string[] split = atCoin.Market.Split('/');
                    if (split[1] == "BTC" && split[0] == c.TagName)
                    {
                        AtomicTradeOrders atOrders = JsonControl.DownloadSerializedApi<AtomicTradeOrders>(
                            _client.GetStreamAsync("https://www.atomic-trade.com/SimpleAPI?a=orderbook&p=BTC&c=" +
                                                   c.TagName).Result);

                        double priceToUse;
                        switch (_bidRecentAsk)
                        {
                            case 0:
                                if (atOrders.Market.Buyorders == null || !atOrders.Market.Buyorders.Any()
                                    || !double.TryParse(atOrders.Market.Buyorders[0].Price,
                                        NumberStyles.Float, CultureInfo.InvariantCulture, out priceToUse))
                                {
                                    priceToUse = 0;
                                }
                                break;
                            case 1:
                                if (!double.TryParse(atCoin.Price, NumberStyles.Float, 
                                    CultureInfo.InvariantCulture, out priceToUse))
                                {
                                    priceToUse = 0;
                                }
                                break;
                            case 2:
                                if (atOrders.Market.Sellorders == null || !atOrders.Market.Sellorders.Any()
                                    || !double.TryParse(atOrders.Market.Sellorders[0].Price,
                                        NumberStyles.Float, CultureInfo.InvariantCulture, out priceToUse))
                                {
                                    priceToUse = 0;
                                }
                                break;
                            default:
                                if (atOrders.Market.Buyorders == null || !atOrders.Market.Buyorders.Any()
                                    || !double.TryParse(atOrders.Market.Buyorders[0].Price,
                                        NumberStyles.Float, CultureInfo.InvariantCulture, out priceToUse))
                                {
                                    priceToUse = 0;
                                }
                                break;
                        }

                        Coin.Exchange atExchange = new Coin.Exchange
                        {
                            ExchangeName = "Atomic Trade",
                            BtcPrice = priceToUse,
                            BtcVolume = double.Parse(atCoin.Volume, NumberStyles.Float,
                            CultureInfo.InvariantCulture)*priceToUse,
                            BuyOrders = new List<Coin.Exchange.Order>(),
                            SellOrders = new List<Coin.Exchange.Order>()
                        };

                        if (_getOrderDepth)
                        {
                            if (atOrders.Market.Buyorders != null && atOrders.Market.Buyorders.Any())
                            {
                                foreach (AtomicTradeOrders.MarketData.Order newOrder in atOrders.Market.Buyorders)
                                {
                                    double price, volume, coinVolume;
                                    if (double.TryParse(newOrder.Price, NumberStyles.Float,
                                        CultureInfo.InvariantCulture, out price)
                                        && double.TryParse(newOrder.Total, NumberStyles.Float,
                                            CultureInfo.InvariantCulture, out volume)
                                        && double.TryParse(newOrder.Quantity, NumberStyles.Float,
                                            CultureInfo.InvariantCulture, out coinVolume))
                                    {
                                        Coin.Exchange.Order order = new Coin.Exchange.Order
                                        {
                                            BtcPrice = price,
                                            BtcVolume = volume,
                                            CoinVolume = coinVolume
                                        };
                                        atExchange.BuyOrders.Add(order);
                                    }
                                }
                            }

                            if (atOrders.Market.Sellorders != null && atOrders.Market.Sellorders.Any())
                            {
                                foreach (AtomicTradeOrders.MarketData.Order newOrder in atOrders.Market.Sellorders)
                                {
                                    double price, volume, coinVolume;
                                    if (double.TryParse(newOrder.Price, NumberStyles.Float,
                                        CultureInfo.InvariantCulture, out price)
                                        && double.TryParse(newOrder.Total, NumberStyles.Float,
                                            CultureInfo.InvariantCulture, out volume)
                                        && double.TryParse(newOrder.Quantity, NumberStyles.Float,
                                            CultureInfo.InvariantCulture, out coinVolume))
                                    {
                                        Coin.Exchange.Order order = new Coin.Exchange.Order
                                        {
                                            BtcPrice = price,
                                            BtcVolume = volume,
                                            CoinVolume = coinVolume
                                        };
                                        atExchange.SellOrders.Add(order);
                                    }
                                }
                            }
                        }

                        if (atCoin.Error == "1")
                        {
                            atExchange.IsFrozen = true;
                        }

                        if (c.HasImplementedMarketApi)
                        {
                            c.Exchanges.Add(atExchange);
                            c.TotalExchange.BtcVolume += atExchange.BtcVolume;
                        }
                        else
                        {
                            c.Exchanges = new List<Coin.Exchange> {atExchange};
                            c.TotalExchange.BtcVolume = atExchange.BtcVolume;
                            c.HasImplementedMarketApi = true;
                        }

                        _po.CancellationToken.ThrowIfCancellationRequested();
                    }
                //}}
            }));
        }
예제 #9
0
        public void UpdateBTer()
        {
            Dictionary<string, BTerPairs> btPairs = JsonControl.DownloadSerializedApi<Dictionary<string, BTerPairs>>(
                _client.GetStreamAsync("http://data.bter.com/api/1/tickers").Result);

            Parallel.ForEach(ListOfCoins, c => Parallel.ForEach(btPairs, _po, btCoin =>
            {
                /*foreach (Coin c in List)
                {
                    foreach (KeyValuePair<string, ...)
                    {*/
                string[] split = btCoin.Key.Split('_');
                if (split[1] == "btc" && split[0].ToUpperInvariant() == c.TagName)
                {
                    double priceToUse;
                    switch (_bidRecentAsk)
                    {
                        case 0:
                            if (!double.TryParse(btCoin.Value.Buy, NumberStyles.Float,
                                CultureInfo.InvariantCulture, out priceToUse)
                                && !double.TryParse(btCoin.Value.Last, NumberStyles.Float,
                                CultureInfo.InvariantCulture, out priceToUse))
                            {
                                priceToUse = 0;
                            }
                            break;
                        case 1:
                            if (!double.TryParse(btCoin.Value.Last, NumberStyles.Float,
                                CultureInfo.InvariantCulture, out priceToUse))
                            {
                                priceToUse = 0;
                            }
                            break;
                        case 2:
                            if (!double.TryParse(btCoin.Value.Sell, NumberStyles.Float,
                                CultureInfo.InvariantCulture, out priceToUse)
                                && !double.TryParse(btCoin.Value.Last, NumberStyles.Float,
                                CultureInfo.InvariantCulture, out priceToUse))
                            {
                                priceToUse = 0;
                            }
                            break;
                        default:
                            if (!double.TryParse(btCoin.Value.Buy, NumberStyles.Float,
                                CultureInfo.InvariantCulture, out priceToUse)
                                && !double.TryParse(btCoin.Value.Last, NumberStyles.Float,
                                CultureInfo.InvariantCulture, out priceToUse))
                            {
                                priceToUse = 0;
                            }
                            break;
                    }

                    Coin.Exchange btExchange = new Coin.Exchange
                    {
                        ExchangeName = "BTer",
                        BtcPrice = priceToUse,
                        BtcVolume = Convert.ToDouble(btCoin.Value.Vols["vol_btc"].ToString()),
                        BuyOrders = new List<Coin.Exchange.Order>(),
                        SellOrders = new List<Coin.Exchange.Order>()
                    };

                    if (_getOrderDepth)
                    {
                        BTerOrders btOrders = JsonControl.DownloadSerializedApi<BTerOrders>(
                            _client.GetStreamAsync("http://data.bter.com/api/1/depth/"
                                                   + btCoin.Key).Result);
                        foreach (double[] newOrder in btOrders.Bids)
                        {
                            Coin.Exchange.Order order = new Coin.Exchange.Order
                            {
                                BtcPrice = newOrder[0],
                                BtcVolume = newOrder[0]*newOrder[1],
                                CoinVolume = newOrder[1]
                            };
                            btExchange.BuyOrders.Add(order);
                        }

                        foreach (double[] newOrder in btOrders.Asks)
                        {
                            Coin.Exchange.Order order = new Coin.Exchange.Order
                            {
                                BtcPrice = newOrder[0],
                                BtcVolume = newOrder[0]*newOrder[1],
                                CoinVolume = newOrder[1]
                            };
                            btExchange.SellOrders.Add(order);
                        }
                    }

                    if (c.HasImplementedMarketApi)
                    {
                        c.Exchanges.Add(btExchange);
                        c.TotalExchange.BtcVolume += btExchange.BtcVolume;
                    }
                    else
                    {
                        c.Exchanges = new List<Coin.Exchange> { btExchange };
                        c.TotalExchange.BtcVolume = btExchange.BtcVolume;
                        c.HasImplementedMarketApi = true;
                    }

                    _po.CancellationToken.ThrowIfCancellationRequested();
                }
                //}
            }));
        }
예제 #10
0
        public void UpdateCryptoine()
        {
            CryptoinePairs cry = JsonControl.DownloadSerializedApi<CryptoinePairs>(
                _client.GetStreamAsync("https://cryptoine.com/api/1/markets").Result);

            Parallel.ForEach(ListOfCoins, c => Parallel.ForEach(cry.Data, _po, cryCoin =>
            {
                string[] split = cryCoin.Key.Split('_');
                if (split[1] == "btc" && split[0].ToUpperInvariant() == c.TagName)
                {
                    double priceToUse;
                    switch (_bidRecentAsk)
                    {
                        case 0:
                            if (!double.TryParse(cryCoin.Value.Buy, NumberStyles.Float, 
                                CultureInfo.InvariantCulture, out priceToUse))
                            {
                                priceToUse = cryCoin.Value.Last;
                            }
                            break;
                        case 1:
                            priceToUse = cryCoin.Value.Last;
                            break;
                        case 2:
                            if (!double.TryParse(cryCoin.Value.Sell, NumberStyles.Float, 
                                CultureInfo.InvariantCulture, out priceToUse))
                            {
                                priceToUse = cryCoin.Value.Last;
                            }
                            break;
                        default:
                            if (!double.TryParse(cryCoin.Value.Buy, NumberStyles.Float, 
                                CultureInfo.InvariantCulture, out priceToUse))
                            {
                                priceToUse = cryCoin.Value.Last;
                            }
                            break;
                    }

                    Coin.Exchange cryExchange = new Coin.Exchange
                    {
                        ExchangeName = "Cryptoine",
                        BtcPrice = priceToUse,
                        BtcVolume = (cryCoin.Value.VolBase),
                        BuyOrders = new List<Coin.Exchange.Order>(),
                        SellOrders = new List<Coin.Exchange.Order>()
                    };

                    if (_getOrderDepth)
                    {
                        CryptoineOrders cryOrders = JsonControl.DownloadSerializedApi<CryptoineOrders>(
                            _client.GetStreamAsync("https://cryptoine.com/api/1/depth/"
                                                   + cryCoin.Key).Result);
                        foreach (double[] newOrder in cryOrders.Bids)
                        {
                            Coin.Exchange.Order order = new Coin.Exchange.Order
                            {
                                BtcPrice = newOrder[0],
                                BtcVolume = newOrder[0]*newOrder[1],
                                CoinVolume = newOrder[1]
                            };
                            cryExchange.BuyOrders.Add(order);
                        }

                        foreach (double[] newOrder in cryOrders.Asks)
                        {
                            Coin.Exchange.Order order = new Coin.Exchange.Order
                            {
                                BtcPrice = newOrder[0],
                                BtcVolume = newOrder[0]*newOrder[1],
                                CoinVolume = newOrder[1]
                            };
                            cryExchange.SellOrders.Add(order);
                        }
                    }

                    if (c.HasImplementedMarketApi)
                    {
                        c.Exchanges.Add(cryExchange);
                        c.TotalExchange.BtcVolume += cryExchange.BtcVolume;
                    }
                    else
                    {
                        c.Exchanges = new List<Coin.Exchange> { cryExchange };
                        c.TotalExchange.BtcVolume = cryExchange.BtcVolume;
                        c.HasImplementedMarketApi = true;
                    }

                    _po.CancellationToken.ThrowIfCancellationRequested();
                }
                //}
            }));
        }
예제 #11
0
        public void UpdateMintPal()
        {
            MintPalPairs mp = JsonControl.DownloadSerializedApi<MintPalPairs>(
                _client.GetStreamAsync("https://api.mintpal.com/v2/market/summary/BTC").Result);

            foreach (Coin c in ListOfCoins)
            {
                foreach (MintPalPairs.Coin mpCoin in mp.Data)
                {
                    if (mpCoin.Exchange == "BTC" && mpCoin.Code == c.TagName)
                    {
                        double priceToUse;
                        switch (_bidRecentAsk)
                        {
                            case 0:
                                priceToUse = mpCoin.TopBid;
                                break;
                            case 1:
                                priceToUse = mpCoin.LastPrice;
                                break;
                            case 2:
                                priceToUse = mpCoin.TopAsk;
                                break;
                            default:
                                priceToUse = mpCoin.TopBid;
                                break;
                        }

                        Coin.Exchange mpExchange = new Coin.Exchange
                        {
                            ExchangeName = "MintPal",
                            BtcPrice = priceToUse,
                            BtcVolume = mpCoin.Last24HVol,
                            BuyOrders = new List<Coin.Exchange.Order>(),
                            SellOrders = new List<Coin.Exchange.Order>()
                        };

                        if (_getOrderDepth)
                        {
                                MintPalOrders mpOrders = JsonControl.DownloadSerializedApi<MintPalOrders>(
                                    new HttpClient().GetStreamAsync("https://api.mintpal.com/v2/market/orders/"
                                                           + mpCoin.Code + "/BTC/ALL").Result);

                                foreach (MintPalOrders.Datas data in mpOrders.Data)
                                {
                                    foreach (MintPalOrders.Datas.Order newOrder in data.Orders)
                                    {
                                        double price, volume, coinVolume;
                                        if (Double.TryParse(newOrder.Price, NumberStyles.Float,
                                            CultureInfo.InvariantCulture, out price) &&
                                            Double.TryParse(newOrder.Total, NumberStyles.Float,
                                                CultureInfo.InvariantCulture, out volume) &&
                                            Double.TryParse(newOrder.Amount, NumberStyles.Float,
                                                CultureInfo.InvariantCulture, out coinVolume))
                                        {
                                            Coin.Exchange.Order order = new Coin.Exchange.Order
                                            {
                                                BtcPrice = price,
                                                BtcVolume = volume,
                                                CoinVolume = coinVolume
                                            };

                                            switch (data.Type)
                                            {
                                                case "buy":
                                                    mpExchange.BuyOrders.Add(order);
                                                    break;
                                                case "sell":
                                                    mpExchange.SellOrders.Add(order);
                                                    break;
                                            }
                                        }
                                    }
                                }
                        }

                        if (c.HasImplementedMarketApi)
                        {
                            c.Exchanges.Add(mpExchange);
                            c.TotalExchange.BtcVolume += mpExchange.BtcVolume;
                        }
                        else
                        {
                            c.Exchanges = new List<Coin.Exchange> {mpExchange};
                            c.TotalExchange.BtcVolume = mpExchange.BtcVolume;
                            c.HasImplementedMarketApi = true;
                        }

                        break;
                    }
                }
            }
        }