/// <summary> Determine if we can deposit asset. </summary> /// /// <remarks> Paul, 15/02/2015. </remarks> /// /// <param name="asset"> The asset. </param> /// /// <returns> true if we can deposit asset, false if not. </returns> public override bool CanDepositAsset(CurrenciesRow asset) { CurrenciesRow baseSymbol, quoteSymbol; CurrencyHelpers.GetBaseAndQuoteFromSymbolPair(m_market.symbol_pair, m_daemon.m_AllCurrencies, out baseSymbol, out quoteSymbol); return(baseSymbol == asset || quoteSymbol == asset); }
/// <summary> Handles the command. </summary> /// /// <remarks> Paul, 26/02/2015. </remarks> /// /// <param name="l"> The BitsharesLedgerEntry to process. </param> /// <param name="handler"> The handler. </param> /// <param name="market"> The market. </param> /// /// <returns> true if it succeeds, false if it fails. </returns> public bool HandleCommand(BitsharesLedgerEntry l, MarketBase handler, MarketRow market, string trxid) { if (m_adminUsernames.Contains(l.from_account)) { try { string[] parts = l.memo.Split(' '); if (l.memo.StartsWith(kSetPricesMemoStart)) { HandlePriceSetting(parts, l, handler, market); return(true); } else if (l.memo.StartsWith(kWithdrawMemo)) { // process withdrawal if (parts[0] == kWithdrawMemo) { // make sure we didn't already process this transaction! if (!m_dataAccess.IsWithdrawalProcessed(trxid)) { decimal amount = decimal.Parse(parts[1]); CurrenciesRow type = CurrencyHelpers.FromSymbol(parts[2], m_allCurrencies); string to; string txid; if (!CurrencyHelpers.IsBitsharesAsset(type)) { to = m_dataAccess.GetStats().bitcoin_withdraw_address; Debug.Assert(to != null); txid = m_bitcoin.SendToAddress(to, amount); } else { to = l.from_account; BitsharesTransactionResponse response = m_bitshares.WalletTransfer(amount, CurrencyHelpers.ToBitsharesSymbol(type), m_bitsharesAccount, to); txid = response.record_id; } // log in DB m_dataAccess.InsertWithdrawal(trxid, txid, type.ToString(), amount, to, DateTime.UtcNow); } return(true); } } } catch (Exception e) { LogGeneralException(e.ToString()); } } return(false); }
public void ToBitsharesSymbol() { for (int i = 0; i < (int)CurrencyTypesDep.max; i++) { CurrencyTypesDep type = (CurrencyTypesDep)i; CurrenciesRow newType = m_currencies[type.ToString()]; Assert.AreEqual(CurrencyHelpersDep.ToBitsharesSymbol(type), CurrencyHelpers.ToBitsharesSymbol(newType)); } }
public static decimal CalculateOfferPrice(OffersRow offer, CurrenciesRow neededCurrency) { using (var connection = SqlConnections.NewFor <OffersRow>()) { var currencyFields = CurrenciesRow.Fields; var currencyOffer = connection.First <CurrenciesRow>(currencyFields.Id == offer.CurrencyId.Value); if (offer.CurrencyId == neededCurrency.Id) { return(new Money(offer.Price ?? 0, Currency.FromCode(currencyOffer.CurrencyId)).Amount); } else { if (currencyOffer.BaseCurrencyId.HasValue) { ExchangeRate exchangeRateOffer; var baseCurrency = connection.First <CurrenciesRow>( currencyFields.Id == currencyOffer.BaseCurrencyId.Value); exchangeRateOffer = new ExchangeRate(Currency.FromCode(baseCurrency.CurrencyId), Currency.FromCode(currencyOffer.CurrencyId), currencyOffer.Rate ?? 0); if (baseCurrency.Id == neededCurrency.Id) { return(exchangeRateOffer .Convert(new Money(offer.Price ?? 0, Currency.FromCode(currencyOffer.CurrencyId))).Amount); } else { var tempPriceOffer = exchangeRateOffer.Convert( new Money(offer.Price ?? 0, Currency.FromCode(currencyOffer.CurrencyId))); var exchangeRateNeeded = new ExchangeRate(Currency.FromCode(baseCurrency.CurrencyId), Currency.FromCode(neededCurrency.CurrencyId), neededCurrency.Rate ?? 0); return(exchangeRateNeeded.Convert(tempPriceOffer).Amount); } } else { var exchangeRateNeeded = new ExchangeRate(Currency.FromCode(currencyOffer.CurrencyId), Currency.FromCode(neededCurrency.CurrencyId), neededCurrency.Rate ?? 0); return(exchangeRateNeeded .Convert(new Money(offer.Price ?? 0, Currency.FromCode(currencyOffer.CurrencyId))).Amount); } } } }
/// <summary> Constructor. </summary> /// /// <remarks> Paul, 05/02/2015. </remarks> /// /// <param name="uid"> The UID. </param> /// <param name="base"> The base. </param> /// <param name="quote"> The quote. </param> /// <param name="bitshares"> The bitshares. </param> /// <param name="bitcoin"> The bitcoin. </param> /// <param name="bitsharesAccount"> The bitshares account. </param> public InternalMarket(MetaDaemonApi daemon, MarketRow market, BitsharesWallet bitshares, BitcoinWallet bitcoin, string bitsharesAccount, CurrenciesRow bitsharesAsset) : base(daemon, market, bitshares, bitcoin, bitsharesAccount) { m_currency = bitsharesAsset; m_flipped = m_market.GetBase(daemon.m_AllCurrencies) != bitsharesAsset; m_asset = m_bitshares.BlockchainGetAsset(CurrencyHelpers.ToBitsharesSymbol(bitsharesAsset)); Dictionary <int, ulong> allBitsharesBalances = m_bitshares.WalletAccountBalance(bitsharesAccount)[bitsharesAccount]; decimal bitcoinBalance = bitcoin.GetBalance(); ComputeMarketPricesAndLimits(ref m_market, allBitsharesBalances, bitcoinBalance); }
public CurrenciesRow AddCurrenciesRow(string CurrencyID, string CurrencyName, System.Double CurrencyRate, bool IsBase) { CurrenciesRow rowCurrenciesRow = ((CurrenciesRow)(this.NewRow())); rowCurrenciesRow.ItemArray = new object[] { CurrencyID, CurrencyName, CurrencyRate, IsBase }; this.Rows.Add(rowCurrenciesRow); return(rowCurrenciesRow); }
public OrdersRow AddOrdersRow( string OrderNo, string OrderType, double OrderValue, System.DateTime OrderDate, double PaidValue, double OutstandingValue, System.DateTime RequiredDate, double DeliveryCost, string DeliveryNumber, int PaymentType, double PaymentValue, string Remarks, CompaniesRow parentCompaniesRowByFK_Orders_Companies, string CompanyCode, string CompanyName, CurrenciesRow parentCurrenciesRowByFK_Orders_Currencies, string CurrencyCode, string CurrencyName, OrdersRow parentOrdersRowByFK_Orders_Parent, string ParentNo, System.DateTime ParentDate, double ParentValue, int WarehouseID, string WarehouseCode, string WarehouseName) { OrdersRow rowOrdersRow = ((OrdersRow)(this.NewRow())); object[] columnValuesArray = new object[] { null, OrderNo, OrderType, OrderValue, OrderDate, PaidValue, OutstandingValue, RequiredDate, DeliveryCost, DeliveryNumber, PaymentType, PaymentValue, Remarks, null, CompanyCode, CompanyName, null, CurrencyCode, CurrencyName, null, ParentNo, ParentDate, ParentValue, WarehouseID, WarehouseCode, WarehouseName}; if ((parentCompaniesRowByFK_Orders_Companies != null)) { columnValuesArray[13] = parentCompaniesRowByFK_Orders_Companies[0]; } if ((parentCurrenciesRowByFK_Orders_Currencies != null)) { columnValuesArray[16] = parentCurrenciesRowByFK_Orders_Currencies[0]; } if ((parentOrdersRowByFK_Orders_Parent != null)) { columnValuesArray[19] = parentOrdersRowByFK_Orders_Parent[0]; } rowOrdersRow.ItemArray = columnValuesArray; this.Rows.Add(rowOrdersRow); return rowOrdersRow; }
public CurrenciesRowChangeEvent(CurrenciesRow row, DataRowAction action) { this.eventRow = row; this.eventAction = action; }
/// <summary> Converts a type to the bitshares symbol. </summary> /// /// <remarks> Paul, 05/02/2015. </remarks> /// /// <param name="type"> The type. </param> /// /// <returns> type as a string. </returns> static public string ToBitsharesSymbol(CurrenciesRow type) { return(type.symbol.TrimStart(kBitassetPrefix)); }
public void RemoveCurrenciesRow(CurrenciesRow row) { this.Rows.Remove(row); }
public void AddCurrenciesRow(CurrenciesRow row) { this.Rows.Add(row); }
public CurrenciesRowChangeEvent(CurrenciesRow row, global::System.Data.DataRowAction action) { this.eventRow = row; this.eventAction = action; }
/// <summary> Gets base and quote from symbol pair. </summary> /// /// <remarks> Paul, 05/02/2015. </remarks> /// /// <param name="symbolPair"> The symbol pair. </param> /// <param name="base"> [out] The base. </param> /// <param name="quote"> [out] The quote. </param> static public void GetBaseAndQuoteFromSymbolPair(string symbolPair, Dictionary <string, CurrenciesRow> currencyMap, out CurrenciesRow @base, out CurrenciesRow quote) { @base = CurrencyHelpers.FromSymbol(symbolPair.Split('_')[0], currencyMap); quote = CurrencyHelpers.FromSymbol(symbolPair.Split('_')[1], currencyMap); }
/// <summary> Gets market symbol pair. </summary> /// /// <remarks> Paul, 05/02/2015. </remarks> /// /// <param name="base"> The base. </param> /// <param name="quote"> The quote. </param> /// /// <returns> The market symbol pair. </returns> static public string GetMarketSymbolPair(CurrenciesRow @base, CurrenciesRow quote) { return(@base.symbol + "_" + quote.symbol); }
public abstract bool CanDepositAsset(CurrenciesRow asset);
/// <summary> Query if 'type' is bitshares asset. </summary> /// /// <remarks> Paul, 05/02/2015. </remarks> /// /// <param name="type"> The type. </param> /// /// <returns> true if bitshares asset, false if not. </returns> static public bool IsBitsharesAsset(CurrenciesRow type) { return(type.bitshares); }