/// <summary> /// Sets a new order Buy Limit. /// </summary> private static void OrdBuyLimit(int bar, int orderIf, int toPos, double lots, double price, OrderSender sender, OrderOrigin origin, string note) { int sessionOrder = session[bar].Orders; Order order = session[bar].Order[sessionOrder] = new Order(); order.OrdNumb = SentOrders; order.OrdDir = OrderDirection.Buy; order.OrdType = OrderType.Limit; order.OrdCond = orderIf > 0 ? OrderCondition.If : OrderCondition.Norm; order.OrdStatus = OrderStatus.Confirmed; order.OrdIf = orderIf; order.OrdPos = toPos; order.OrdLots = lots; order.OrdPrice = Math.Round(price, InstrProperties.Digits); order.OrdPrice2 = 0; order.OrdSender = sender; order.OrdOrigin = origin; order.OrdNote = note; ordCoord[SentOrders].Bar = bar; ordCoord[SentOrders].Ord = sessionOrder; session[bar].Orders++; SentOrders++; }
private void PlazaControllerOnNewMyOrderEvent(Order order) { lock (_lockerUpdateOrders) { if (_orders != null) { Order oldOrder = _orders.Find(order1 => order1.NumberUser == order.NumberUser); if (oldOrder != null && order.Price != 0) { order.Volume = oldOrder.Volume; order.VolumeExecute = oldOrder.Volume - order.VolumeExecute; } } if (_securities == null) { if (order.State != OrderStateType.Activ) { return; } OrderSender sender = new OrderSender(); sender.Order = order; sender.UpdeteOrderEvent += PlazaControllerOnNewMyOrderEvent; Thread worker = new Thread(sender.Sand); worker.CurrentCulture = new CultureInfo("ru-RU"); worker.IsBackground = true; worker.Start(); return; } Security security = _securities.Find(security1 => security1.NameId == order.SecurityNameCode); if (order.SecurityNameCode != null) { if (security == null) { if (order.State != OrderStateType.Activ) { return; } OrderSender sender = new OrderSender(); sender.Order = order; sender.UpdeteOrderEvent += PlazaControllerOnNewMyOrderEvent; Thread worker = new Thread(sender.Sand); worker.CurrentCulture = new CultureInfo("ru-RU"); worker.IsBackground = true; worker.Start(); return; } order.SecurityNameCode = security.Name; } if (MyOrderEvent != null) { MyOrderEvent(order); } } }
/// <summary> /// Sets a new order Sell Stop Limit. /// </summary> private static void OrdSellStopLimit(int bar, int orderIf, int toPos, double lots, double price1, double price2, OrderSender sender, OrderOrigin origin, string note) { int sessionOrder = session[bar].Orders; Order order = session[bar].Order[sessionOrder] = new Order(); order.OrdNumb = SentOrders; order.OrdDir = OrderDirection.Sell; order.OrdType = OrderType.StopLimit; order.OrdCond = orderIf > 0 ? OrderCondition.If : OrderCondition.Norm; order.OrdStatus = OrderStatus.Confirmed; order.OrdIf = orderIf; order.OrdPos = toPos; order.OrdLots = lots; order.OrdPrice = Math.Round(price1, InstrProperties.Digits); order.OrdPrice2 = Math.Round(price2, InstrProperties.Digits); order.OrdSender = sender; order.OrdOrigin = origin; order.OrdNote = note; ordCoord[SentOrders].Bar = bar; ordCoord[SentOrders].Ord = sessionOrder; session[bar].Orders++; SentOrders++; }
static async Task Main(string[] args) { // Send Order Information To Queue await OrderSender.SendOrderInformationToQueueAsync(serviceBusConnection, queueName); // Receive Order Information To Queue await OrderReceiver.ReceiveOrderInformationFromQueueAsync(serviceBusConnection, queueName); }
public OrderSenderTests() { mockMessageService = new Mock <IMessageService>(); messageService = mockMessageService.Object; mockShippingCostCalculator = new Mock <IShippingCostCalculator>(); shippingCostCalculator = mockShippingCostCalculator.Object; orderSender = new OrderSender(shippingCostCalculator, messageService); }
/// <summary> /// Default constructor. /// </summary> public Order() { ordDir = OrderDirection.None; ordType = OrderType.None; ordCond = OrderCondition.None; ordStatus = OrderStatus.None; ordSender = OrderSender.None; ordOrigin = OrderOrigin.None; ordNote = "Not Defined"; }
public void Send_InvalidOrder_ShouldntSendMessage() { // Arrange OrderSender orderSender = new OrderSender(new OrderCalculator(), messageService); // Act orderSender.Send(new Order() { TotalAmount = 0m }); // Assert mockMessageService.Verify(ms => ms.Send(It.IsAny <Message>()), Times.Never); }
public void Send_ValidOrder_RaiseOrderSentEvent() { // Arrange OrderSender orderSender = new OrderSender(new OrderCalculator(), new FakeMessageService()); Order id = null; orderSender.OrderSent += (sender, args) => { id = args; }; // Act orderSender.Send(new Order()); // Asserts Assert.NotNull(id); }
public void Send_ValidOrder_RaiseOrderSentEvent() { // Arrange mockMessageService .Setup(ms => ms.Send(It.IsAny <Message>())) .Verifiable(); OrderSender orderSender = new OrderSender(new OrderCalculator(), messageService); Order id = null; orderSender.OrderSent += (sender, args) => { id = args; }; // Act orderSender.Send(new Order()); // Asserts Assert.NotNull(id); }
private void OperationSend(ParametrBuySellView parametrBuySell, bool isBuy) { var apiKeys = GetKeys(); if (apiKeys?.Count() > 0) { var orderSender = new OrderSender(); var resultSend = string.Empty; foreach (var apiKey in apiKeys) { var keyHidden = $"{apiKey.PublicKey.Substring(0, 4)}...{apiKey.PublicKey.Substring(apiKey.PublicKey.Length - 4, 4)}"; var parametr = orderSender.GetTransacParamLimit(parametrBuySell.GetPair(), isBuy, parametrBuySell.Amount, parametrBuySell.Price); var response = orderSender.OrderLimit(parametr, apiKey.PublicKey, apiKey.SecretKey); if (response != null) { if (string.IsNullOrWhiteSpace(response.Msg)) { resultSend += $"{keyHidden} успешно: ордер № {response.OrderId}\n"; } else { resultSend += $"{keyHidden} ошибка: {response.Msg}\n"; } } else { resultSend += $"{keyHidden} Неизвестная ошибка\n"; } } MessageBox.Show(resultSend, "BUY/SELL", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Не найдено ни одного активного ключа в статусе ОК.", "BUY/SELL", MessageBoxButton.OK, MessageBoxImage.Information); } }
/// <summary> /// в системе изменился ордер /// </summary> void _plazaController_UpdateOrders(Order order) { lock (_lockerUpdateOrders) { if (_orders != null) { Order oldOrder = _orders.Find(order1 => order1.NumberUser == order.NumberUser); if (oldOrder != null && order.Price != 0) { order.Volume = oldOrder.Volume; order.VolumeExecute = oldOrder.Volume - order.VolumeExecute; } } if (_securities == null) { if (order.State != OrderStateType.Activ) { return; } OrderSender sender = new OrderSender(); sender.Order = order; sender.UpdeteOrderEvent += _plazaController_UpdateOrders; Thread worker = new Thread(sender.Sand); worker.CurrentCulture = new CultureInfo("ru-RU"); worker.IsBackground = true; worker.Start(); return; } Security security = _securities.Find(security1 => security1.NameId == order.SecurityNameCode); if (order.SecurityNameCode != null) { if (security == null) { if (order.State != OrderStateType.Activ) { return; } OrderSender sender = new OrderSender(); sender.Order = order; sender.UpdeteOrderEvent += _plazaController_UpdateOrders; Thread worker = new Thread(sender.Sand); worker.CurrentCulture = new CultureInfo("ru-RU"); worker.IsBackground = true; worker.Start(); return; } order.SecurityNameCode = security.Name; } if (_myTrades != null && _myTrades.Count != 0) { List <MyTrade> myTrade = _myTrades.FindAll(trade => trade.NumberOrderParent == order.NumberMarket); for (int tradeNum = 0; tradeNum < myTrade.Count; tradeNum++) { if (NewMyTradeEvent != null) { NewMyTradeEvent(myTrade[tradeNum]); } } } if (_ordersNumbers == null) { _ordersNumbers = new List <string>(); } if (_ordersNumbers.Find(orderNum => orderNum == order.NumberMarket) == null) { _ordersNumbers.Add(order.NumberMarket); } if (NewOrderIncomeEvent != null) { NewOrderIncomeEvent(order); } } }
/// <summary> /// Default constructor. /// </summary> public Order() { ordDir = OrderDirection.None; ordType = OrderType.None; ordCond = OrderCondition.None; ordStatus = OrderStatus.None; ordSender = OrderSender.None; ordOrigin = OrderOrigin.None; ordNote = "Not Defined"; }
/// <summary> /// Sets a new order Buy Stop. /// </summary> static void OrdBuyStop(int bar, int orderIf, int toPos, double lots, double price, OrderSender sender, OrderOrigin origin, string note) { int sessionOrder = session[bar].Orders; Order order = session[bar].Order[sessionOrder] = new Order(); order.OrdNumb = totalOrders; order.OrdDir = OrderDirection.Buy; order.OrdType = OrderType.Stop; order.OrdCond = orderIf > 0 ? OrderCondition.If : OrderCondition.Norm; order.OrdStatus = OrderStatus.Confirmed; order.OrdIF = orderIf; order.OrdPos = toPos; order.OrdLots = lots; order.OrdPrice = Math.Round(price, InstrProperties.Digits); order.OrdPrice2 = 0; order.OrdSender = sender; order.OrdOrigin = origin; order.OrdNote = note; ordCoord[totalOrders].Bar = bar; ordCoord[totalOrders].Ord = sessionOrder; session[bar].Orders++; totalOrders++; }