Пример #1
0
        /// <summary>
        /// i am using MarketSimulation to handle the orders. I do not need all arguments of the FMR API. 
        /// Only RezefBasicOrder and OrderID are in this phase. 
        /// This one is going to be our workhorse at the moment.
        /// Sends Single Rezef Order. Replaces SendRezefOrder function.
        /// </summary>
        /// <param name="sessionId">Use FMRShell.Connection.GetSessionId()</param>
        /// <param name="Order">Structure of RezefSimpleOrder Type containing all details regarding the order that is being sent.</param>
        /// <param name="AsmachtaFmr">Unique order reference number provided by FMR systems. 
        /// This reference is returned as an out parameter, and should be provided when updating or canceling the order.</param>
        /// <param name="AsmachtaRezef">Unique order reference number provided by the stock exchange. 
        /// The reference should be retrieved using order retrieval function. Must be provided when updating/canceling.</param>
        /// <param name="VBMsg">If the sending order operation is unsuccessful, a message is relayed back to the client application 
        /// with the reason for the failure. If the operation is successful, VBMsg remains empty. </param>
        /// <param name="ErrNO">If an error occurs during the operation, an error number will be relayed back to the client application.
        /// see wiki/ fmr's help for details.</param>
        /// <param name="ErrorType">Type of error returned by function call. 
        /// Error type is defined by OrdersErrorTypes enumeration. </param>
        /// <param name="OrderID">Unique order id allocated by taskbar returned by function for order transaction identification. 
        /// Must be provided when resending order due to user confirmation requirement. </param>
        /// <param name="AuthUserName">In the event that the operation requires password authorization, 
        /// this field will contain the authorizing user name. </param>
        /// <param name="AuthPassword">In the event that the operation requires password authorization, 
        /// this field will contain the password for the authorizing user. </param>
        /// <param name="ReEnteredValue">In case that the operation requires confirmation, 
        /// the field will contain the value re-entered by the user. </param>
        /// <returns>The function returns 0 upon success and -1 upon failure. </returns>
        public virtual int SendOrderRZ(int sessionId, ref RezefSimpleOrder Order, ref int AsmachtaFmr, int AsmachtaRezef, out string VBMsg, out int ErrNO,
            out OrdersErrorTypes ErrorType, ref int OrderID, string AuthUserName, string AuthPassword, string ReEnteredValue)
        {
            //initialize data
            int rc = 0;
            VBMsg = "";
            ErrNO = 0;
            ErrorType = OrdersErrorTypes.NoError;

            //continue flag
            bool _continue = false;

            //check the arguments, internal error if something is wrong
            if (sessionId != this._sessionId)
            {
                VBMsg = "Sending failure";
                ErrNO = -2;
                ErrorType = OrdersErrorTypes.Fatal;
                rc = -1;
            }

            else
            {
                if (
                Order.operation == OrderOperation.OrderOperationDelete ||
                Order.operation == OrderOperation.OrderOperationUpdBuy ||
                Order.operation == OrderOperation.OrderOperationUpdSell)
                {
                    if (AsmachtaFmr == 0 || AsmachtaRezef == 0)
                    {
                        VBMsg = "Missing parameters in RezefBasicOrder Type.";
                        ErrNO = 91;
                        ErrorType = OrdersErrorTypes.Fatal;
                        rc = -1;
                    }
                }

                if (Order.Amount >= 99999)
                {
                    if (ReEnteredValue == "YES")
                    {
                        _continue = true;
                    }
                    else
                    {
                        VBMsg = " Order value above permitted limit.";
                        ErrNO = 9;
                        ErrorType = OrdersErrorTypes.Confirmation;
                        rc = -1;
                    }
                }

                else if (Order.price <= 0)
                {
                    if (ReEnteredValue == default(string))
                    {
                        VBMsg = "LMT Order value above permitted limit.";
                        ErrNO = 3;
                        ErrorType = OrdersErrorTypes.ReEnter;
                        rc = -1;
                    }
                    else
                    {
                        Order.price = JQuant.Convert.StrToDouble(ReEnteredValue);
                        _continue = true;
                    }
                }

                else if (Order.price > 50000)
                {
                    if (AuthPassword == default(string) ||
                        AuthUserName == default(string))
                    {
                        VBMsg = "Illegal change from base rate.";
                        ErrNO = 25;
                        ErrorType = OrdersErrorTypes.PasswordReq;
                        rc = -1;
                    }
                    else
                        _continue = true;
                }

                else if (Order.price == 1)
                {
                    VBMsg = "Illegal difference between Closing price and Base price.";
                    ErrNO = 22;
                    ErrorType = OrdersErrorTypes.Alert;
                    _continue = true;
                }
                else
                {
                    _continue = true;
                }

                if (_continue)
                {
                    //only in case of success the order is passed to TASE:

                    switch (Order.operation)
                    {
                        //a new order
                        case OrderOperation.OrderOperationNewBuy:
                        case OrderOperation.OrderOperationNewSell:
                            this._rezefSimpleOrder = Order;
                            this._orderId++;            //generate unique order id
                            AsmachtaFmr = _orderId;     //initialize ref no
                            this._pollsCounter = 0;
                            this._orderState = rzOrdersStates.WaitingApprove;
                            break;
                        //cancel
                        case OrderOperation.OrderOperationDelete:
                            this._pollsCounter = 0;
                            this._orderState = rzOrdersStates.WaitingCancel;
                            break;
                        //update
                        case OrderOperation.OrderOperationUpdBuy:
                        case OrderOperation.OrderOperationUpdSell:
                            this._rezefSimpleOrder = Order; //just copy updated order
                            this._pollsCounter = 0;
                            this._orderState = rzOrdersStates.WaitingUpdate;
                            break;
                    }
                }
            }

            return rc;
        }
Пример #2
0
        /// <summary>
        /// Retrieves a detailed list of Rezef orders and executions for the specifed branch and account.
        /// GetOrdersRZ receives Order records either directly from the Order's Server or from an AS/400 server, 
        /// depending on the user's configuration. To enable the records to be drawn from the server, 
        /// OrdersStreamStart must first be executed. Records can be parsed using the RZFINQType structure. 
        /// </summary>
        /// <param name="sessionId">Use FMRShell.Connection.GetSessionId()</param>
        /// <param name="vecRecords">A String array into which the rezef order records will be inserted. 
        /// If strLastTime is specified and is other than "00000000", the vector will represent any orders
        /// received after that time. </param>
        /// <param name="Account">A filter, use FMRShell.Connection.Parameters.Account property</param>
        /// <param name="Branch">A filter, use FMRShell.Connection.Parameters.Branch property</param>
        /// <param name="LastTime">This is the 'Retrieve & Refresh' last time parameter. 
        /// Only records which have been updated past this time will be retrieved. 
        /// If this parameter is omitted or if "0" is specified all records are retrieved regardless of update time. </param>
        /// <returns>Upon success the function returns the total number of records retrieved into vecRecords. 
        /// -1 : General function failure. 
        /// -2 : Orders Data source initialization failure.
        /// -4 : Short Account not found.
        /// -5 : Inedequate authorization.</returns>
        public virtual int GetOrdersRZ(int sessionId, out Array vecRecords, string Account, string Branch, ref string LastTime)
        {
            //respond only if there is not null order instance in waiting state
            if (this._rezefSimpleOrder.Equals(default(RezefSimpleOrder)))
            {
                vecRecords = new object[0];
            }
            else
            {
                //give it some time to respond - always get back after 4 polls:
                if (this._pollsCounter < 4)
                {
                    _pollsCounter++;
                    vecRecords = new object[0];
                }
                else
                {
                    //reset polls counter
                    this._pollsCounter = 0;

                    // fill the vecRecords
                    RZFINQType data = new RZFINQType();

                    Random rand = new Random();

                    data.BNO_N = _rezefSimpleOrder.BNO.ToString();
                    data.BNO_NAME = rand.Next().ToString();
                    data.BRANCH_N = "000";
                    data.COD_UPD = rand.Next().ToString();
                    data.DIL_N = rand.Next().ToString(); ;
                    data.DIL_NV_N = rand.Next().ToString();
                    data.DIL_PRC_N = rand.Next().ToString();
                    data.DIL_TIME_N = rand.Next().ToString();
                    data.DSP_FMR = rand.Next().ToString();
                    data.ERR = rand.Next().ToString();
                    data.ERR_DATA = rand.Next().ToString();
                    data.ERR_INQ = rand.Next().ToString();
                    data.ERR_UPD = rand.Next().ToString();
                    data.ID_MAVR_N = rand.Next().ToString();
                    data.ID_N = rand.Next().ToString();
                    data.ID_NAME = rand.Next().ToString();
                    data.MANA_N = rand.Next().ToString();
                    data.MBR_SEQ_N = rand.Next().ToString();
                    data.MSG1 = rand.Next().ToString();
                    data.NOSTRO = rand.Next().ToString();
                    data.OP = rand.Next().ToString();
                    data.OPR_NAME = rand.Next().ToString();
                    data.ORDER_NO_N = rand.Next().ToString();
                    data.ORDR_NV_N = rand.Next().ToString();
                    data.ORDR_PRC_N = rand.Next().ToString();
                    data.ORDR_SUG = rand.Next().ToString();
                    data.ORDR_TIME = rand.Next().ToString();
                    data.ORDR_TYPE = rand.Next().ToString();
                    data.RZF_ORD_N = rand.Next().ToString();
                    data.RZF_SEQ_N = rand.Next().ToString();
                    data.SEQ_N = this._orderId.ToString(); //this is our AsmachtaFMR - order's unique id
                    data.SND_RCV = rand.Next().ToString();
                    data.STS_NAME = rand.Next().ToString();
                    data.SUG_ID_N = rand.Next().ToString();
                    data.SUG_INFO = rand.Next().ToString();
                    data.SUG_INQ = rand.Next().ToString();
                    data.SUG_MAVR_N = rand.Next().ToString();
                    data.SUG_N = rand.Next().ToString();
                    data.SYS_TYPE = rand.Next().ToString();
                    data.TIK_N = rand.Next().ToString();

                    switch (_orderState)
                    {
                        case rzOrdersStates.WaitingApprove:
                        case rzOrdersStates.WaitingUpdate:
                            data.STS = "4"; //"נקלט" - approved TASE  - just change its value in order to test various events in orders FSM
                            this._orderState = rzOrdersStates.WaitingFill;
                            break;
                        case rzOrdersStates.WaitingFill:
                            data.STS = "6"; //"בצוע מלא" - complete fill TODO: add support for partial fill
                            //cleanup after the fill
                            /*
                            this._orderState = rzOrdersStates.Idle;
                            this._rezefSimpleOrder = default(RezefSimpleOrder);
                            */
                            break;
                        case rzOrdersStates.WaitingCancel:
                            data.STS = "7"; //"בוטל"
                            //cleanup after cancel
                            this._orderState = rzOrdersStates.Idle;
                            this._rezefSimpleOrder = default(RezefSimpleOrder);
                            break;
                        default:
                            data.STS = "A"; //"שגוי"
                            //cleanup - the order is not valid anymore
                            this._orderState = rzOrdersStates.Idle;
                            this._rezefSimpleOrder = default(RezefSimpleOrder);
                            break;
                    }

                    if (data.STS == "6")
                    {
                        vecRecords = new object[0];
                    }
                    else
                    {
                        vecRecords = new object[1];
                        vecRecords.SetValue(data, 0);
                    }

                    //fill LastTime with the value
                    LastTime =
                        DateTime.Now.Hour.ToString() +
                        DateTime.Now.Minute.ToString() +
                        DateTime.Now.Second.ToString() +
                        DateTime.Now.Millisecond.ToString()
                        ;

                    this._pollsCounter = 0;

                }
            }
            return vecRecords.Length;
        }