/// <summary> /// this pair must be confirmed with ticker or assetpairs to be valid /// </summary> /// <param name="_base"></param> /// <param name="_quote"></param> /// <returns></returns> public static string ToPairString(Kraken.Asset _base, Kraken.Asset _quote) { string sbase = _base.GetEnumName(); string squote = _quote.GetEnumName(); if (sbase.IsNullOrEmpty() || squote.IsNullOrEmpty()) { return(null); } if (Kraken.IsCurrency(_base)) { sbase = "Z" + sbase; } else if (Kraken.IsCryptocurrency(_base)) { sbase = "X" + sbase; } if (Kraken.IsCurrency(_quote)) { squote = "Z" + squote; } else if (Kraken.IsCryptocurrency(_quote)) { squote = "X" + squote; } return(sbase + squote); }
public Fundings(Kind Name, Kraken.Asset Asset, AccountType Type, ValidationType Validation = ValidationType.None) { this.Name = Name.GetEnumDescription(); this.Asset = Asset; this.Type = Type; this.Validation = Validation; }
public static bool IsAssets(this AssetPair pair, Kraken.Asset _assetFirst, Kraken.Asset _assetSecond) { if (pair.IsPair(_assetFirst, _assetSecond) || pair.IsPair(_assetSecond, _assetFirst)) { return(true); } else { return(false); } }
public static bool IsAssets(this Ticker ticker, Kraken.Asset _assetFirst, Kraken.Asset _assetSecond) { if (ticker.IsPair(_assetFirst, _assetSecond) || ticker.IsPair(_assetSecond, _assetFirst)) { return(true); } else { return(false); } }
public static bool IsPair(this Ticker ticker, Kraken.Asset _base, Kraken.Asset _quote) { if (ticker.IsBase(_base) && ticker.IsQuote(_quote)) { return(true); } else { return(false); } }
public static bool IsPair(this AssetPair pair, Kraken.Asset _base, Kraken.Asset _quote) { if (pair.IsBase(_base) && pair.IsQuote(_quote)) { return(true); } else { return(false); } }
public static Fundings ToFundings(this FundingsJson json) { Fundings.Kind kind = Enums.ToEnumByDescription <Fundings.Kind>(json.Name); Kraken.Asset asset = Enums.ToEnumByDescription <Kraken.Asset>(json.Asset); Fundings.AccountType type = Enums.ToEnumByDescription <Fundings.AccountType>(json.Type); Fundings.ValidationType validation = Enums.ToEnumByDescription <Fundings.ValidationType>(json.Validation); Fundings fundings = new Fundings(kind, asset, type, validation); fundings.Address = json.Address; fundings.Tag = json.Tag; return(fundings); }
public decimal SellPrice(Kraken.Asset asset, decimal amount, decimal feeLinear) { if (this.IsBase(asset)) { decimal result = BidPrice * amount; return(result.AddPercentage(-feeLinear)); } else if (this.IsQuote(asset)) { decimal taxfree = amount.FindValueByPercentages(100m - feeLinear, 100m); return(taxfree / BidPrice); } throw new Exception("Specified assed is not falid for this ticker."); }
public Fundings Get(Fundings.AccountType type, Kraken.Asset asset, string name) { if (Fundings == null) { return(null); } for (int i = 0; i < Fundings.Count; i++) { if (Fundings[i].Type == type && Fundings[i].Asset == asset && Fundings[i].Name == name) { return(Fundings[i]); } } return(null); }
public Fundings[] Get(Fundings.AccountType type, Kraken.Asset asset) { if (Fundings == null) { return(null); } List <Fundings> fundings = new List <Fundings>(); for (int i = 0; i < Fundings.Count; i++) { if (Fundings[i].Type == type && Fundings[i].Asset == asset) { fundings.Add(Fundings[i]); } } return(fundings.ToArray()); }
/// <summary> /// returns unit value (ask) of asset in units of specified currency /// </summary> /// <param name="tickers"></param> /// <param name="_asset"></param> /// <param name="_currency"></param> /// <returns></returns> public static decimal?GetValueInCurrency(this Ticker[] tickers, Kraken.Asset _asset, Kraken.Currency _currency, decimal assetAmount = 1) { if (tickers == null || tickers.Length <= 0) { return(null); } if (_asset == Kraken.ToAsset(_currency)) { return(1); } if (Kraken.IsCurrency(_asset)) { decimal?ask1 = tickers.GetValueInCurrency(Kraken.Asset.XBT, Kraken.ToCurrency(_asset), 1); decimal?ask2 = tickers.GetValueInCurrency(Kraken.Asset.XBT, _currency, 1); if (ask1.IsNull() || ask2.IsNull()) { return(null); } return((decimal)ask2.Value / ask1.Value); } Kraken.Asset acurrency = Kraken.ToAsset(_currency); Ticker ticker = tickers.GetAny(_asset, acurrency); if (ticker == null) { return(null); } if (ticker.IsBase(_asset) && ticker.IsQuote(acurrency)) { return(ticker.Ask[0] * assetAmount); } else if (ticker.IsBase(acurrency) && ticker.IsQuote(_asset)) { return(((decimal)1 / ticker.Ask[0]) * assetAmount); } return(null); }
public static Ticker Get(this Ticker[] tickers, Kraken.Asset _base, Kraken.Asset _quote) { if (tickers == null || tickers.Length <= 0) { return(null); } string pair = Kraken.ToPairString(_base, _quote); foreach (Ticker ticker in tickers) { if (ticker.Name == pair) { return(ticker); } } return(null); }
public bool IsQuote(Kraken.Asset asset) { if (AssetPairs == null || AssetPairs.Length <= 0) { throw new Exception("AssetPairs are not loaded."); } for (int i = 0; i < AssetPairs.Length; i++) { var aquote = AssetPairs[i].AssetQuote; if (aquote != null && aquote.HasValue && aquote.Value == asset) { return(true); } } return(false); }
protected void UTbxAmountSecondaryReset(bool update = false) { if (!SManager.AssetSecondary.IsValid()) { return; } Kraken.Asset asset = SManager.AssetSecondary.Asset.Value; Asset info = Manager.Kraken.AssetInfo(asset); int decimals = info.GetDisplayDecimals(2); decimal amount = Math.Round(SManager.AssetSecondary.Amount, decimals); UTbxAmountSecondary.Text = amount.ToString("N" + decimals).Replace(",", ""); if (update) { UTbxAmountSecondary.Update(); } }
public static AssetPair GetAny(this AssetPair[] pairs, Kraken.Asset _assetFirst, Kraken.Asset _assetSecond) { if (pairs == null || pairs.Length <= 0) { return(null); } foreach (AssetPair pair in pairs) { if (pair == null) { continue; } if (pair.IsAssets(_assetFirst, _assetSecond)) { return(pair); } } return(null); }
public static AssetPair Get(this AssetPair[] pairs, Kraken.Asset _base, Kraken.Asset _quote) { if (pairs == null || pairs.Length <= 0) { return(null); } foreach (AssetPair pair in pairs) { if (pair == null) { continue; } if (pair.IsPair(_base, _quote)) { return(pair); } } return(null); }
protected void TbxAmountPrimary_TextChanged(object sender, EventArgs e) { if (!SManager.AssetPrimary.IsValid() || !SManager.AssetPrimary.IsFixed) { return; } //UTbxAmountSecondaryReset(true); Kraken.Asset asset = SManager.AssetPrimary.Asset.Value; Asset info = Manager.Kraken.AssetInfo(asset); if (info == null) { return; } /**/ //if (UTbxAmountSecondary.Text == "") UTbxAmountSecondaryReset(true); decimal value = UTbxAmountPrimary.Text.ParseDecimal(-1); if (value.CountPrecisionDigits() > info.DisplayDecimals) { string format = string.Format("<b>Info !</b> Primary amount precision is to high, no more then <b>{0}</b> decimals places allowed.", info.DisplayDecimals); AlertsControlPrimary.ShowInfo(format); } else { AlertsControlPrimary.HideInfo(); } value = Math.Round(value, info.DisplayDecimals); if (value > 0 && value < 100000000000000) { SManager.AssetPrimary.Amount = value; this.AlertsControlPrimary.HideWarning(); } else { //SManager.AssetPrimary.Amount = 0; this.AlertsControlPrimary.ShowWarning("<b>Warning !</b> Primary amount is invalid."); } this.InitializeTextBoxes(); } protected void TbxAmountSecondary_TextChanged(object sender, EventArgs e) { if (!SManager.AssetSecondary.IsValid() || !SManager.AssetSecondary.IsFixed) { return; } //UTbxAmountPrimaryReset(true); Kraken.Asset asset = SManager.AssetSecondary.Asset.Value; Asset info = Manager.Kraken.AssetInfo(asset); if (info == null) { return; } // if (UTbxAmountPrimary.Text == "") UTbxAmountPrimaryReset(true); /*if (UTbxAmountSecondary.Text == "" && SManager.AssetSecondary.CotrolsUpdateTextBox) * { * SManager.AssetSecondary.CotrolsUpdateTextBox = false; * UTbxAmountSecondaryReset(true); * }*/ decimal value = UTbxAmountSecondary.Text.ParseDecimal(-1); if (value.CountPrecisionDigits() > info.DisplayDecimals) { string format = string.Format("<b>Info !</b> Secondary amount precision is to high, no more then <b>{0}</b> decimals places allowed.", info.DisplayDecimals); this.AlertsControlSecondary.ShowInfo(format); } else { this.AlertsControlSecondary.HideInfo(); } value = Math.Round(value, info.DisplayDecimals); if (value > 0 && value < 100000000000000) { SManager.AssetSecondary.Amount = value; this.AlertsControlSecondary.HideWarning(); } else { //SManager.AssetSecondary.Amount = 0; this.AlertsControlSecondary.ShowWarning("<b>Warning !</b> Secondary amount is invalid."); } this.InitializeTextBoxes(); }