Ejemplo n.º 1
0
        public void requestOrder(ETRADER_OP nCmd, double dLots_req, bool bReqAsync = false)
        {
            double dReqPrice_A = 0;
            double dReqPrice_B = 0;
            double dReqPrice_C = 0;
            double dLots       = dLots_req;

//HSM???
//             if (nCmd == ETRADER_OP.BUY_CLOSE || nCmd == ETRADER_OP.SELL_CLOSE)
//                 dLots = Math.Abs(m_product_A.getPosLots_Total_real()); //Some times there is different virtual & real lots

            if (nCmd == ETRADER_OP.BUY || nCmd == ETRADER_OP.SELL_CLOSE)
            {
                dReqPrice_A = m_product_A.m_dAsk;
                dReqPrice_B = m_product_B.m_dBid;
                if (m_nType_trade == EPRODUCT_TYPE_TRADE.A_BC)
                {
                    dReqPrice_C = m_product_C.m_dBid;
                }
            }

            if (nCmd == ETRADER_OP.SELL || nCmd == ETRADER_OP.BUY_CLOSE)
            {
                dReqPrice_A = m_product_A.m_dBid;
                dReqPrice_B = m_product_B.m_dAsk;
                if (m_nType_trade == EPRODUCT_TYPE_TRADE.A_BC)
                {
                    dReqPrice_C = m_product_C.m_dAsk;
                }
            }

            if (!bReqAsync)
            {
                m_product_A.reqOrder(nCmd, ref dLots, ref dReqPrice_A, EORDER_TYPE.MARKET);//First Order
                m_product_B.reqOrder(TRADER.cmdOpposite(nCmd), ref dLots, ref dReqPrice_B, EORDER_TYPE.MARKET);

                if (m_nType_trade == EPRODUCT_TYPE_TRADE.A_BC)
                {
                    m_product_C.reqOrder(TRADER.cmdOpposite(nCmd), ref dLots, ref dReqPrice_C, EORDER_TYPE.MARKET);
                }
            }
            else
            {
                m_product_A.reqOrder_async(nCmd, dLots, dReqPrice_A, EORDER_TYPE.PENDING_STOP, 0);//First Order
                m_product_B.reqOrder_async(TRADER.cmdOpposite(nCmd), dLots * 0.32, dReqPrice_B, EORDER_TYPE.MARKET, 1);

                if (m_nType_trade == EPRODUCT_TYPE_TRADE.A_BC)
                {
                    m_product_C.reqOrder_async(TRADER.cmdOpposite(nCmd), dLots * 0.46, dReqPrice_C, EORDER_TYPE.MARKET, 2);
                }
            }
        }
Ejemplo n.º 2
0
        public void requestSecondSiteOrder()
        {
            double dReqPrice_second = 0;
            double dLots            = ex_dLots;

            if (ex_nUseRandomLots == 1)
            {
                dLots = getRandomLots(dLots);
            }

            dLots += ex_dAddLots;

            int           nProfit_calc_02 = 0;
            EFILLED_STATE nRet;

            if (m_nCmd4Thread == ETRADER_OP.BUY_CLOSE || m_nCmd4Thread == ETRADER_OP.SELL_CLOSE)
            {
                dLots = Math.Abs(m_products[_SECOND].getPosLots_vt(0));
            }

            if (dLots < CFATCommon.ESP)
            {
                CFATLogger.output_proc("*** Invalid Lots !!!, pls check virtual position!!!!");
                dLots = ex_dLots;
            }

            if (m_nCmd4Thread == ETRADER_OP.BUY || m_nCmd4Thread == ETRADER_OP.SELL_CLOSE)
            {
                dReqPrice_second = m_products[_SECOND].m_dBid;
                nProfit_calc_02  = 1;
            }

            if (m_nCmd4Thread == ETRADER_OP.SELL || m_nCmd4Thread == ETRADER_OP.BUY_CLOSE)
            {
                dReqPrice_second = m_products[_SECOND].m_dAsk;
                nProfit_calc_02  = -1;
            }

            dLots = getSecondLots(dLots);
            nRet  = m_products[_SECOND].reqOrder(TRADER.cmdOpposite(m_nCmd4Thread), ref dLots, ref dReqPrice_second, EORDER_TYPE.MARKET);
            if (nRet == EFILLED_STATE.FULL)
            {
                m_tradeHistory.pushHistory(dReqPrice_second * nProfit_calc_02);
                if (m_nCmd4Thread == ETRADER_OP.SELL_CLOSE || m_nCmd4Thread == ETRADER_OP.BUY_CLOSE)
                {
                    m_tradeHistory.settleHistory();
                }
            }
            else
            {
                CFATLogger.output_proc("second order failed!");
                m_tradeHistory.setProfitAsZero();
                clearAllPositions();
                setState(ELOGIC_STATE.WAITING_FORCE_CLOSE);
                return;
            }

            // setState(ELOGIC_STATE.NEED_CHECK_POSITION_MATCH);
            m_dtLastFilledTime    = DateTime.Now;
            m_bIsSecondThreadLive = false;
            m_products[_SECOND].m_site.setStatus(Site.CSite.SITE_STATUS.NONE);
        }
Ejemplo n.º 3
0
        private void requestOrder(ETRADER_OP nCmd)
        {
            // modified by cmh
            if (ex_bAsyncOrder)
            {
                m_nCmd4Thread         = nCmd;
                m_bIsFirstThreadLive  = true;
                m_bIsSecondThreadLive = true;
                m_bIsOrderHappened    = true;
                m_products[_FIRST].m_site.setStatus(Site.CSite.SITE_STATUS.PROCESSING);
                m_products[_SECOND].m_site.setStatus(Site.CSite.SITE_STATUS.PROCESSING);
                Thread thFirstOrder  = new Thread(requestFirstSiteOrder);
                Thread thSecondOrder = new Thread(requestSecondSiteOrder);
                thFirstOrder.Start();
                thSecondOrder.Start();
                return;
            }
            // ---

            double dReqPrice_first  = 0;
            double dReqPrice_second = 0;
            double dLots            = ex_dLots;

            if (ex_nUseRandomLots == 1)
            {
                dLots = getRandomLots(dLots);
            }

            dLots += ex_dAddLots;

            int           nProfit_calc_01 = 0;
            int           nProfit_calc_02 = 0;
            EFILLED_STATE nRet;

            if ((nCmd == ETRADER_OP.BUY || nCmd == ETRADER_OP.SELL) && m_products[_FIRST].getPosCount_vt() == 0)
            {
                setParam_newOrder(ex_nIsNewOrder - 1);
            }

            if (nCmd == ETRADER_OP.BUY_CLOSE || nCmd == ETRADER_OP.SELL_CLOSE)
            {
                dLots = Math.Abs(m_products[_FIRST].getPosLots_vt(0));
            }

            if (dLots < CFATCommon.ESP)
            {
                CFATLogger.output_proc("*** Invalid Lots !!!, pls check virtual postion!!!!");
                dLots = ex_dLots;
            }

            if (nCmd == ETRADER_OP.BUY || nCmd == ETRADER_OP.SELL_CLOSE)
            {
                dReqPrice_first  = m_products[_FIRST].m_dAsk;
                dReqPrice_second = m_products[_SECOND].m_dBid;
                //dReqPrice_self = m_dAsk_First_low;
                nProfit_calc_01 = -1;
                nProfit_calc_02 = 1;
            }

            if (nCmd == ETRADER_OP.SELL || nCmd == ETRADER_OP.BUY_CLOSE)
            {
                dReqPrice_first  = m_products[_FIRST].m_dBid;
                dReqPrice_second = m_products[_SECOND].m_dAsk;
                //dReqPrice_self = m_dBid_First_high;
                nProfit_calc_01 = 1;
                nProfit_calc_02 = -1;
            }

            m_nTradeRet = ETRADE_RET.NEWORDER;

            nRet = m_products[_FIRST].reqOrder(nCmd, ref dLots, ref dReqPrice_first, EORDER_TYPE.MARKET);//First Order
            if (nRet == EFILLED_STATE.FULL)
            {
                m_tradeHistory.pushHistory(dReqPrice_first * nProfit_calc_01);
                dLots = getSecondLots(dLots);
                nRet  = m_products[_SECOND].reqOrder(TRADER.cmdOpposite(nCmd), ref dLots, ref dReqPrice_second, EORDER_TYPE.MARKET);
                if (nRet == EFILLED_STATE.FULL)
                {
                    m_tradeHistory.pushHistory(dReqPrice_second * nProfit_calc_02);
                    if (nCmd == ETRADER_OP.SELL_CLOSE || nCmd == ETRADER_OP.BUY_CLOSE)
                    {
                        m_tradeHistory.settleHistory();
                    }
                }
                else
                {
                    CFATLogger.output_proc("second order failed!");
                    m_tradeHistory.setProfitAsZero();
                    clearAllPositions();
                    setState(ELOGIC_STATE.WAITING_FORCE_CLOSE);
                    return;
                }
            }
            else
            {
                CFATLogger.output_proc("first order failed!");
            }

            setState(ELOGIC_STATE.NEED_CHECK_POSITION_MATCH);
            m_dtLastFilledTime = DateTime.Now;
        }