public NewOrderRepresentation CreateOrder(CreateOrderCommand orderCommand) { IOrderIdGenerator orderIdGenerator = ContextRegistry.GetContext()["OrderIdGenerator"] as IOrderIdGenerator; Tuple <string, string> splittedCurrencyPairs = CurrencySplitterService.SplitCurrencyPair(orderCommand.Pair); Order order = OrderFactory.CreateOrder(orderCommand.TraderId, orderCommand.Pair, orderCommand.Type, orderCommand.Side, orderCommand.Volume, orderCommand.Price, orderIdGenerator); if (_balanceValidationService.FundsConfirmation(order.TraderId.Id, splittedCurrencyPairs.Item1, splittedCurrencyPairs.Item2, order.Volume.Value, order.Price.Value, order.OrderSide.ToString(), order.OrderId.Id)) { InputDisruptorPublisher.Publish(InputPayload.CreatePayload(order)); return(new NewOrderRepresentation(order)); } throw new InvalidOperationException("Not Enough Balance for Trader with ID: " + orderCommand.TraderId); }
/// <summary> /// </summary> /// <param name="orderContext"></param> /// <param name="qutationContext"></param> /// <param name="orderStore"></param> /// <param name="orderPolicyStore"></param> /// <param name="pricePolicyStore"></param> /// <param name="generator"></param> /// <param name="notify"></param> /// <param name="logger"></param> public OrderService(OrderContext orderContext, QuotationContext qutationContext, IOrderStore orderStore, IOrderPolicyStore orderPolicyStore, IPricePolicyStore pricePolicyStore, IOrderIdGenerator generator, IOrderNotify notify, ILogger <OrderService> logger) { if (orderContext == null) { throw new ArgumentNullException(nameof(orderContext)); } if (qutationContext == null) { throw new ArgumentNullException(nameof(qutationContext)); } if (orderStore == null) { throw new ArgumentNullException(nameof(orderStore)); } if (generator == null) { throw new ArgumentNullException(nameof(generator)); } if (notify == null) { throw new ArgumentNullException(nameof(notify)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } _orderContext = orderContext; _qutationContext = qutationContext; _orderStore = orderStore; _orderPolicyStore = orderPolicyStore; _pricePolicyStore = pricePolicyStore; _orderIdGenerator = generator; _notify = notify; _logger = logger; DefaultOpenOpenPricePolicy = new RealTimeOpenPricePolicy(); }
public int?GetLastOrderId(IOrderIdGenerator idGenerator) { throw new NotImplementedException(); }
public static Order CreateOrder(string traderId, string currencyPair, string type, string side, decimal volume, decimal limitPrice, IOrderIdGenerator orderIdGenerator) { Order order = null; TraderId id = new TraderId(traderId); OrderId orderId = orderIdGenerator.GenerateOrderId(); Volume orderVolume = new Volume(volume); if (side.Equals(Constants.ORDER_SIDE_BUY, StringComparison.CurrentCultureIgnoreCase) && type.Equals(Constants.ORDER_TYPE_MARKET, StringComparison.CurrentCultureIgnoreCase)) { Price price = new Price(0); order = BuyMarketOrder(orderId, currencyPair, OrderType.Market, orderVolume, price, id); } else if (side.Equals(Constants.ORDER_SIDE_SELL, StringComparison.CurrentCultureIgnoreCase) && type.Equals(Constants.ORDER_TYPE_MARKET, StringComparison.CurrentCultureIgnoreCase)) { Price price = new Price(0); order = SellMarketOrder(orderId, currencyPair, OrderType.Market, orderVolume, price, id); } else if (side.Equals(Constants.ORDER_SIDE_BUY, StringComparison.CurrentCultureIgnoreCase) && type.Equals(Constants.ORDER_TYPE_LIMIT, StringComparison.CurrentCultureIgnoreCase)) { Price price = new Price(limitPrice); order = BuyLimitOrder(orderId, currencyPair, price, OrderType.Limit, orderVolume, id); } else if (side.Equals(Constants.ORDER_SIDE_SELL, StringComparison.CurrentCultureIgnoreCase) && type.Equals(Constants.ORDER_TYPE_LIMIT, StringComparison.CurrentCultureIgnoreCase)) { Price price = new Price(limitPrice); order = SellLimitOrder(orderId, currencyPair, price, OrderType.Limit, orderVolume, id); } //TODO:Validation of funds and other things return(order); }
public OrderService(IOrderIdGenerator idGenerator, IBasketRepository basketRepository) { this.idGenerator = idGenerator; this.basketRepository = basketRepository; }