Exemplo n.º 1
0
        public void UpdateSignal(ESignal Signal)
        {
            //Console.WriteLine( "In UpdateSignal" );
            if (this.EntrySignal == Signal)
            {
                // don't bother with stuff in the same direction, just keep monitoring the situation
            }
            else
            {
                switch (Signal)
                {
                case ESignal.Long:
                case ESignal.Short:
                    throw new ArgumentException(
                              instrument.Symbol + " has improper Update Signal: "
                              + Signal.ToString() + " vs " + EntrySignal.ToString());
                    break;

                case ESignal.ScaleIn:
                    break;

                case ESignal.ScaleOut:
                    break;

                case ESignal.Exit:
                    //Console.WriteLine( "UpdateSignal {0} {1} {2} {3}", Signal, State, PositionRequested, PositionFilled );
                    if (EState.WaitForExit == State || EState.EntrySent == State)
                    {
                        // cancel all outstanding orders
                        CancelSubmittedOrders();
                        // set flag so that if something gets filled, to unfill it right away
                        // later may want to keep it if things are going in the correct direction
                        SingleOrder order;
                        if (0 < PositionFilled)
                        {
                            order = atsc.MarketOrder(Side.Sell, Math.Abs(PositionFilled));
                            //entryOrder = new LimitOrder(instrument, SmartQuant.FIX.Side.Buy, Quantity, 4.55 );
                            //entryOrder = new StopOrder(instrument, SmartQuant.FIX.Side.Sell, Quantity, quote.Bid - Jump );
                            order.Text = "Long Mkt Exit";
                            ordersTag.Add(order.ClOrdID, EOrderTag.Exit);
                            PositionRequested -= Math.Abs(PositionFilled);
                            State              = EState.CleanUp;
                            trip.Exit(quote, order);
                            SendOrder(quote, order);
                        }
                        if (0 > PositionFilled)
                        {
                            order = atsc.MarketOrder(Side.Buy, Math.Abs(PositionFilled));
                            //entryOrder = new LimitOrder(instrument, SmartQuant.FIX.Side.Buy, Quantity, 4.55 );
                            //entryOrder = new StopOrder(instrument, SmartQuant.FIX.Side.Buy, Quantity, quote.Ask + Jump );
                            order.Text = "Shrt Mkt Exit";
                            ordersTag.Add(order.ClOrdID, EOrderTag.Exit);
                            PositionRequested += Math.Abs(PositionFilled);
                            State              = EState.CleanUp;
                            trip.Exit(quote, order);
                            SendOrder(quote, order);
                        }
                    }
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public TransactionSet(
            ESignal Signal, ATSComponent atsc,
            int InitialQuantity, int ScalingQuantity, int MaxQuantity,
            Quote quote, double JumpDelta,
            double HardStopDelta, double TrailingStopDelta,
            TransactionSetEventHolder eventholder
            )
        {
            //Console.WriteLine( "{0} Entered Transaction Set", quote.DateTime.ToString("HH:mm:ss.fff") );

            this.eventholder = eventholder;

            eventholder.OnUpdateQuote  += OnUpdateQuote;
            OnStrategyStopEventActive   = true;
            eventholder.OnStrategyStop += OnStrategyStop;
            OnStrategyStopEventActive   = true;

            this.EntrySignal       = Signal;
            this.JumpDelta         = JumpDelta; // extra bit for setting a limit order
            this.HardStopDelta     = HardStopDelta;
            this.TrailingStopDelta = TrailingStopDelta;
            this.quote             = quote;
            this.atsc   = atsc;
            instrument  = atsc.Instrument;
            Symbol      = instrument.Symbol;
            quanInitial = InitialQuantity;
            quanScaling = ScalingQuantity;
            quanMax     = MaxQuantity;

            trip = new RoundTrip(instrument);

            ordersSubmitted       = new Hashtable(10);
            ordersPartiallyFilled = new Hashtable(10);
            ordersFilled          = new Hashtable(10);
            ordersCancelled       = new Hashtable(10);
            ordersRejected        = new Hashtable(10);
            ordersTag             = new Hashtable(10);

            if (!((ESignal.Long == Signal) || (ESignal.Short == Signal)))
            {
                Console.WriteLine("Transaction Set Problem 1");
                throw new ArgumentException(instrument.Symbol + " has improper Entry Signal: " + Signal.ToString());
            }

            SingleOrder order;

            switch (Signal)
            {
            case ESignal.Long:
                order = atsc.MarketOrder(Side.Buy, quanInitial);
                //order = atsc.LimitOrder(Side.Buy, quanInitial);
                //entryOrder = new LimitOrder(instrument, SmartQuant.FIX.Side.Buy, Quantity, 4.55 );
                //order = atsc.StopOrder( SmartQuant.FIX.Side.Buy, quanInitial, Math.Round( quote.Ask + JumpDelta, 2 ) );
                order.Text = "Long Lmt Entr";
                ordersTag.Add(order.ClOrdID, EOrderTag.Entry);
                PositionRequested = quanInitial;
                State             = EState.EntrySent;
                trip.Enter(quote, order);
                SendOrder(quote, order);
                break;

            case ESignal.Short:
                order = atsc.MarketOrder(Side.Sell, quanInitial);
                //order = atsc.LimitOrder(Side.Sell, quanInitial);
                //entryOrder = new LimitOrder(instrument, SmartQuant.FIX.Side.Buy, Quantity, 4.55 );
                //order = atsc.StopOrder( SmartQuant.FIX.Side.Sell, quanInitial, Math.Round( quote.Bid - JumpDelta, 2 ) );
                order.Text = "Shrt Lmt Entr";
                ordersTag.Add(order.ClOrdID, EOrderTag.Entry);
                PositionRequested = -quanInitial;
                State             = EState.EntrySent;
                trip.Enter(quote, order);
                SendOrder(quote, order);
                break;
            }
        }