Exemple #1
0
        /// <summary>
        /// Event notification for price update
        /// </summary>
        void m_ps_FieldsUpdated(object sender, FieldsUpdatedEventArgs e)
        {
            if (e.Error == null)
            {
                // Make sure that there is a valid bid
                if (e.Fields.GetBestBidPriceField().HasValidValue)
                {
                    if (m_orderKey == "")
                    {
                        // In this example, the order is submitted to ASE-A.
                        // You should use the order feed that is appropriate for your purposes.
                        AutospreaderSyntheticOrderProfile op = new AutospreaderSyntheticOrderProfile(((AutospreaderInstrument)e.Fields.Instrument).GetValidGateways()[m_ASEGateway],
                                                                                                     (AutospreaderInstrument)e.Fields.Instrument);
                        op.BuySell       = BuySell.Buy;
                        op.OrderQuantity = Quantity.FromInt(e.Fields.Instrument, 10);
                        op.OrderType     = OrderType.Limit;
                        op.LimitPrice    = e.Fields.GetBestBidPriceField().Value;

                        if (!m_ts.SendOrder(op))
                        {
                            Console.WriteLine("Send new order failed.  {0}", op.RoutingStatus.Message);
                        }
                        else
                        {
                            m_orderKey = op.SiteOrderKey;
                            Console.WriteLine("Send new order succeeded.");
                        }
                    }
                    else if (m_ts.Orders.ContainsKey(m_orderKey) &&
                             m_ts.Orders[m_orderKey].LimitPrice != e.Fields.GetBestBidPriceField().Value)
                    {
                        // If there is a working order, reprice it if its price is not the same as the bid
                        AutospreaderSyntheticOrderProfile op = m_ts.Orders[m_orderKey].GetOrderProfile() as AutospreaderSyntheticOrderProfile;
                        op.LimitPrice = e.Fields.GetBestBidPriceField().Value;
                        op.Action     = OrderAction.Change;

                        if (!m_ts.SendOrder(op))
                        {
                            Console.WriteLine("Send change order failed.  {0}", op.RoutingStatus.Message);
                        }
                        else
                        {
                            Console.WriteLine("Send change order succeeded.");
                        }
                    }
                }
            }
            else
            {
                if (e.Error.IsRecoverableError == false)
                {
                    Console.WriteLine("Unrecoverable price subscription error: {0}", e.Error.Message);
                    Dispose();
                }
            }
        }
Exemple #2
0
        public static bool CancelAutospreaderOrder(string orderKey, ttapiUtils.AutoSpreader autoSpreader, Logger logger)
        {
            ASInstrumentTradeSubscription Ts = autoSpreader.ts;
            bool Status = false;

            if (Ts.Orders.ContainsKey(orderKey))
            {
                AutospreaderSyntheticOrderProfile Op = Ts.Orders[orderKey].GetOrderProfile() as AutospreaderSyntheticOrderProfile;

                Op.Action = OrderAction.Delete;

                if (!Ts.SendOrder(Op))
                {
                    logger.Log("Cancal order failed.  {0}" + Op.RoutingStatus.Message);
                }
                else
                {
                    logger.Log("Cancel order succeeded.");
                    Status = true;
                }
            }

            return(Status);
        }
Exemple #3
0
        public static bool ChangeAutospreaderOrder(string orderKey, decimal price, ttapiUtils.AutoSpreader autoSpreader,
                                                   TradingTechnologies.TTAPI.Instrument instrument, Logger logger)
        {
            ASInstrumentTradeSubscription Ts = autoSpreader.ts;
            bool Status = false;

            if (Ts.Orders.ContainsKey(orderKey))
            {
                AutospreaderSyntheticOrderProfile Op = Ts.Orders[orderKey].GetOrderProfile() as AutospreaderSyntheticOrderProfile;
                Rounding Rounding = Rounding.Down;

                if (Op.BuySell == BuySell.Sell)
                {
                    Rounding = Rounding.Up;
                }

                Price LimitPrice = Price.FromDouble(instrument.InstrumentDetails, Convert.ToDouble(price), Rounding);

                if (Op.LimitPrice != LimitPrice)
                {
                    Op.LimitPrice = LimitPrice;
                    Op.Action     = OrderAction.Change;

                    if (!Ts.SendOrder(Op))
                    {
                        logger.Log("Send change order failed.  {0}" + Op.RoutingStatus.Message);
                    }
                    else
                    {
                        logger.Log("Send change order succeeded.");
                        Status = true;
                    }
                }
            }
            return(Status);
        }