public void GetRatesTest_ChecksTheRatesForAllCurrencyPairsSubmittingDepthLevels_ChecksTheRatesReturnedToVerify()
        {
            MarketController marketController = (MarketController)_applicationContext["MarketController"];
            BBOMemoryImage   bboMemoryImage   = (BBOMemoryImage)_applicationContext["BBOMemoryImage"];

            DepthLevel xbtUsdBidLevel = new DepthLevel(new Price(491));
            DepthLevel ltcUsdBidLevel = new DepthLevel(new Price(492));
            DepthLevel btcUsdBidLevel = new DepthLevel(new Price(493));

            DepthLevel xbtUsdAskLevel = new DepthLevel(new Price(494));
            DepthLevel ltcUsdAskLevel = new DepthLevel(new Price(495));
            DepthLevel btcUsdAskLevel = new DepthLevel(new Price(496));

            bboMemoryImage.OnBBOArrived("XBT/USD", xbtUsdBidLevel, xbtUsdAskLevel);
            bboMemoryImage.OnBBOArrived("LTC/USD", ltcUsdBidLevel, ltcUsdAskLevel);
            bboMemoryImage.OnBBOArrived("BTC/USD", btcUsdBidLevel, btcUsdAskLevel);
            IHttpActionResult httpActionResult = marketController.GetAllRates();

            OkNegotiatedContentResult <RatesList> returnedOkRate = (OkNegotiatedContentResult <RatesList>)httpActionResult;
            RatesList ratesList = returnedOkRate.Content;

            Assert.AreEqual("XBT/USD", ratesList.ToList()[0].CurrencyPair);
            Assert.AreEqual(492.5, ratesList.ToList()[0].RateValue); // MidPoint of xbtUsdBidLevel = 491 & xbtUsdAskLevel = 494
            Assert.AreEqual("LTC/USD", ratesList.ToList()[1].CurrencyPair);
            Assert.AreEqual(493.5, ratesList.ToList()[1].RateValue); // MidPoint of ltcUsdBidLevel = 492 & ltcUsdAskLevel = 495
            Assert.AreEqual("BTC/USD", ratesList.ToList()[2].CurrencyPair);
            Assert.AreEqual(494.5, ratesList.ToList()[2].RateValue); // MidPoint of btcUsdBidLevel = 493 & btcUsdAskLevel = 496
        }
        protected override RateViewsList getRandomObject()
        {
            var l = new RatesList(null, null);

            SetRandom.Values(l);
            return(new RateViewsList(l));
        }
示例#3
0
        public void Find()
        {
            player.Play("Find");

            Assert.DoesNotThrowAsync(async() => {
                RatesList found = await client.FindRatesAsync("USDGBP");
            });
        }
        /// <summary>
        /// Get Rates for all the currency pairs
        /// </summary>
        /// <returns></returns>
        public RatesList GetAllRates()
        {
            RatesList ratesList = new RatesList();

            ratesList.AddRate("XBT/USD", 491.34M, 495.65M);
            ratesList.AddRate("LTC/USD", 496.34M, 499.65M);

            return(ratesList);
        }
        public IEnumerable <Transaction> GetTransactionsBySku(string sku)
        {
            _myTracing.Debug(string.Format("{0} --- {1}", nameof(DataManager), nameof(GetTransactionsBySku)));
            double sum = 0;

            try
            {
                if (RatesList == null)
                {
                    _myTracing.Error(string.Format("RatesList is empty"));
                    throw new NullReferenceException();
                }
                if (TransactionsList == null)
                {
                    _myTracing.Error(string.Format("TransactionsList is empty"));
                    throw new NullReferenceException();
                }
                List <Transaction> resultFiltered = new List <Transaction>();
                resultFiltered = TransactionsList.Where(x => x.Sku.Equals(sku)).ToList();
                if (!resultFiltered.Any())
                {
                    _myTracing.Error(string.Format("SKU not found"));
                    return(resultFiltered);
                }
                foreach (Transaction element in resultFiltered)
                {
                    if (element.Currency.Equals("EUR"))
                    {
                        sum += element.Amount;
                        continue;
                    }

                    Rates rate = RatesList.Where((r => (r.From == element.Currency) && (r.To.Equals("EUR")))).FirstOrDefault();
                    if (rate != null)
                    {
                        element.Amount  *= rate.Rate;
                        element.Currency = "EUR";
                        sum += element.Amount;
                        continue;
                    }
                }
                return(resultFiltered);
            }
            catch (Exception ex)
            {
                _myTracing.Error(string.Format("Error while the data has been filtering : {0}", ex.Message));
                throw ex;
            }
        }
        public string GetApartments()
        {
            var data = new List <Rate>();

            try
            {
                var service_item = new RatesService();
                var rates_list   = new RatesList(service_item);
                data  = rates_list.rates;
                rates = data;
            }
            catch (Exception ex)
            {
            }
            var str = JsonConvert.SerializeObject(data);

            return(str);
        }
        public void UpdateSupplierOrderView(int supplierOrderId)
        {
            if (supplierOrderId == 0)
            {
                SupplierOrder = new SupplierOrderView()
                {
                    id = 0
                };

                SelectedSupplier = new Supplier();
                SelectedBroker   = BrokersList[0];
                SelectedContract = new Contract();
                SelectedRate     = new RatesList();
            }
            else
            {
                SupplierOrder    = SupplierOrderService.ReadSupplierOrder(supplierOrderId);
                SelectedSupplier = suppliersListStorage.FirstOrDefault(s => s.Id == SupplierOrder.supplierId);
                SearchCompany    = SelectedSupplier.Name;

                if (SupplierOrder.brokerId != null)
                {
                    SelectedBroker = BrokersList.FirstOrDefault(s => s.Id == SupplierOrder.brokerId);
                }
                else
                {
                    SelectedBroker = null;
                }

                if (SupplierOrder.brokerId != null)
                {
                    ContractsList    = DictionariesService.ReadContracts(SelectedSupplier.companyId, SelectedBroker.Id);
                    SelectedContract = ContractsList.FirstOrDefault(c => c.id == SupplierOrder.contractId);
                }
                else
                {
                    ContractsList = new List <Contract>();
                }
            }
        }
示例#8
0
 public IHttpActionResult GetAllRates()
 {
     if (log.IsDebugEnabled)
     {
         log.Debug("Get All Rates Call");
     }
     try
     {
         RatesList rates = _marketDataService.GetAllRates();
         if (rates != null)
         {
             return(Ok <RatesList>(rates));
         }
         return(BadRequest());
     }
     catch (Exception exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Get All Rates Call Error", exception);
         }
         return(InternalServerError());
     }
 }
        public static decimal GetRatePercent(int supplierId, int auctionId, int exchangeId, decimal debt, int brokerId)
        {
            /*var supplierOrder = dbManager.ReadSupplierOrder(supplierId, auctionId);
             *
             * if (supplierOrder == null || supplierOrder.contractId == null) return 0;*/

            //
            var company = dbManager.GetCompanySupplier(supplierId);

            if (company == null)
            {
                return(0);
            }

            var contracts = dbManager.ReadContracts(company.id, brokerId);

            if (contracts == null || contracts.Count < 1)
            {
                return(0);
            }

            RatesList ratesList = new RatesList()
            {
                id = 0
            };

            foreach (var contract in contracts)
            {
                var ratesLst = dbManager.ReadRatesList(contract.id, exchangeId);

                if (ratesLst != null)
                {
                    ratesList = ratesLst;
                }
            }

            if (ratesList.id == 0)
            {
                return(0);
            }
            //

            //var ratesList = dbManager.ReadRatesList((int)supplierOrder.contractId, exchangeId);

            if (ratesList == null)
            {
                return(0);
            }

            var rates = dbManager.ReadRates(ratesList.id);

            if (rates == null)
            {
                return(0);
            }

            var rateItem = rates.OrderByDescending(r => r.transaction).FirstOrDefault(r => r.transaction < debt);

            try {
                if (rateItem != null)
                {
                    return(rates.FirstOrDefault(r => r.id == rateItem.id).percent);
                }
                else
                {
                    return(rates.FirstOrDefault(r => r.id == rates.OrderBy(ra => ra.transaction).FirstOrDefault().id).percent);
                }
            } catch { return(0); }
        }
        public void GetRatesEndToEndTests_SubmitsOrdersAndChecksTheRatesForCurrencyPairs_VerifiesThroughTheReturnedRatesList()
        {
            // Get the instance through Spring configuration
            OrderController orderController = (OrderController)_applicationContext["OrderController"];

            orderController.Request = new HttpRequestMessage(HttpMethod.Post, "");
            orderController.Request.Headers.Add("Auth", "123456789");

            ManualResetEvent  manualResetEvent = new ManualResetEvent(false);
            IHttpActionResult orderHttpResult  = orderController.CreateOrder(new CreateOrderParam()
            {
                Pair   = "XBTUSD",
                Price  = 491,
                Volume = 100,
                Side   = "buy",
                Type   = "limit"
            });

            OkNegotiatedContentResult <NewOrderRepresentation> orderRepresentationContent = (OkNegotiatedContentResult <NewOrderRepresentation>)orderHttpResult;

            Assert.IsNotNull(orderRepresentationContent.Content);
            manualResetEvent.Reset();
            manualResetEvent.WaitOne(2000);
            orderController.CreateOrder(new CreateOrderParam()
            {
                Pair   = "BTCUSD",
                Price  = 493,
                Volume = 1000,
                Side   = "buy",
                Type   = "limit"
            });
            manualResetEvent.Reset();
            manualResetEvent.WaitOne(2000);
            orderController.CreateOrder(new CreateOrderParam()
            {
                Pair   = "XBTUSD",
                Price  = 494,
                Volume = 900,
                Side   = "sell",
                Type   = "limit"
            });
            manualResetEvent.Reset();
            manualResetEvent.WaitOne(2000);
            orderController.CreateOrder(new CreateOrderParam()
            {
                Pair   = "BTCUSD",
                Price  = 496,
                Volume = 700,
                Side   = "sell",
                Type   = "limit"
            });
            manualResetEvent.Reset();
            manualResetEvent.WaitOne(2000);
            MarketController marketController = (MarketController)_applicationContext["MarketController"];

            IHttpActionResult httpActionResult = marketController.GetAllRates();
            OkNegotiatedContentResult <RatesList> okResponse = (OkNegotiatedContentResult <RatesList>)httpActionResult;

            RatesList ratesList = okResponse.Content;

            Assert.AreEqual("XBTUSD", ratesList.ToList()[0].CurrencyPair);
            Assert.AreEqual(492.5, ratesList.ToList()[0].RateValue); // MidPoint of xbtUsdBidLevel = 491 & xbtUsdAskLevel = 494
            Assert.AreEqual("BTCUSD", ratesList.ToList()[1].CurrencyPair);
            Assert.AreEqual(494.5, ratesList.ToList()[1].RateValue); // MidPoint of btcUsdBidLevel = 493 & btcUsdAskLevel = 496
        }