Beispiel #1
0
        private void InitBittrex(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabBittrex);

            txtBittrexFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtBittrexLeftover.Text    = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtBittrexDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtBittrexWeight.Text      = (exchange.Weight * 100).ToString("0.##") + "%";

            linkBittrex.Text     = "Bittrex: " + _usedCoin.TagName + "/BTC";
            linkBittrex.Links[0] = new LinkLabel.Link(0, linkBittrex.Text.Length,
                                                      "https://bittrex.com/Market/Index?MarketName=BTC-" + _usedCoin.TagName);

            UpdateBittrex(exchange);
        }
Beispiel #2
0
        private void InitBTer(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabBTer);

            txtBterFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtBterLeftover.Text    = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtBterDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtBterWeight.Text      = (exchange.Weight * 100).ToString("0.##") + "%";

            linkBter.Text     = "BTer: " + _usedCoin.TagName + "/BTC";
            linkBter.Links[0] = new LinkLabel.Link(0, linkBter.Text.Length,
                                                   "https://bter.com/trade/" + _usedCoin.TagName.ToLowerInvariant() + "_btc");

            UpdateBTer(exchange);
        }
Beispiel #3
0
        private void InitMintPal(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabMintpal);

            txtMintpalFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtMintpalLeftover.Text    = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtMintpalDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtMintpalWeight.Text      = (exchange.Weight * 100).ToString("0.##") + "%";

            linkMintpal.Text     = "MintPal: " + _usedCoin.TagName + "/BTC";
            linkMintpal.Links[0] = new LinkLabel.Link(0, linkMintpal.Text.Length,
                                                      "https://www.mintpal.com/market/" + _usedCoin.TagName + "/BTC");

            UpdateMintpal(exchange);
        }
Beispiel #4
0
        private void InitCCex(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabCCex);

            txtCcexFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtCcexLeftover.Text    = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtCcexDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtCcexWeight.Text      = (exchange.Weight * 100).ToString("0.##") + "%";

            linkCcex.Text     = "C-Cex: " + _usedCoin.TagName + "/BTC";
            linkCcex.Links[0] = new LinkLabel.Link(0, linkCcex.Text.Length,
                                                   "https://c-cex.com/?p=" + _usedCoin.TagName.ToLowerInvariant() + "-btc");

            UpdateCCex(exchange);
        }
Beispiel #5
0
        private void InitAllCrypt(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabAllCrypt);

            txtAllcryptFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtAllcryptLeftover.Text    = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtAllcryptDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtAllcryptWeight.Text      = (exchange.Weight * 100).ToString("0.##") + "%";

            linkAllcrypt.Text     = "Allcrypt: " + _usedCoin.TagName + "/BTC";
            linkAllcrypt.Links[0] = new LinkLabel.Link(0, linkAllcrypt.Text.Length,
                                                       "https://www.google.com/search?q=allcrypt+" + _usedCoin.TagName + "+btc&btnI=&gws_rd=ssl");

            UpdateAllCrypt(exchange);
        }
Beispiel #6
0
        private void InitAllCoin(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabAllCoin);

            txtAllcoinFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtAllcoinLeftover.Text    = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtAllcoinDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtAllcoinWeight.Text      = (exchange.Weight * 100).ToString("0.##") + "%";

            linkAllcoin.Text     = "Allcoin: " + _usedCoin.TagName + "/BTC";
            linkAllcoin.Links[0] = new LinkLabel.Link(0, linkAllcoin.Text.Length,
                                                      "https://www.allcoin.com/trade/" + _usedCoin.TagName + "_BTC");

            UpdateAllcoin(exchange);
        }
Beispiel #7
0
        private void InitCryptoine(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabCryptoine);

            txtCryptoineFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtCryptoineLeftover.Text    = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtCryptoineDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtCryptoineWeight.Text      = (exchange.Weight * 100).ToString("0.##") + "%";

            linkCryptoine.Text     = "Cryptoine: " + _usedCoin.TagName + "/BTC";
            linkCryptoine.Links[0] = new LinkLabel.Link(0, linkCryptoine.Text.Length,
                                                        "https://cryptoine.com/trade/" + _usedCoin.TagName.ToLowerInvariant() + "_btc");

            UpdateCryptoine(exchange);
        }
Beispiel #8
0
        private void InitAtomic(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabAtomicTrade);

            txtAtomicFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtAtomicLeftover.Text    = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtAtomicDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtAtomicWeight.Text      = (exchange.Weight * 100).ToString("0.##") + "%";

            linkAtomic.Text     = "Atomic: " + _usedCoin.TagName + "/BTC";
            linkAtomic.Links[0] = new LinkLabel.Link(0, linkAtomic.Text.Length,
                                                     "https://www.atomic-trade.com/markets");

            UpdateAtomic(exchange);
        }
Beispiel #9
0
        private void UpdateCryptoine(Coin.Exchange exchange)
        {
            chkCryptoineBtc.Checked     = _useBtc;
            lblCryptoineDepth.Text      = "Depth: " + _depth + " orders";
            trackCryptoineDepth.Value   = _depth;
            lblCryptoineBox.Text        = "Box percentage: " + _boxPercentage + "% - " + (100 - _boxPercentage) + "%";
            trackCryptoineBox.Value     = _boxPercentage;
            lblCryptoineWhisker.Text    = "Whisker percentage: " + _whiskerPercentage + "% - " + (100 - _whiskerPercentage) + "%";
            trackCryptoineWhisker.Value = _whiskerPercentage;

            double[] yBuyValues = GetBoxPlotValues(_boxPercentage, _whiskerPercentage, _depth,
                                                   exchange.BuyOrders, _useBtc);
            chartCryptoineBuy.Series["BoxPlotSeries"].Points.Clear();
            chartCryptoineBuy.Series["BoxPlotSeries"].Points.Add(yBuyValues);
            dgvCryptoineBuy.DataSource = exchange.BuyOrders;

            double[] ySellValues = GetBoxPlotValues(_boxPercentage, _whiskerPercentage, _depth,
                                                    exchange.SellOrders, _useBtc);
            chartCryptoineSell.Series["BoxPlotSeries"].Points.Clear();
            chartCryptoineSell.Series["BoxPlotSeries"].Points.Add(ySellValues);
            dgvCryptoineSell.DataSource = exchange.SellOrders;
        }
Beispiel #10
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();
                }
                //}
            }));
        }
Beispiel #11
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();
                }
            }));
        }
Beispiel #12
0
        private void AddPoolPickerPool(PoolPicker.Pool pool, List<PoolPicker.Pool.Algo> profitList, string algo, 
            DateTime whenToEnd, bool reviewCalc, double reviewPercentage)
        {
            Coin c = new Coin
            {
                HasImplementedMarketApi = true,
                IsMultiPool = true,
            };
            Coin.Exchange ppExchange = new Coin.Exchange { ExchangeName = pool.Name, };
            c.Exchanges.Add(ppExchange);

            c.Algo = algo;
            c.FullName = pool.Name + " " + c.Algo + " (PP)";
            c.TagName = "PP" + pool.Id + c.Algo;

            double dAverage = 0;
            int iCounter;
            for (iCounter = 0; iCounter < profitList.Count; iCounter++)
            {
                PoolPicker.Pool.Algo profit = profitList[iCounter];
                DateTime profitDate = DateTime.ParseExact(profit.Date, "yyyy-MM-dd",
                    CultureInfo.InvariantCulture);

                if (profitDate.Date < whenToEnd.Date)
                {
                    break;
                }

                dAverage += profit.Btc;
                
                if (profitDate.Date.Equals(whenToEnd.Date)) break;
            }

            c.Exchanges[0].BtcPrice = 
                c.Algo == "KECCAK" || c.Algo == "SHA256"
                ? dAverage/(iCounter + 1)
                : dAverage/(iCounter + 1)*1000;

            if (reviewCalc)
            {
                c.Exchanges[0].BtcPrice *= reviewPercentage;
            }

            c.Source = "PoolPicker.eu";
            c.Retrieved = DateTime.Now;

            Add(c);
        }
Beispiel #13
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();
                    }
                //}}
            }));
        }
Beispiel #14
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);
            }
        }
Beispiel #15
0
        public void UpdateCrypToday(decimal average)
        {
            CrypToday ct = JsonControl.DownloadSerializedApi<CrypToday>(
                _client.GetStreamAsync("http://cryp.today/data").Result);
            Coin[] tempMultipools = new Coin[ct.Cols.Count-1];

            Parallel.For(0, ct.Cols.Count - 1, _po, i =>
            {
                string[] splitNameAndAlgo = ct.Cols[i + 1].Label.Split(' ');
                tempMultipools[i] = new Coin();
                switch (splitNameAndAlgo[1])
                {
                    case "X11":
                    case "X13":
                        tempMultipools[i].Algo = splitNameAndAlgo[1];
                        break;
                    case "N":
                        tempMultipools[i].Algo = "SCRYPTN";
                        break;
                    //case "S":
                    default:
                        tempMultipools[i].Algo = "SCRYPT";
                        break;
                }

                tempMultipools[i].FullName = ct.Cols[i + 1].Label + " (CT)";
                tempMultipools[i].TagName = "CT" + i + tempMultipools[i].Algo;

                tempMultipools[i].HasImplementedMarketApi = true;
                tempMultipools[i].IsMultiPool = true;

                Coin.Exchange ctExchange = new Coin.Exchange {ExchangeName = splitNameAndAlgo[0]};
                tempMultipools[i].Exchanges.Add(ctExchange);
            });

            for (int i = ct.Rows.Count - 1; i >= ct.Rows.Count - average; i--)
            {
                int row = i;
                Parallel.For(1, ct.Rows[i].Results.Count, _po, column =>
                {
                    double priceHolder;
                    if (!string.IsNullOrWhiteSpace(ct.Rows[row].Results[column].Btc) &&
                        double.TryParse(ct.Rows[row].Results[column].Btc, NumberStyles.Float,
                            CultureInfo.InvariantCulture, out priceHolder))
                    {
                        tempMultipools[column - 1].Exchanges[0].BtcPrice += priceHolder;
                        // Temp storing amount of not-null BtcPerDays into BlockReward
                        tempMultipools[column - 1].BlockReward++;
                    }
                });
            }

            foreach (Coin c in tempMultipools)
            {
                switch (c.Algo)
                {
                    case "X11":
                        c.Exchanges[0].BtcPrice /= 5.2;
                        break;
                    case "X13":
                        c.Exchanges[0].BtcPrice /= 3;
                        break;
                    case "SCRYPTN":
                        c.Exchanges[0].BtcPrice /= 0.47;
                        break;
                }

                c.Exchanges[0].BtcPrice /= c.BlockReward;
                c.Exchanges[0].BtcPrice *= 1000;
                c.BlockReward = 0;

                c.Source = "Cryp.Today";
                c.Retrieved = DateTime.Now;

                Add(c);
            }
        }
Beispiel #16
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();
                }
            }));
        }
Beispiel #17
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();
                        }
                    //}
                }));
        }
Beispiel #18
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();
                }
                //}
            }));
        }
Beispiel #19
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();
                }
            }));
        }
Beispiel #20
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();
                }
            }));
        }
Beispiel #21
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();
                }
            }));
        }
Beispiel #22
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;
                    }
                }
            }
        }