Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);
        }
Example #3
0
        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));
            }
        }
Example #4
0
        public AjaxResult ThemGiaoDich(int hoaDonID, int soTien, string ngayGiaoDich)
        {
            IHoaDonRepository hoaDonRepository = uow.Repository <HoaDonRepository>();
            var model = hoaDonRepository.GetHoaDonModelByID(hoaDonID);

            if (model == null)
            {
                return(AjaxResult.Fail("Hóa đơn không tồn tại. Vui lòng tải lại trang.", true));
            }

            if (model.CoDuNoQuaHan)
            {
                return(AjaxResult.Fail("Khách hàng có dư nợ quá hạn cần thanh toán trước.", true));
            }

            var current = DateTime.Now.AddMonths(-1);

            if (!(!model.CoDuNoQuaHan && // không có dư nợ & (tháng hiện tại || (< tháng hiện tại & chưa thu))
                  ((model.HoaDon.ThangHoaDon == current.Month && model.HoaDon.NamHoaDon == current.Year) ||
                   ((model.HoaDon.NamHoaDon < current.Year || (model.HoaDon.NamHoaDon == current.Year && model.HoaDon.ThangHoaDon < current.Month)) &&
                    (model.HoaDon.Trangthaithu == false || model.HoaDon.Trangthaithu == null)))))
            {
                return(AjaxResult.Fail("Không thể thêm giao dịch cho hóa đơn này. Dữ liệu bất đồng bộ, vui lòng load lại trang.", true));
            }

            DateTime dt;

            if (!DateTime.TryParseExact(ngayGiaoDich, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
            {
                dt = DateTime.Now;
            }

            if (!GiaoDichHelpers.ThemGiaoDich(model, soTien, dt, uow))
            {
                return(AjaxResult.Fail("Lỗi thêm giao dịch. Vui lòng thử lại."));
            }

            int duNo = (int)(model.SoTienNopTheoThang.SoTienPhaiNop - model.SoTienNopTheoThang.SoTienDaThu);

            return(AjaxResult.Success("Giao dịch thành công.", false,
                                      new
            {
                HoaDon = new
                {
                    ID = model.HoaDon.HoadonnuocID,
                    TrangThaiThu = model.HoaDon.Trangthaithu,
                    NgayNopTien = model.HoaDon.NgayNopTien != null ? model.HoaDon.NgayNopTien.Value.ToString("dd/MM/yyyy") : ""
                },
                SoTienNopTheoThang = new
                {
                    SoTienDaThu = CurrencyHelpers.FormatVN(model.SoTienNopTheoThang.SoTienDaThu ?? 0),
                    DuNo = CurrencyHelpers.FormatVN(duNo > 0 ? duNo : -duNo)
                }
            }));
        }
Example #5
0
        public TestBase()
        {
            m_database = new Database(kDatabaseName, kDatabaseUser, kDatabasePassword, Thread.CurrentThread.ManagedThreadId);

            RedisWrapper.Initialise("test");

            m_data       = new MySqlData(kDatabaseName, kDatabaseUser, kDatabasePassword);
            m_currencies = m_data.GetAllCurrencies();

            m_defaultSymbolPair = CurrencyHelpers.GetMarketSymbolPair(m_currencies["bitBTC"], m_currencies[kBtc]);
            m_alternateMarket   = CurrencyHelpers.GetMarketSymbolPair(m_currencies["bitGOLD"], m_currencies[kBtc]);

            Thread thread = new Thread(() =>
            {
                string bitsharesUrl      = "http://localhost:65066/rpc";
                string bitsharesUser     = "******";
                string bitsharesPassword = "******";
                string bitsharesAccount  = "gatewaytest";

                string bitcoinUrl      = "http://localhost:18332";
                string bitcoinUser     = "******";
                string bitcoinPassword = "******";
                bool bitcoinUseTestNet = true;

                string database         = kDatabaseName;
                string databaseUser     = kDatabaseUser;
                string databasePassword = kDatabasePassword;

                string apiListen = kApiRoot;

                // create a scheduler so we can be sure of thread affinity
                AsyncPump scheduler = new AsyncPump(Thread.CurrentThread, OnException);

                m_api = new MetaDaemonApi(new RpcConfig {
                    m_url = bitsharesUrl, m_rpcUser = bitsharesUser, m_rpcPassword = bitsharesPassword
                },
                                          new RpcConfig {
                    m_url = bitcoinUrl, m_rpcUser = bitcoinUser, m_rpcPassword = bitcoinPassword, m_useTestnet = bitcoinUseTestNet
                },
                                          bitsharesAccount,
                                          database, databaseUser, databasePassword,
                                          apiListen, null, null, "gatewayclient", "http://192.168.0.2:1235/", "192.168.0.2", scheduler);

                m_api.m_ApiServer.m_HttpServer.m_DdosProtector.m_Enabled = false;

                scheduler.RunWithUpdate(m_api.Start, m_api.Update, 1);

                Console.WriteLine("meta thread exiting...");
            });

            thread.Start();
        }
Example #6
0
        /// <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);
        }
Example #7
0
        public void GetBaseAndQuoteFromSymbolPair()
        {
            IEnumerable <string> markets = m_data.GetAllMarkets().Select <MarketRow, string>(r => r.symbol_pair);

            foreach (string m in markets)
            {
                CurrencyTypesDep baseOld, quoteOld;
                CurrenciesRow    baseNew, quoteNew;
                CurrencyHelpersDep.GetBaseAndQuoteFromSymbolPair(m, out baseOld, out quoteOld);
                CurrencyHelpers.GetBaseAndQuoteFromSymbolPair(m, m_currencies, out baseNew, out quoteNew);

                Assert.AreEqual(baseOld.ToString(), baseNew.ToString());
                Assert.AreEqual(quoteOld.ToString(), quoteNew.ToString());
            }
        }
Example #8
0
        public void FromBitsharesSymbol()
        {
            string[] symbols =
            {
                "BTS", "BTC", "USD", "GOLD", "CNY"
            };

            foreach (string s in symbols)
            {
                string old = CurrencyHelpersDep.FromBitsharesSymbol(s).ToString();
                string n   = CurrencyHelpers.FromBitsharesSymbol(s, m_currencies, false).ToString();

                Assert.AreEqual(old, n);
            }
        }
Example #9
0
        /// <summary>
        /// thanh toán hóa đơn vs ID đã cho
        /// nếu ngày nộp không đúng > ngày nộp = ngày hiện tại
        /// </summary>
        /// <effects>
        ///     get HoaDonModel <tt>model</tt> with specified <tt>hoaDonID</tt>
        ///     if model == null || model.HoaDon.TrangThaiThu == true
        ///         throw NotPossibleException: Dữ liệu bất đồng bộ, vui lòng refresh lại trang
        ///     invoke @{link HoaDonHelpers#ThemGiaoDich(HoaDonModel)}: thanh toan HoaDonModel
        /// </effects>
        public AjaxResult ThanhToan(int hoaDonID, string ngayThu)
        {
            var model = hoaDonRepository.GetHoaDonModelByID(hoaDonID);

            if (model == null || model.HoaDon.Trangthaithu == true)
            {
                return(AjaxResult.Fail("Dữ liệu bất đồng bộ, vui lòng refresh lại trang.", true));
            }

            try
            {
                DateTime dt;
                if (!DateTime.TryParseExact(ngayThu, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                {
                    dt = DateTime.Now;
                }

                if (!HoaDonHelpers.ThanhToan(model, dt, uow))
                {
                    return(AjaxResult.Fail("Lỗi cập nhật dữ liệu. Vui lòng thử lại."));
                }
            }
            catch (Exception e)
            {
                return(AjaxResult.Fail(e.Message));
            }

            int duNo = (int)(model.SoTienNopTheoThang.SoTienPhaiNop - model.SoTienNopTheoThang.SoTienDaThu);

            return(AjaxResult.Success("Thanh toán thành công.",
                                      (model.HoaDon.ThangHoaDon != current.Month && model.HoaDon.NamHoaDon != current.Year),
                                      new
            {
                HoaDon = new
                {
                    ID = model.HoaDon.HoadonnuocID,
                    TrangThaiThu = model.HoaDon.Trangthaithu,
                    NgayNopTien = model.HoaDon.NgayNopTien != null ? model.HoaDon.NgayNopTien.Value.ToString("dd/MM/yyyy") : ""
                },
                SoTienNopTheoThang = new
                {
                    SoTienDaThu = CurrencyHelpers.FormatVN(model.SoTienNopTheoThang.SoTienDaThu ?? 0),
                    DuNo = CurrencyHelpers.FormatVN(duNo > 0 ? duNo : -duNo)
                }
            }));
        }
Example #10
0
        public void FromSymbol()
        {
            List <string> symbols = new List <string>();

            for (int i = 0; i < (int)CurrencyTypesDep.max; i++)
            {
                CurrencyTypesDep type = (CurrencyTypesDep)i;
                symbols.Add(type.ToString());
            }

            foreach (string s in symbols)
            {
                string old = CurrencyHelpersDep.FromSymbol(s).ToString();
                string n   = CurrencyHelpers.FromSymbol(s, m_currencies).ToString();

                Assert.AreEqual(old, n);
            }
        }
Example #11
0
        /// <summary>	Creates handler for market. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <exception cref="UnexpectedCaseException">	Thrown when an Unexpected Case error condition
        ///                                             occurs. </exception>
        ///
        /// <param name="market">	The market. </param>
        ///
        /// <returns>	The new handler for market. </returns>
        MarketBase CreateHandlerForMarket(MarketRow market)
        {
            CurrenciesRow @base, quote;

            CurrencyHelpers.GetBaseAndQuoteFromSymbolPair(market.symbol_pair, m_allCurrencies, out @base, out quote);

            if (CurrencyHelpers.IsBitsharesAsset(@base) && !CurrencyHelpers.IsBitsharesAsset(quote))
            {
                return(new InternalMarket(this, market, m_bitshares, m_bitcoin, m_bitsharesAccount, @base));
            }
            else if (!CurrencyHelpers.IsBitsharesAsset(@base) && CurrencyHelpers.IsBitsharesAsset(quote))
            {
                return(new InternalMarket(this, market, m_bitshares, m_bitcoin, m_bitsharesAccount, @quote));
            }
            else
            {
                throw new UnexpectedCaseException();
            }
        }
Example #12
0
        /// <summary>
        /// Hủy thanh toán hóa đơn vs ID đã cho
        /// </summary>
        /// <effects>
        ///     get HoaDonModel <tt>model</tt> with specified <tt>hoaDonID</tt>
        ///     if model == null || model.TrangThaiThu == false
        ///         throw NotPossibleException: Dữ liệu bất đồng bộ, vui lòng refresh lại trang
        ///     if model.SoTienPhaiNop.SoTienDaThu == 0
        ///         throw NotPossibleException: Khách hàng thanh toán trừ dư có
        ///     if model.KhachHang.HinhThucThanhToan == ChuyenKhoan
        ///         throw NotPossibleException: Khách hàng thanh toán qua chuyển khoản
        ///     if lastGiaoDich.NgayThu == model.HoaDon.NgayThu && lastGiaoDich.SoTien == model.SoTienNopTheoThang.SoTienDaThu
        ///         invoke @{link #HuyGiaoDich()}: huy giao dich gan nhat
        ///     throw NotPossibleException: Không thể hủy thanh toán! Vui lòng hủy giao dịch tại Xem lịch sử giao dịch.
        /// </effects>
        public AjaxResult HuyThanhToan(int hoaDonID)
        {
            var model = hoaDonRepository.GetHoaDonModelByID(hoaDonID);

            if (model == null || model.HoaDon.Trangthaithu == false || model.HoaDon.Trangthaithu == null)
            {
                return(AjaxResult.Fail("Dữ liệu bất đồng bộ, vui lòng refresh lại trang.", true));
            }

            try
            {
                if (!HoaDonHelpers.HuyThanhToan(model, uow))
                {
                    return(AjaxResult.Fail("Lỗi cập nhật dữ liệu. Vui lòng thử lại."));
                }
            }
            catch (Exception e)
            {
                return(AjaxResult.Fail(e.Message));
            }

            int duNo = (int)(model.SoTienNopTheoThang.SoTienPhaiNop - model.SoTienNopTheoThang.SoTienDaThu);

            return(AjaxResult.Success("Hủy thanh toán thành công.", false,
                                      new
            {
                HoaDon = new
                {
                    ID = model.HoaDon.HoadonnuocID,
                    TrangThaiThu = model.HoaDon.Trangthaithu,
                    NgayNopTien = model.HoaDon.NgayNopTien != null ? model.HoaDon.NgayNopTien.Value.ToString("dd/MM/yyyy") : ""
                },
                SoTienNopTheoThang = new
                {
                    SoTienDaThu = CurrencyHelpers.FormatVN(model.SoTienNopTheoThang.SoTienDaThu ?? 0),
                    DuNo = CurrencyHelpers.FormatVN(duNo > 0 ? duNo : -duNo)
                }
            }));
        }
Example #13
0
        public void GetMarketSymbolPair()
        {
            List <string> symbols = new List <string>();

            for (int i = 0; i < (int)CurrencyTypesDep.max; i++)
            {
                CurrencyTypesDep type = (CurrencyTypesDep)i;
                symbols.Add(type.ToString());
            }

            for (int i = 0; i < symbols.Count - 1; i++)
            {
                for (int j = i + 1; j < symbols.Count; j++)
                {
                    CurrencyTypesDep @base = CurrencyHelpersDep.FromSymbol(symbols[i]);
                    CurrencyTypesDep quote = CurrencyHelpersDep.FromSymbol(symbols[j]);

                    string marketOld = CurrencyHelpersDep.GetMarketSymbolPair(@base, quote);
                    string marketNew = CurrencyHelpers.GetMarketSymbolPair(m_currencies[@base.ToString()], m_currencies[quote.ToString()]);

                    Assert.AreEqual(marketOld, marketNew);
                }
            }
        }
Example #14
0
 public bool IsNativeTo(CultureInfo cultureInfo) => CurrencyHelpers.IsNativeTo(Code, cultureInfo);
 public object Convert(object value, Type targetType, object parameter, string culture)
 {
     return(CurrencyHelpers.ConvertToShorthand((double)value));
 }
Example #16
0
 public void UnknownAsset()
 {
     Assert.Throws(typeof(ArgumentException), () => CurrencyHelpersDep.FromSymbol("ldss"));
     Assert.Throws(typeof(KeyNotFoundException), () => CurrencyHelpers.FromSymbol("ldss", m_currencies));
 }
Example #17
0
 public CurrenciesRow GetQuote(Dictionary <string, CurrenciesRow> currencyMap)
 {
     return(CurrencyHelpers.FromSymbol(symbol_pair.Split('_')[1], currencyMap));
 }