Esempio n. 1
0
 public override void Process(IListResponse <Coin, CoinData> mr)
 {
     foreach (CoinData data in mr.Data)
     {
         CoinInfo.ListingStatus listingstatus = CryptoShark2.CoinInfo.ListingStatusConverter(data.ListingStatus);
         CoinInfo.CoinStatus    coinstatus    = CryptoShark2.CoinInfo.CoinStatusConverter(data.Status);
         bool     enabled = ValidateStatus(data.Status);
         CoinInfo ci      = new CoinInfo(data.Id, data.Name, data.Symbol, data.Algorithm, null, data.WithdrawFee, data.MinWithdraw, Convert.ToInt32(data.DepositConfirmations), null, enabled, enabled, coinstatus, data.StatusMessage, null, null);
         this._Data.Add(data.Symbol, ci);
     }
 }
Esempio n. 2
0
        private void btnSimSell_Click(object sender, RoutedEventArgs e)
        {
            string pair           = txtTradePair.Text;
            string pairCoin       = InitializeSim(pair);
            double currencyAmount = Convert.ToDouble(txtCurrencyAmount.Text);

            foreach (KeyValuePair <string, IExchange> kv in ExchangeList)
            {
                IExchange ex = kv.Value;

                bool ignoreInactive            = (bool)configuration.UiSettings["menuOptionsIgnoreInactive"];
                CoinInfo.CoinStatus coinStatus = CoinInfo.CoinStatus.OK;

                // If the ignoreInactive option is set, pretend that the pair is active even if it isn't.
                // Otherwise, use the actual IsActive value
                if (!ignoreInactive)
                {
                    if (!(ex.CoinInfo.ContainsKey(pairCoin) && coinStatus == CoinInfo.CoinStatus.OK))
                    {
                        coinStatus = CoinInfo.CoinStatus.Unknown;
                    }
                }

                bool haskey = ex.Markets.ContainsKey(pair);

                if (ex.Summary.ContainsKey(pair) && coinStatus == CoinInfo.CoinStatus.OK)
                {
                    BuyPower sell = new BuyPower();
                    sell.SellDepth = 0;
                    sell.Volume    = currencyAmount;
                    sell.Balance   = 0;

                    double   minTradeAmount = ex.Markets[pair].MinTradeSize;
                    double   fee            = ex.Markets[pair].MakerFeeRate;
                    BookInfo book           = ex.GetOrderBook(pair);



                    foreach (BookInfo.Order order in book.Buys)
                    {
                        if (sell.Volume * order.Price > minTradeAmount)
                        {
                            double priceMinusFee;
                            double total = order.Price * order.Volume;
                            sell.SellDepth++;

                            if (sell.Volume >= order.Volume)
                            {
                                priceMinusFee = total - (total * fee);
                                sell.Volume  -= order.Volume;
                                sell.Balance += priceMinusFee;
                            }
                            else
                            {
                                priceMinusFee = (sell.Volume * order.Price) - (sell.Volume * order.Price * fee);
                                sell.Volume   = 0;
                                sell.Balance += priceMinusFee;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    double sold = currencyAmount - sell.Volume;

                    txtResults.Text += "\n" + kv.Key + " (" + pair + ")\n";
                    txtResults.Text += "Sold " + sold.ToString() + " " + pairCoin + " for " + sell.Balance.ToString() + " " + pairBase + " (" + (sell.Balance / sold).ToString("F8") + ")\n";

                    txtResults.ScrollToEnd();
                }
            }
        }
Esempio n. 3
0
        private void btnSimBuy_Click(object sender, RoutedEventArgs e)
        {
            string pair       = txtTradePair.Text;
            string pairCoin   = InitializeSim(pair);
            double baseamount = Convert.ToDouble(txtBaseAmount.Text);

            foreach (KeyValuePair <string, IExchange> kv in ExchangeList)
            {
                IExchange ex = kv.Value;

                bool ignoreInactive            = (bool)configuration.UiSettings["menuOptionsIgnoreInactive"];
                CoinInfo.CoinStatus coinStatus = CoinInfo.CoinStatus.OK;

                // If the ignoreInactive option is set, pretend that the pair is active even if it isn't.
                // Otherwise, use the Unknown value.
                if (!ignoreInactive)
                {
                    coinStatus = ex.CoinInfo[pairCoin].Status;
                    if (!(ex.CoinInfo.ContainsKey(pairCoin) && coinStatus == CoinInfo.CoinStatus.OK))
                    {
                        coinStatus = CoinInfo.CoinStatus.Unknown;
                    }
                }

                if (ex.Summary.ContainsKey(pair) && coinStatus == CoinInfo.CoinStatus.OK)
                {
                    BuyPower buy = new BuyPower();
                    buy.SellDepth = 0;
                    buy.Volume    = 0;
                    buy.Balance   = baseamount;

                    double   fee  = ex.Markets[pair].TakerFeeRate;
                    BookInfo book = ex.GetOrderBook(pair);

                    foreach (BookInfo.Order order in book.Sells)
                    {
                        double totalPrice      = order.Price * order.Volume;
                        double pricePlusFee    = totalPrice + (totalPrice * fee);
                        double minPricePlusFee = order.Price + (order.Price * fee);
                        double maxShares       = buy.Balance / order.Price;
                        double maxPricePlusFee = (maxShares * order.Price) + (maxShares * order.Price * fee);
                        double minTradeAmount  = ex.Markets[pair].MinTradeSize;

                        if (buy.Balance > minPricePlusFee)
                        {
                            buy.BuyDepth++;
                            double total        = order.Price * order.Volume;
                            double priceplusfee = total + (total * fee);

                            if (buy.Balance > priceplusfee)
                            {
                                buy.Volume  += order.Volume;
                                buy.Balance -= priceplusfee;
                            }
                            else
                            {
                                while (buy.Balance < maxPricePlusFee)
                                {
                                    maxShares      -= 1;
                                    maxPricePlusFee = (maxShares * order.Price) + (maxShares * order.Price * fee);
                                }

                                buy.Volume  += maxShares;
                                buy.Balance -= maxPricePlusFee;
                                break;
                            }
                        }
                    }

                    double spent = baseamount - buy.Balance;

                    txtResults.Text += "\n" + kv.Key + " (" + pair + ")\n";
                    txtResults.Text += "Bought " + buy.Volume.ToString() + " " + pairCoin + " for " + spent.ToString() + " " + pairBase + " (" + (spent / buy.Volume).ToString("F8") + ")\n";

                    txtResults.ScrollToEnd();
                }
            }
        }