コード例 #1
0
        private void InitializeTextBoxes()
        {
            if (SManager == null)
            {
                return;
            }

            ExchangeSettings settings = SManager.CalculateExchangeSettings(Manager);

            if (settings == null || settings.Error)
            {
                return;
            }

            if (SManager.AssetPrimary.IsFixed)
            {
                #region Setup Primary

                if (!settings.Primary.IsAmountValid) //incorrect amoont outsoide of limmits
                {
                    string fromat = string.Format("<b>Warning ! </b> Primary value of {0} <b>{1}</b> is out of allowed range min {2}, max {3}"
                                                  , settings.Primary.Amount, settings.Primary.Asset.GetEnumName(), settings.Primary.MinAmount, settings.Primary.MaxAmount);
                    AlertsControlPrimary.ShowWarning(fromat);
                }

                if (UTbxAmountSecondary.Text.ParseDecimal(-1) != settings.Secondary.Amount)
                {
                    UTbxAmountSecondaryReset(true);
                }

                #endregion
            }
            else if (SManager.AssetSecondary.IsFixed)
            {
                #region Setup Secondary


                if (!settings.Secondary.IsAmountValid) //incorrect amoont outsoide of limmits
                {
                    string fromat = string.Format("<b>Warning ! </b>Secondary value of {0} <b>{1}</b> is out of allowed range min {2}, max {3}"
                                                  , settings.Secondary.Amount, settings.Secondary.Asset.GetEnumName(), settings.Secondary.MinAmount, settings.Secondary.MaxAmount);
                    AlertsControlSecondary.ShowWarning(fromat);
                }

                if (UTbxAmountPrimary.Text.ParseDecimal(-1) != settings.Primary.Amount)
                {
                    UTbxAmountPrimaryReset(true);
                }

                #endregion
            }

            this.InitializeTextBoxesColors();
        }
コード例 #2
0
        protected void BtnOrderExecute_Click(object sender, EventArgs e)
        {
            if (SManager == null || SManager.AssetPrimary.Asset == null || SManager.AssetSecondary.Asset == null)
            {
                AlertsControlExecute.ShowWarning("Session ended, plese refresh this webpage !");
                SManager.ExchangeOrder.TimeoutWarningsExecute = TickTime.Now;
                return;
            }

            this.InitializeTerms();

            //cannot proceed, used must agree to terms and conditions
            if (!CmbxOrderAccept.Checked)
            {
                UpdPnlOrderControl.Update();
                return;
            }

            ExchangeSettings settings = SManager.CalculateExchangeSettings(Manager);

            if (settings == null || !settings.Primary.IsAmountValid || !settings.Secondary.IsAmountValid)
            {
                AlertsControlExecute.ShowWarning("<b>Warning ! </b>Exchange Settings are invalid !");
                SManager.ExchangeOrder.TimeoutWarningsExecute = TickTime.Now;
                return;
            }

            if (SManager.FundingWithdraw == null ||
                SManager.FundingDeposit == null ||
                SManager.FundingWithdraw.Fundings == null ||
                SManager.FundingDeposit.Fundings == null ||
                !SManager.FundingWithdraw.Fundings.IsValid ||
                !SManager.FundingDeposit.Fundings.IsValid)
            {
                AlertsControlExecute.ShowWarning("<b>Warning ! </b>Fundings Settings are invalid !");
                SManager.ExchangeOrder.TimeoutWarningsExecute = TickTime.Now;
                return;
            }

            this.Execute();
        }
コード例 #3
0
        public ExchangeSettings CalculateExchangeSettings(ExchangeManager Manager)
        {
            ExchangeSettings exchange  = new ExchangeSettings();
            ExchangeAsset    primary   = new ExchangeAsset();
            ExchangeAsset    secondary = new ExchangeAsset();

            if (Manager == null || AssetPrimary.Asset == null || AssetSecondary.Asset == null)
            {
                return(null);
            }

            primary.Asset             = AssetPrimary.Asset.Value;
            secondary.Asset           = AssetSecondary.Asset.Value;
            primary.Info              = Manager.Kraken.AssetInfo(primary.Asset);
            secondary.Info            = Manager.Kraken.AssetInfo(secondary.Asset);
            primary.DisplayDecimals   = primary.Info.GetDisplayDecimals(2);
            secondary.DisplayDecimals = secondary.Info.GetDisplayDecimals(2);

            //Get min and max amounts
            decimal[] min = Manager.Kraken.MinAmount(primary.Asset, secondary.Asset);
            decimal[] max = Manager.Kraken.MaxAmount(primary.Asset, secondary.Asset);//TODO: Fail secondary

            if (min == null || max == null || min[0] <= 0 || min[1] <= 0 || max[0] <= 0 || max[1] <= 0)
            {
                return(null);
            }

            Ticker _ticker = Manager.Kraken.Tickers.GetAny(primary.Asset, secondary.Asset);
            Ticker ticker  = Manager.Kraken.CalculateExchangeTicker(_ticker); //calculates ticker for income

            if (ticker == null || ticker.AssetBase == null || ticker.AssetQuote == null)
            {
                return(null);
            }

            primary.MinAmount   = Math.Round(min[0], primary.DisplayDecimals);
            primary.MaxAmount   = Math.Round(max[0], primary.DisplayDecimals);
            secondary.MinAmount = Math.Round(min[1], secondary.DisplayDecimals);
            secondary.MaxAmount = Math.Round(max[1], secondary.DisplayDecimals);

            if (AssetPrimary.IsFixed)
            {
                #region Setup Primary
                primary.Amount = AssetPrimary.Amount;

                if (AssetPrimary.Buy)
                {
                    secondary.Amount = ticker.BuyPrice(primary.Asset, primary.Amount);
                }
                else if (AssetPrimary.Sell)
                {
                    secondary.Amount = ticker.SellPrice(primary.Asset, primary.Amount);
                }
                else
                {
                    return(null);
                }

                AssetSecondary.Amount = Math.Round(secondary.Amount, secondary.DisplayDecimals);

                #endregion
            }
            else if (AssetSecondary.IsFixed)
            {
                #region Setup Secondary
                secondary.Amount = AssetSecondary.Amount;

                if (AssetSecondary.Buy)
                {
                    primary.Amount = ticker.BuyPrice(secondary.Asset, secondary.Amount);
                }
                else if (AssetSecondary.Sell)
                {
                    primary.Amount = ticker.SellPrice(secondary.Asset, secondary.Amount);
                }
                else
                {
                    return(null);
                }

                AssetPrimary.Amount = Math.Round(primary.Amount, primary.DisplayDecimals);

                #endregion
            }
            else
            {
                return(null);
            }



            exchange.Primary   = primary;
            exchange.Secondary = secondary;

            return(exchange);
        }