Beispiel #1
0
        public override async Task <OrdersResponse> GetActiveOrders(OrdersRequest request, ServerCallContext context)
        {
            var result = await _validationService.ValidateOrdersRequestAsync(request.AssetPairId, request.Offset, request.Take);

            if (result != null)
            {
                return(new OrdersResponse
                {
                    Error = new Error
                    {
                        Code = (int)result.Code,
                        Message = result.Message
                    }
                });
            }

            var statuses = new List <string> {
                OrderStatus.Placed.ToString(), OrderStatus.PartiallyMatched.ToString()
            };

            var orders = _ordersReader.Get(context.GetHttpContext().User.GetWalletId(), request.Offset, request.Take,
                                           x => (string.IsNullOrEmpty(request.AssetPairId) || x.AssetPairId == request.AssetPairId) && statuses.Contains(x.Status));

            var res = new OrdersResponse();

            res.Payload.AddRange(_mapper.Map <List <Order> >(orders));
            return(res);
        }
        public async Task <ActionResult> Index(string IdOrden, string IdProducto, int?page)
        {
            if (page == null)
            {
                page = 1;
            }
            OrdersService ordersService = new OrdersService();
            Order         order         = await ordersService.GetOrder(Session["token"].ToString(), IdOrden);

            var ordersResponse = new OrdersResponse();

            ordersResponse.orders = new List <Order>();
            ordersResponse.orders.Add(order);
            ordersResponse.totalPaginas = 1;
            var pager = new Object();

            pager = new Pager(ordersResponse.orders.Count(), page, 10, ordersResponse.totalPaginas.Value + 1);
            var viewModel = new IndexViewModelOrders
            {
                Items = ordersResponse.orders,
                Pager = (Pager)pager
            };

            return(View(viewModel));
        }
Beispiel #3
0
        public override async Task <OrdersResponse> GetClosedOrders(OrdersRequest request, ServerCallContext context)
        {
            var result = await _validationService.ValidateOrdersRequestAsync(request.AssetPairId, request.Offset, request.Take);

            if (result != null)
            {
                return(new OrdersResponse
                {
                    Error = new Error
                    {
                        Code = (int)result.Code,
                        Message = result.Message
                    }
                });
            }

            var orders = await _historyClient.GetOrdersByWalletAsync(context.GetHttpContext().User.GetWalletId(), request.AssetPairId,
                                                                     new [] { OrderStatus.Matched, OrderStatus.Cancelled }, null, false, request.Offset, request.Take);

            var res = new OrdersResponse();

            res.Payload.AddRange(_mapper.Map <List <Order> >(orders));

            return(res);
        }
Beispiel #4
0
        public IActionResult MoveBack(int id)
        {
            OrderManager   orderManager  = new OrderManager(_clientFactory, _contextAccessor);
            OrdersResponse orderResponse = orderManager.Get($"{id}");

            if ((orderResponse.Stage + 1) < 1)
            {
                return(NotFound());
            }

            OrderRequest orderRequest = new OrderRequest
            {
                OrderSKU     = orderResponse.OrderSKU,
                OrderDate    = orderResponse.OrderDate,
                TotalAmount  = orderResponse.TotalAmount,
                Phone        = orderResponse.Phone,
                City         = orderResponse.City,
                Address      = orderResponse.Address,
                Address2     = orderResponse.Address2,
                OrderEmail   = orderResponse.OrderEmail,
                OrderZipCode = orderResponse.OrderZipCode,
                Stage        = orderResponse.Stage - 1
            };

            orderManager.Put(orderRequest);

            return(RedirectToAction("Index"));
        }
Beispiel #5
0
        public static OrdersResponse GetCustomerOrders(int customerid)
        {
            OrdersResponse        ordersResponse  = new OrdersResponse();
            AuctionSystemEntities auctionEntities = new AuctionSystemEntities();

            var orders = auctionEntities.orders.Where(c => c.customer_id == customerid).ToList();

            if (orders == null)
            {
                ordersResponse.Fault = new Error {
                    Code = ErrorCodes.NoOrders, Message = "There are no orders for this customer"
                };
                return(ordersResponse);
            }

            ordersResponse.CustomerOrders = new List <Order>();

            foreach (order order in orders)
            {
                Order customerOrders = new Order();
                customerOrders.AuctionId          = order.auction_id;
                customerOrders.CustomerId         = order.customer_id;
                customerOrders.CustomerPaymentId  = order.customer_payment_id;
                customerOrders.OrderAmount        = order.order_amount;
                customerOrders.OrderDatetime      = order.order_datetime.ToString(format);
                customerOrders.OrderId            = order.id;
                customerOrders.Status             = order.customer_status.status;
                customerOrders.StatusReason       = order.status_reason.reason;
                customerOrders.ProductName        = order.auction.product.product_Name;
                customerOrders.ProductDescription = order.auction.product.product_description;
                ordersResponse.CustomerOrders.Add(customerOrders);
            }
            return(ordersResponse);
        }
Beispiel #6
0
        internal static void Execute(DisplayMode mode)
        {
            Console.Clear();
            if (!ConsoleIO.GetDateValue("Enter the date you wish to display orders for: ", null, out DateTime orderDate))
            {
                return;
            }
            OrderManager   myOM       = OrderManagerFactory.Create(orderDate);
            OrdersResponse responseOs = myOM.GetOrders();

            if (responseOs.Success)
            {
                ConsoleIO.DisplayOrders(mode, responseOs.Orders, ConsoleColor.Blue);
            }
            else
            {
                ConsoleIO.DisplayText(responseOs.Message, false, false, ConsoleColor.Red);
                if (responseOs.Orders.Count > 2) //Must have more than just header = 1 order to have other lines to display.
                {
                    if (!ConsoleIO.GetString($"Press (Y/y) if you wish to display other orders despite this error.", 1, out string input))
                    {
                        return;
                    }
                    if (input.ToUpper() == "Y")
                    {
                        ConsoleIO.DisplayOrders(mode, responseOs.Orders, ConsoleColor.Blue);
                    }
                }
                else
                {
                    ConsoleIO.DisplayText("Press any key to continue...", false, true);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Retrieves the list of orders belonging to the account
        /// </summary>
        /// <param name="account">the account to retrieve the list for</param>
        /// <param name="orderIDs">the order IDs to retrieve</param>
        /// <param name="requestParams">optional additional parameters for the request (name, value pairs)</param>
        /// <returns>List of Order objects (or empty list, if no orders)</returns>
        public static async Task <List <IOrder> > GetOrderListAsync(string account, List <string> orderIDs = null, Dictionary <string, string> requestParams = null)
        {
            string requestString = Server(EServer.Account) + "accounts/" + account + "/orders";

            if (requestParams == null)
            {
                requestParams = new Dictionary <string, string>();
            }

            // order IDs should only be in the list
            if (requestParams.ContainsKey("ids"))
            {
                requestParams.Remove("ids");
            }

            if (orderIDs != null)
            {
                string idsParam = GetCommaSeparatedList(orderIDs);
                requestParams.Add("ids", idsParam);
            }

            OrdersResponse response = await MakeRequestAsync <OrdersResponse>(requestString, "GET", requestParams);

            var orders = new List <IOrder>();

            orders.AddRange(response.orders);

            return(orders);
        }
Beispiel #8
0
        public OrdersResponse GetOrders()
        {
            OrdersResponse response = new OrdersResponse();

            response.Success = true;
            response.Orders  = _orders;
            return(response);
        }
Beispiel #9
0
        public static async Task <HttpResponseMessage> GetCurrentOrders([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            var response = new OrdersResponse();

            response.Orders = CosmosClient.Instance.GetCurrentOrders();

            return(req.CreateResponse(HttpStatusCode.OK, response));
        }
Beispiel #10
0
        public IActionResult ViewOrderItems(int order)
        {
            OrderManager   orderManager = new OrderManager(_clientFactory, _contextAccessor);
            OrdersResponse currentOrder = orderManager.Get($"{order}");

            List <OrderDetailsResponse> products = currentOrder.OrderDetails.ToList();

            return(View(new OrderDetailsView(products)));
        }
Beispiel #11
0
        public OrdersResponse Post([FromBody] OrdersRequest req)
        {
            string json = "";

            OrdersResponse resp = new OrdersResponse(req);

            //json = JsonConvert.SerializeObject(resp);


            return(resp);
        }
Beispiel #12
0
        public void TestGetSingleInvoice()
        {
            Mock <IDatastore> mockDatastore = new Mock <IDatastore>();

            mockDatastore.Setup(_invoiceExpectation).Returns(_jsonData);

            WhmcsApi       instance      = new WhmcsApi("User", "Pass", "Website", mockDatastore.Object);
            OrdersResponse singleInvoice = instance.GetOrders(123);

            Assert.NotNull(singleInvoice);
        }
Beispiel #13
0
        /// <summary>
        /// Retrieves the list of open orders belonging to the account
        /// </summary>
        /// <param name="account">the account to retrieve the list for</param>
        /// <param name="requestParams">optional additional parameters for the request (name, value pairs)</param>
        /// <returns>List of Order objects (or empty list, if no orders)</returns>
        public static async Task <List <Order> > GetOrderListAsync(int account, Dictionary <string, string> requestParams = null)
        {
            string requestString = Server(EServer.Account) + "accounts/" + account + "/orders";

            OrdersResponse ordersResponse = await MakeRequestAsync <OrdersResponse>(requestString, "GET", requestParams);

            var orders = new List <Order>();

            orders.AddRange(ordersResponse.orders);

            return(orders);
        }
Beispiel #14
0
        /// <summary>
        /// Retrieves the list of open orders belonging to the account
        /// </summary>
        /// <param name="account">the account to retrieve the list for</param>
        /// <param name="requestParams">optional additional parameters for the request (name, value pairs)</param>
        /// <returns>List of Order objects (or empty list, if no orders)</returns>
        public static async Task <List <IOrder> > GetPendingOrderListAsync(string account)
        {
            string requestString = Server(EServer.Account) + "accounts/" + account + "/pendingOrders";

            OrdersResponse response = await MakeRequestAsync <OrdersResponse>(requestString);

            var orders = new List <IOrder>();

            orders.AddRange(response.orders);

            return(orders);
        }
        private int GetNextOrderNumber()
        {
            int retVal = 0;
            //Look in an existing file, and get the next OrderNumber
            OrdersResponse ordersResponse = new OrdersResponse();

            ordersResponse = GetOrders();
            if (ordersResponse.Success)
            {
                retVal = ordersResponse.Orders.Max(o => o.OrderNumber) + 1;
            }
            return(retVal);
        }
Beispiel #16
0
 public static void WriteOrdersInfo(OrdersResponse orders)
 {
     Console.WriteLine($"Listing {orders.CurveOrders.Count} curve orders:");
     foreach (var curveOrder in orders.CurveOrders)
     {
         WriteCurveOrder(curveOrder);
     }
     Console.WriteLine();
     Console.WriteLine($"Listing {orders.BlockLists.Count} block orders");
     foreach (var blockList in orders.BlockLists)
     {
         WriteBlockList(blockList);
     }
 }
Beispiel #17
0
        /// <summary>
        /// Get the list of open orders for a given account
        /// </summary>
        /// <param name="account">the account ID of the account</param>
        /// <returns>list of open orders (empty list if there are none)</returns>
        public static List <Order> GetOrderList(int account)
        {
            string requestString  = sApiServer + "v1/accounts/" + account + "/orders";
            string responseString = MakeRequest(requestString);

            JavaScriptSerializer serializer    = new JavaScriptSerializer();
            OrdersResponse       tradeResponse = serializer.Deserialize <OrdersResponse>(responseString);

            List <Order> orders = new List <Order>();

            orders.AddRange(tradeResponse.Orders);
            // TODO: should loop through the "next pages"

            return(orders);
        }
        public async Task <ActionResult> Cancelar(long IdOrden, string cancel)
        {
            OrdersService ordersService = new OrdersService();
            var           order         = await ordersService.CancelOrderAsync(Session["token"].ToString(), IdOrden);

            var pager          = new Pager(1, 1, 10, 1);
            var ordersResponse = new OrdersResponse();
            var viewModel      = new IndexViewModelOrders
            {
                Items = ordersResponse.orders,
                Pager = pager
            };

            return(RedirectToAction("Index", "Orders"));
        }
        public OrderResponse GetOrder(int orderNumber)
        {
            OrderResponse response = new OrderResponse();

            try
            {
                OrdersResponse responseOs = new OrdersResponse();
                responseOs = GetOrders();
                if (responseOs.Success)
                {
                    Order orderToGet = responseOs.Orders.Find(o => o.OrderNumber == orderNumber);
                    if (orderToGet == null)
                    {
                        response.Message = $"Was unable to find an order for order number: {orderNumber}!";
                        response.Success = false;
                        return(response);
                    }
                    else
                    {
                        response.Success = true;
                        response.Order   = orderToGet;
                        return(response);
                    }
                }
                else
                {
                    response.Message = responseOs.Message;
                    response.Success = false;
                    return(response);
                }
            }

            catch (FileNotFoundException)
            {
                response.Message = $"The file: {OrdersFileName} was not found. \nContact IT!";
                response.Success = false;
                return(response);
            }
            catch (Exception ex)
            {
                throw ex; //Throw exception up to calling method for handling in catch there.
            }

            finally
            {
            }
        }
Beispiel #20
0
        public void CanReadOrdersFromEasyFile()
        {
            //OrderManager myOM = OrderManagerFactory.Create(_orderDateEasy);
            OrderFileRepository myOFR          = new OrderFileRepository(_orderDateEasy);
            OrdersResponse      ordersResponse = new OrdersResponse();

            ordersResponse = myOFR.GetOrders();

            //Did it retrieve 10 orders?
            Assert.AreEqual(10, ordersResponse.Orders.Count());

            //1,Ada Lovelace,TX,8.19,Wood,2203,12.5,9.25,27537.5,20377.75,3924.26,51839.51
            Order orderToValidate = ordersResponse.Orders.Find(o => o.OrderNumber == 1);

            Assert.AreEqual(_orderDateEasy, orderToValidate.OrderDate);
            Assert.AreEqual(1, orderToValidate.OrderNumber);
            Assert.AreEqual("Ada Lovelace", orderToValidate.CustomerName);
            Assert.AreEqual("TX", orderToValidate.OrderStateTax.StateCode);
            Assert.AreEqual(8.19, orderToValidate.OrderStateTax.TaxRate);
            Assert.AreEqual("Wood", orderToValidate.OrderProduct.ProductType);
            Assert.AreEqual(2203, orderToValidate.Area);
            Assert.AreEqual(12.5, orderToValidate.OrderProduct.CostPerSquareFoot);
            Assert.AreEqual(9.25, orderToValidate.OrderProduct.LaborCostPerSquareFoot);
            Assert.AreEqual(27537.5, orderToValidate.FileMaterialCost);
            Assert.AreEqual(20377.75, orderToValidate.FileLaborCost);
            Assert.AreEqual(3924.26, orderToValidate.FileTax);
            Assert.AreEqual(51839.51, orderToValidate.FileTotal);

            //10,Elon Musk,TX,8.19,Carpet,1532,12.5,6.3,19150.0,9651.6,2358.85104,31160.45104
            orderToValidate = ordersResponse.Orders.Find(o => o.OrderNumber == 10);
            Assert.AreEqual(_orderDateEasy, orderToValidate.OrderDate);
            Assert.AreEqual(10, orderToValidate.OrderNumber);
            Assert.AreEqual("Elon Musk", orderToValidate.CustomerName);
            Assert.AreEqual("TX", orderToValidate.OrderStateTax.StateCode);
            Assert.AreEqual(8.19, orderToValidate.OrderStateTax.TaxRate);
            Assert.AreEqual("Carpet", orderToValidate.OrderProduct.ProductType);
            Assert.AreEqual(1532, orderToValidate.Area);
            Assert.AreEqual(12.5, orderToValidate.OrderProduct.CostPerSquareFoot);
            Assert.AreEqual(6.3, orderToValidate.OrderProduct.LaborCostPerSquareFoot);
            Assert.AreEqual(19150.0, orderToValidate.FileMaterialCost);
            Assert.AreEqual(9651.6, orderToValidate.FileLaborCost);
            Assert.AreEqual(2358.85104, orderToValidate.FileTax);
            Assert.AreEqual(31160.45104, orderToValidate.FileTotal);
        }
Beispiel #21
0
        public void CanReadQuoteDelimitedCommaOrderFromHardFile()
        {
            //OrderManager myOM = OrderManagerFactory.Create(_orderDateHard);
            OrderFileRepository myOFR          = new OrderFileRepository(_orderDateHard);
            OrdersResponse      ordersResponse = new OrdersResponse();

            ordersResponse = myOFR.GetOrders();

            Assert.AreEqual(26, ordersResponse.Orders.Count());

            //11,"Hill, Nathan",KY,6,Marble,250000,88.73,34.25,22182500.00,8562500.00,1844700.0000,32589700.0000
            Order orderToValidate = ordersResponse.Orders.Find(o => o.OrderNumber == 11);

            Assert.AreEqual(_orderDateHard, orderToValidate.OrderDate);
            Assert.AreEqual(11, orderToValidate.OrderNumber);
            Assert.AreEqual("Hill, Nathan", orderToValidate.CustomerName);
            Assert.AreEqual("KY", orderToValidate.OrderStateTax.StateCode);
            Assert.AreEqual(6, orderToValidate.OrderStateTax.TaxRate);
            Assert.AreEqual("Marble", orderToValidate.OrderProduct.ProductType);
            Assert.AreEqual(250000M, orderToValidate.Area);
            Assert.AreEqual(88.73M, orderToValidate.OrderProduct.CostPerSquareFoot);
            Assert.AreEqual(34.25M, orderToValidate.OrderProduct.LaborCostPerSquareFoot);
            Assert.AreEqual(22182500.00M, orderToValidate.FileMaterialCost);
            Assert.AreEqual(8562500.00M, orderToValidate.FileLaborCost);
            Assert.AreEqual(1844700.00M, orderToValidate.FileTax);
            Assert.AreEqual(32589700.00M, orderToValidate.FileTotal);

            //73144,"Thurston Howell, III",KY,6,Marble,65298,88.73,34.25,5793891.54,2236456.5,481820.88,8512168.92
            orderToValidate = ordersResponse.Orders.Find(o => o.OrderNumber == 73144);
            Assert.AreEqual(_orderDateHard, orderToValidate.OrderDate);
            Assert.AreEqual(73144, orderToValidate.OrderNumber);
            Assert.AreEqual("Thurston Howell, III", orderToValidate.CustomerName);
            Assert.AreEqual("KY", orderToValidate.OrderStateTax.StateCode);
            Assert.AreEqual(6, orderToValidate.OrderStateTax.TaxRate);
            Assert.AreEqual("Marble", orderToValidate.OrderProduct.ProductType);
            Assert.AreEqual(65298M, orderToValidate.Area);
            Assert.AreEqual(88.73M, orderToValidate.OrderProduct.CostPerSquareFoot);
            Assert.AreEqual(34.25M, orderToValidate.OrderProduct.LaborCostPerSquareFoot);
            Assert.AreEqual(5793891.54M, orderToValidate.FileMaterialCost);
            Assert.AreEqual(2236456.5M, orderToValidate.FileLaborCost);
            Assert.AreEqual(481820.88M, orderToValidate.FileTax);
            Assert.AreEqual(8512168.92M, orderToValidate.FileTotal);
        }
Beispiel #22
0
 public static Order Parse(OrdersResponse o)
 {
     return(new Order()
     {
         Amount = o.Amount,
         State = o.State,
         PickupTime = o.PickupTime,
         Created = o.Created,
         Comment = o.Comment,
         ClientId = o.ClientId,
         StoreId = o.StoreId,
         Id = o.Id,
         Client = o.Client,
         Store = o.Store != null
             ? StoreResponse.Parse(o.Store)
             : new Core.Store(),
         OrderProducts = o.OrderProducts,
     });
 }
Beispiel #23
0
        public void CanReadOrdersFromHardFile()
        {
            //OrderManager myOM = OrderManagerFactory.Create(_orderDateHard);
            OrderFileRepository myOFR          = new OrderFileRepository(_orderDateHard);
            OrdersResponse      ordersResponse = new OrdersResponse();

            ordersResponse = myOFR.GetOrders();
            //Did it retrieve 26 orders?
            Assert.AreEqual(26, ordersResponse.Orders.Count());

            //72751,"Alan M. Galloway, Sr.",XX,9.46,Wood,183934,12.5,9.25,2299175,1701389.5,378453.4,4379017.9
            Order orderToValidate = ordersResponse.Orders.Find(o => o.OrderNumber == 72751);

            Assert.AreEqual(_orderDateHard, orderToValidate.OrderDate);
            Assert.AreEqual("Alan M. Galloway, Sr.", orderToValidate.CustomerName);
            Assert.AreEqual("XX", orderToValidate.OrderStateTax.StateCode);
            Assert.AreEqual(9.46M, orderToValidate.OrderStateTax.TaxRate);
            Assert.AreEqual("Wood", orderToValidate.OrderProduct.ProductType);
            Assert.AreEqual(183934M, orderToValidate.Area);
            Assert.AreEqual(12.5M, orderToValidate.OrderProduct.CostPerSquareFoot);
            Assert.AreEqual(9.25M, orderToValidate.OrderProduct.LaborCostPerSquareFoot);
            Assert.AreEqual(2299175M, orderToValidate.FileMaterialCost);
            Assert.AreEqual(1701389.5M, orderToValidate.FileLaborCost);
            Assert.AreEqual(378453.4M, orderToValidate.FileTax);
            Assert.AreEqual(4379017.9M, orderToValidate.FileTotal);

            //73430,"Monsters Inc.",LO,9.46,Carpet,21601,12.5,6.3,270012.5,136086.3,38416.95,444515.75
            orderToValidate = ordersResponse.Orders.Find(o => o.OrderNumber == 73430);
            Assert.AreEqual(_orderDateHard, orderToValidate.OrderDate);
            Assert.AreEqual(73430, orderToValidate.OrderNumber);
            Assert.AreEqual("Monsters Inc.", orderToValidate.CustomerName);
            Assert.AreEqual("LO", orderToValidate.OrderStateTax.StateCode);
            Assert.AreEqual(9.46M, orderToValidate.OrderStateTax.TaxRate);
            Assert.AreEqual("Carpet", orderToValidate.OrderProduct.ProductType);
            Assert.AreEqual(21601M, orderToValidate.Area);
            Assert.AreEqual(12.5M, orderToValidate.OrderProduct.CostPerSquareFoot);
            Assert.AreEqual(6.3M, orderToValidate.OrderProduct.LaborCostPerSquareFoot);
            Assert.AreEqual(270012.5M, orderToValidate.FileMaterialCost);
            Assert.AreEqual(136086.3M, orderToValidate.FileLaborCost);
            Assert.AreEqual(38416.95M, orderToValidate.FileTax);
            Assert.AreEqual(444515.75M, orderToValidate.FileTotal);
        }
Beispiel #24
0
        public async Task <IActionResult> GetSearchMethodForOrder(string Email, OrdersRequest request)
        {
            var result = new OrdersResponse();

            var orders = await _context.Orders.Take(request.Quantity).Where(c => c.Email.StartsWith(Email) || c.Email.Contains(Email) || c.Email.EndsWith(Email)).Select(p => new Order {
                OrderId = p.Id, Email = p.Email
            }).ToListAsync();

            if (orders.Count == 0)
            {
                result.Code    = -100;
                result.Message = "Can't get products with given parameters.";
                return(Ok(result));
            }

            result.Code    = 100;
            result.Message = "Success";
            result.Orders  = orders;
            return(Ok(result));
        }
Beispiel #25
0
        public async Task <IActionResult> GetOrders(OrdersRequest request)
        {
            var result = new OrdersResponse();

            var orders = await _context.Orders.Skip(request.Skip).Take(request.Quantity).Select(p => new Order {
                OrderId = p.Id, Email = p.Email
            }).ToListAsync();

            if (orders.Count == 0)
            {
                result.Code    = -100;
                result.Message = "Can't get products with given parameters.";
                return(Ok(result));
            }

            result.Code    = 100;
            result.Message = "Success";
            result.Orders  = orders;
            return(Ok(result));
        }
 private bool HandleObjectMessage(string msg)
 {
     // ********************
     // ADD OBJECT HANDLERS BELOW
     // ********************
     //var response = FtxJsonSerializer.Deserialize<JObject>(msg);
     return
         (SubscribedResponse.TryHandle(msg, Streams.SubscribedSubject) ||
          ErrorResponse.TryHandle(msg, Streams.ErrorSubject) ||
          PongResponse.TryHandle(msg, Streams.PongSubject) ||
          TickerResponse.TryHandle(msg, Streams.TickerSubject) ||
          OrderBookUpdateResponse.TryHandle(msg, Streams.OrderBookUpdateSubject, "update") ||
          OrderBookSnapshotResponse.TryHandle(msg, Streams.OrderBookSnapshotSubject, "partial") ||
          // MarketsUpdateResponse.TryHandle(msg, Streams.MarketsUpdateSubject, "update") ||
          // MarketsSnapshotResponse.TryHandle(msg, Streams.MarketsSnapshotSubject, "partial") ||
          MarketsResponse.TryHandle(msg, Streams.MarketsSubject) ||
          TradeResponse.TryHandle(msg, Streams.TradesSubject) ||
          OrdersResponse.TryHandle(msg, Streams.OrdersSubject) ||
          FillsResponse.TryHandle(msg, Streams.FillsSubject));
 }
 public async Task <ActionResult> Index(string IdOrden, string IdProducto)
 {
     if (Session["token"] != null)
     {
         OrdersService ordersService  = new OrdersService();
         var           ordersResponse = new OrdersResponse();
         ordersResponse.orders       = new List <Order>();
         ordersResponse.totalPaginas = 1;
         var pager     = new Pager(1, 1, 10, 1);
         var viewModel = new IndexViewModelOrders
         {
             Items = ordersResponse.orders,
             Pager = pager
         };
         return(View(viewModel));
     }
     else
     {
         return(RedirectToAction("Login", "Account"));
     }
 }
        public async Task <ActionResult> Index2()
        {
            OrdersService ordersService   = new OrdersService();
            List <Order>  ordenesAbiertas = await ordersService.GetOrderOpenTop(Session["token"].ToString());

            int page           = 1;
            var ordersResponse = new OrdersResponse();

            ordersResponse.orders       = new List <Order>();
            ordersResponse.orders       = ordenesAbiertas;
            ordersResponse.totalPaginas = 0;
            var pager = new Object();

            pager = new Pager(ordersResponse.orders.Count(), page, 10, ordersResponse.totalPaginas.Value + 1);
            var viewModel = new IndexViewModelOrders
            {
                Items = ordersResponse.orders,
                Pager = (Pager)pager
            };

            return(View(viewModel));
        }
Beispiel #29
0
        //To get customer orders
        public ActionResult GetCustomerOrders()
        {
            LoginModelResponse customerinfo = (LoginModelResponse)Session["Customer"];
            OrdersResponse     orders       = new OrdersResponse();

            if (customerinfo != null)
            {
                ViewBag.LoginSuccess = "True";
                int customerid = customerinfo.CustomerId;
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://localhost:54713/api/");
                    //HTTP GET
                    var url = "Order/GetCustomerOrders?customerid=" + customerid;
                    var responseMessageTask = client.GetAsync(url);
                    responseMessageTask.Wait();

                    var result = responseMessageTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var readTask = result.Content.ReadAsAsync <OrdersResponse>();
                        readTask.Wait();
                        orders = readTask.Result;
                        return(View(orders));
                    }
                    else //web api sent error response
                    {
                        //log response status here..

                        ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                        return(View(orders));
                    }
                }
            }
            else
            {
                return(RedirectToActionPermanent("Index", "Login"));
            }
        }
        private void OnOrdersResponse(OrdersResponse response)
        {
            foreach (var order in response.Orders.Cast <TransaqBaseOrder>().Concat(response.StopOrders))
            {
                var stockSharpTransactionId = _orders.TryGetValue(order.TransactionId);

                if (stockSharpTransactionId == 0)
                {
                    stockSharpTransactionId = order.TransactionId;

                    // если заявка пришла от терминала, то просто идентификатор транзакции ассоциируем как стокшарповский
                    _orders.Add(order.TransactionId, order.TransactionId);

                    _ordersTypes.Add(order.TransactionId, order is TransaqStopOrder ? OrderTypes.Conditional : OrderTypes.Limit);
                }

                var execMsg = new ExecutionMessage
                {
                    SecurityId = new SecurityId {
                        Native = order.SecId
                    },
                    Side = order.BuySell.FromTransaq(),
                    OriginalTransactionId = stockSharpTransactionId,
                    PortfolioName         = order.Client,
                    ExpiryDate            = order.ExpDate == null ? (DateTimeOffset?)null : order.ExpDate.Value.ApplyTimeZone(TimeHelper.Moscow),
                    ExecutionType         = ExecutionTypes.Order,
                };

                var usualOrder = order as TransaqOrder;

                if (usualOrder != null)
                {
                    execMsg.OrderId       = usualOrder.OrderNo;
                    execMsg.Balance       = usualOrder.Balance;
                    execMsg.ServerTime    = usualOrder.WithdrawTime ?? usualOrder.Time ?? usualOrder.AcceptTime ?? DateTimeOffset.MinValue;
                    execMsg.Comment       = usualOrder.BrokerRef;
                    execMsg.SystemComment = usualOrder.Result;
                    execMsg.Price         = usualOrder.Price;
                    execMsg.Volume        = usualOrder.Quantity;
                    execMsg.OrderType     = usualOrder.Price == 0 ? OrderTypes.Market : OrderTypes.Limit;
                    execMsg.Commission    = usualOrder.MaxCommission;

                    if (usualOrder.ConditionType != TransaqAlgoOrderConditionTypes.None)
                    {
                        execMsg.OrderType = OrderTypes.Conditional;

                        execMsg.Condition = new TransaqOrderCondition
                        {
                            AlgoType  = usualOrder.ConditionType,
                            AlgoValue = usualOrder.ConditionValue.To <decimal>(),

                            AlgoValidAfter  = usualOrder.ValidAfter,
                            AlgoValidBefore = usualOrder.ValidBefore,
                        };
                    }
                }
                else
                {
                    var stopOrder = (TransaqStopOrder)order;

                    execMsg.OrderId    = stopOrder.ActiveOrderNo;
                    execMsg.OrderType  = OrderTypes.Conditional;
                    execMsg.ServerTime = stopOrder.AcceptTime == null
                                                ? DateTimeOffset.MinValue
                                                : stopOrder.AcceptTime.Value.ApplyTimeZone(TimeHelper.Moscow);

                    var stopCond = new TransaqOrderCondition
                    {
                        Type          = stopOrder.StopLoss != null && stopOrder.TakeProfit != null ? TransaqOrderConditionTypes.TakeProfitStopLoss : (stopOrder.StopLoss != null ? TransaqOrderConditionTypes.StopLoss : TransaqOrderConditionTypes.TakeProfit),
                        ValidFor      = stopOrder.ValidBefore,
                        LinkedOrderId = stopOrder.LinkedOrderNo,
                    };

                    if (stopOrder.StopLoss != null)
                    {
                        stopCond.StopLossActivationPrice = stopOrder.StopLoss.ActivationPrice;
                        stopCond.StopLossOrderPrice      = stopOrder.StopLoss.OrderPrice;
                        stopCond.StopLossByMarket        = stopOrder.StopLoss.OrderPrice == null;
                        stopCond.StopLossVolume          = stopOrder.StopLoss.Quantity;
                        //stopCond.StopLossUseCredit = stopOrder.StopLoss.UseCredit.To<bool>();

                        if (stopOrder.StopLoss.GuardTime != null)
                        {
                            stopCond.StopLossProtectionTime = (int)stopOrder.StopLoss.GuardTime.Value.TimeOfDay.TotalMinutes;
                        }

                        stopCond.StopLossComment = stopOrder.StopLoss.BrokerRef;
                    }

                    if (stopOrder.TakeProfit != null)
                    {
                        stopCond.TakeProfitActivationPrice = stopOrder.TakeProfit.ActivationPrice;
                        stopCond.TakeProfitByMarket        = stopOrder.TakeProfit.GuardSpread == null;
                        stopCond.TakeProfitVolume          = stopOrder.TakeProfit.Quantity;
                        //stopCond.TakeProfitUseCredit = stopOrder.TakeProfit.UseCredit.To<bool>();

                        if (stopOrder.TakeProfit.GuardTime != null)
                        {
                            stopCond.TakeProfitProtectionTime = (int)stopOrder.TakeProfit.GuardTime.Value.TimeOfDay.TotalMinutes;
                        }

                        stopCond.TakeProfitComment          = stopOrder.TakeProfit.BrokerRef;
                        stopCond.TakeProfitCorrection       = stopOrder.TakeProfit.Correction;
                        stopCond.TakeProfitProtectionSpread = stopOrder.TakeProfit.GuardSpread;
                    }
                }

                execMsg.OrderState = order.Status.ToStockSharpState();
                //execMsg.OrderStatus = order2.Status.ToStockSharpStatus();

                if (order.Status != TransaqOrderStatus.cancelled)
                {
                    if (execMsg.OrderState == OrderStates.Failed && usualOrder != null)
                    {
                        execMsg.Error = new InvalidOperationException(usualOrder.Result);
                    }
                }

                SendOutMessage(execMsg);

                //if (order.Condition != null && order.DerivedOrder == null && order2.ConditionType != TransaqAlgoOrderConditionTypes.None && order2.OrderNo != 0)
                //	AddDerivedOrder(security, order2.OrderNo, order, (stopOrder, limitOrder) => stopOrder.DerivedOrder = limitOrder);
            }
        }