Beispiel #1
0
 public Mantle.Fix44.OrderCancelReplaceRequest OrderCancelReplaceRequest(
     NewOrderRequest request, string orderID, decimal quantity, decimal price, OnReplaceReject onReject)
 {
     var res = new Mantle.Fix44.OrderCancelReplaceRequest() { StandardHeader = StandardHeader() };
     res.ClOrdID.Value = _clOrdIDGenerator.GenerateID();
     res.OrigClOrdID.Value = res.ClOrdID.Value;
     res.OrderID.Value = orderID;
     res.Account.Value = _cfg.Account;
     if (_cfg.PartyID != null)
     {
         var party = new Mantle.Fix44.Party();
         party.PartyID.Value = _cfg.PartyID;
         party.PartyIDSource.Value = _cfg.PartyIDSource;
         party.PartyRole.Value = _cfg.PartyRole;
         res.PartyGroup.Add(party);
     }
     res.Instrument.Symbol.Value = request.Symbol;
     res.Price.Value = price;
     res.OrderQty.Value = quantity;
     if (_cfg.TradingSessionID != null)
         res.TradingSessionIDGroup.Add(new Mantle.Fix44.TradingSessionID { Value = _cfg.TradingSessionID });
     res.OrdType.Value = request.OrderType == OrderType.Market ? '1' : '2';
     res.Side.Value = request.Side == Side.Buy ? '1' : '2';
     res.TransactTime.Value = res.StandardHeader.SendingTime.Value;
     if (onReject == OnReplaceReject.Cancel)
         res.CancelOrigOnReject.Value = true;
     return res;
 }
Beispiel #2
0
        public Mantle.Fix44.OrderCancelReplaceRequest OrderCancelReplaceRequest(
            NewOrderRequest request, string orderID, decimal quantity, decimal price, OnReplaceReject onReject)
        {
            var res = new Mantle.Fix44.OrderCancelReplaceRequest()
            {
                StandardHeader = StandardHeader()
            };

            res.ClOrdID.Value     = _clOrdIDGenerator.GenerateID();
            res.OrigClOrdID.Value = res.ClOrdID.Value;
            res.OrderID.Value     = orderID;
            res.Account.Value     = _cfg.Account;
            if (_cfg.PartyID != null)
            {
                var party = new Mantle.Fix44.Party();
                party.PartyID.Value       = _cfg.PartyID;
                party.PartyIDSource.Value = _cfg.PartyIDSource;
                party.PartyRole.Value     = _cfg.PartyRole;
                res.PartyGroup.Add(party);
            }
            res.Instrument.Symbol.Value = request.Symbol;
            res.Price.Value             = price;
            res.OrderQty.Value          = quantity;
            if (_cfg.TradingSessionID != null)
            {
                res.TradingSessionIDGroup.Add(new Mantle.Fix44.TradingSessionID {
                    Value = _cfg.TradingSessionID
                });
            }
            res.OrdType.Value      = request.OrderType == OrderType.Market ? '1' : '2';
            res.Side.Value         = request.Side == Side.Buy ? '1' : '2';
            res.TransactTime.Value = res.StandardHeader.SendingTime.Value;
            if (onReject == OnReplaceReject.Cancel)
            {
                res.CancelOrigOnReject.Value = true;
            }
            return(res);
        }
Beispiel #3
0
        bool Replace(IOrder order, NewOrderRequest request, decimal quantity, decimal price, OnReplaceReject onReject)
        {
            try
            {
                if (!_cfg.ReplaceEnabled)
                {
                    switch (onReject)
                    {
                    case OnReplaceReject.Keep:
                        _log.Info("Order Replace() requested but the exchange doesn't support moves. Doing nothing.");
                        return(false);

                    case OnReplaceReject.Cancel:
                        _log.Info("Order ReplaceOrCancel() requested but the exchange doesn't support moves. Just cancelling.");
                        return(Cancel(order, request));
                    }
                    Debug.Assert(false, "Unreachable");
                }

                if (order.IsPending)
                {
                    _log.Info("Can't replace order with a pending request", order);
                    return(false);
                }
                // If OnReplaceReject is Keep, the order status should be Accepted.
                // If it's Cancel, the order status may also be PartiallyFilled.
                if (order.Status != OrderStatus.Accepted &&
                    (onReject == OnReplaceReject.Keep || order.Status != OrderStatus.PartiallyFilled))
                {
                    _log.Info("Order is not in a replacable state with OnReject policy = {0}: {1}", onReject, order);
                    return(false);
                }
                Assert.NotNull(order.OrderID);
                Mantle.Fix44.OrderCancelReplaceRequest msg =
                    _messageBuilder.OrderCancelReplaceRequest(request, order.OrderID, quantity, price, onReject);
                return(StoreOp(order, msg.ClOrdID.Value, _connection.Send(msg), null));
            }
            catch (Exception e)
            {
                if (!_disposed)
                {
                    _log.Error(e, "Unexpected error while replacing an order");
                }
                return(false);
            }
        }