Esempio n. 1
0
        /// <summary>
        /// Non fixed volume
        /// </summary>
        public decimal GetNonFixedVoulume()
        {
            var     _buy      = this.GetAssetBuy();
            var     _sell     = this.GetAssetSell();
            var     info_buy  = this.GetAssetInfoBuy();
            var     info_sell = this.GetAssetInfoSell();
            Ticker  _ticker   = this.GetTicker();
            decimal _fee      = this.GetFee();

            if (info_buy == null || info_sell == null || _ticker == null)
            {
                return(0);
            }


            decimal volumeFixed = this.GetFixedVolume();
            decimal volume      = 0;

            if (IsFixedBuy)
            {
                volume = _ticker.BuyPrice(_buy.Value, volumeFixed, _fee).MathRound(info_sell.DisplayDecimals);
            }
            else if (IsFixedSell)
            {
                volume = _ticker.SellPrice(_sell.Value, volumeFixed, _fee).MathRound(info_buy.DisplayDecimals);
            }

            return(volume);
        }
Esempio n. 2
0
        public void Update()
        {
            if (Manager.Kraken.Tickers == null || Manager.Kraken.Tickers.Length <= 0)
            {
                return;
            }

            for (int i = 0; i < Manager.Kraken.Tickers.Length; i++)
            {
                Ticker _ticker = Manager.Kraken.Tickers[i];
                Ticker ticker  = Manager.Kraken.CalculateExchangeTicker(_ticker); //calculates ticker for income

                if (ticker == null)
                {
                    continue;
                }

                InfoTicker infoTicker = SManager.InfoTickers(ticker.Name);
                infoTicker.Ask = ticker.BuyPrice(ticker.AssetBase.Value, 1);
                infoTicker.Bid = ticker.SellPrice(ticker.AssetBase.Value, 1);
            }

            if (Manager.Kraken == null || Manager.Kraken.ServerTime.IsDefault)
            {
                return;
            }

            SManager.ServerTime = Manager.Kraken.ServerTime;
        }
Esempio n. 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);
        }