Esempio n. 1
0
        private void checkForOpen()
        {
            if (m_product_diff.getPosCount_vt() > 0)
            {
                return;
            }
            //             if (CFATCommon.m_dtCurTime.Hour == 15)
            //                 return;

            int nSignal = getSignal();
            int nSig_cc = m_indCC.getSignal(ex_dOpen_abs, ex_dClose_abs);

            if (TRADER.isContain(nSignal, (int)ETRADER_OP.BUY) &&
                TRADER.isContain(nSig_cc, (int)ETRADER_OP.BUY))
            {
                if (ex_nIsNewOrder > 0)
                {
                    requestOrder(ETRADER_OP.BUY);
                }
            }

            if (TRADER.isContain(nSignal, (int)ETRADER_OP.SELL) &&
                TRADER.isContain(nSig_cc, (int)ETRADER_OP.SELL))
            {
                if (ex_nIsNewOrder > 0)
                {
                    requestOrder(ETRADER_OP.SELL);
                }
            }
        }
Esempio n. 2
0
        private void checkForOpen()
        {
            if (m_products[ID_SHANGHAI].getPosCount_vt() == 1)
            {
                return;
            }

            DateTime dtCurTime = m_products[ID_SHANGHAI].getTickTime();

            if (isMarketCloseTime_forOpen())
            {
                return;
            }

            int nSignal = getSignal();

            if (TRADER.isContain(nSignal, (int)ETRADER_OP.BUY))
            {
                requestOrder(ETRADER_OP.BUY);
            }

            if (TRADER.isContain(nSignal, (int)ETRADER_OP.SELL))
            {
                requestOrder(ETRADER_OP.SELL);
            }
        }
Esempio n. 3
0
        public bool Update(TRADER trader)
        {
            var targetUpdate = db.TRADERs.Find(trader.Id_Trader);

            try
            {
                targetUpdate.Id_Trader        = trader.Id_Trader;
                targetUpdate.Id_User          = trader.Id_User;
                targetUpdate.Name_Trader      = trader.Name_Trader;
                targetUpdate.Birthday_Trader  = trader.Birthday_Trader;
                targetUpdate.Gender_Trader    = trader.Gender_Trader;
                targetUpdate.Address_Trader   = trader.Address_Trader;
                targetUpdate.Telephone_Trader = trader.Telephone_Trader;
                targetUpdate.Email_Trader     = trader.Email_Trader;

                db.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                return(false);

                throw new Exception(e.Message);
            }
        }
Esempio n. 4
0
        private void checkForOpen()
        {
            if (m_product_diff.getPosCount_vt() > 0)
            {
                return;
            }

            int nSignal = getSignal();

            if (TRADER.isContain(nSignal, (int)ETRADER_OP.BUY))
            {
                if (ex_nIsNewOrder > 0)
                {
                    requestOrder(ETRADER_OP.BUY);
                }
            }

            if (TRADER.isContain(nSignal, (int)ETRADER_OP.SELL))
            {
                if (ex_nIsNewOrder > 0)
                {
                    requestOrder(ETRADER_OP.SELL);
                }
            }
        }
Esempio n. 5
0
        public void setData(string sData)
        {
            string[] sVals = sData.Split(',');

            m_dtOpenTime_req  = Convert.ToDateTime(sVals[0]);
            m_dtOpenTime_exc  = Convert.ToDateTime(sVals[1]);
            m_dtCloseTime_req = Convert.ToDateTime(sVals[2]);
            m_dtCloseTime_exc = Convert.ToDateTime(sVals[3]);

            m_sSymbol   = sVals[4];
            m_dLots_req = Convert.ToDouble(sVals[5]);
            m_dLots_exc = Convert.ToDouble(sVals[6]);

            m_nCmd = TRADER.string2Cmd(sVals[7]);

            m_dOpenPrice_req = Convert.ToDouble(sVals[8]);
            m_dOpenPrice_exc = Convert.ToDouble(sVals[9]);

            m_dClosePrice_req = Convert.ToDouble(sVals[10]);
            m_dClosePrice_exc = Convert.ToDouble(sVals[11]);

            m_dProfit_real = Convert.ToDouble(sVals[12]);
            m_sLogicID     = sVals[13];
            m_sComment     = sVals[14];
        }
Esempio n. 6
0
        private void checkForClose()
        {
            if (m_product_diff.getPosCount_vt() == 0)
            {
                return;
            }

            //CheckForClose by Signal line
            int nSignal = getSignal();
            int nSig_cc = m_indCC.getSignal(ex_dOpen_abs, ex_dClose_abs);

            ETRADER_OP nCmd = m_product_diff.getPosCmd_vt(0);

            if (nCmd == ETRADER_OP.BUY && TRADER.isContain(nSignal, (int)ETRADER_OP.BUY_CLOSE) &&
                TRADER.isContain(nSig_cc, (int)ETRADER_OP.BUY_CLOSE))
            {
                requestOrder(ETRADER_OP.BUY_CLOSE);
                return;
            }

            if (nCmd == ETRADER_OP.SELL && TRADER.isContain(nSignal, (int)ETRADER_OP.SELL_CLOSE) &&
                TRADER.isContain(nSig_cc, (int)ETRADER_OP.SELL_CLOSE))
            {
                requestOrder(ETRADER_OP.SELL_CLOSE);
                return;
            }


            //CheckForClose by Absolution profit
            if (m_products[0].getPosProfit_vt(0) + m_products[1].getPosProfit_vt(0) * m_products[2].m_dMid >= ex_dP_ABS)
            {
                if (nCmd == ETRADER_OP.BUY)
                {
                    requestOrder(ETRADER_OP.BUY_CLOSE);
                }
                if (nCmd == ETRADER_OP.SELL)
                {
                    requestOrder(ETRADER_OP.SELL_CLOSE);
                }
                return;
            }

            /*
             * //CheckForClose by MarketEndTime with minimum profit, 15:00~ 15:30
             * if ( CFATCommon.m_dtCurTime.Hour == 15 )
             * {
             *  if (m_products[0].getPosProfit_vt(0) + m_products[1].getPosProfit_vt(0) * m_products[2].m_dMid >= ex_dP_MIN)
             *  {
             *      if (nCmd == ETRADER_OP.BUY)
             *          requestOrder(ETRADER_OP.BUY_CLOSE);
             *      if (nCmd == ETRADER_OP.SELL)
             *          requestOrder(ETRADER_OP.SELL_CLOSE);
             *      return;
             *  }
             * }
             */
        }
Esempio n. 7
0
 public int getSignal_unitTest()
 {
     for (int i = 0; i < m_lstUnitTest_signal.Count; i++)
     {
         if (m_lstUnitTest_signal[i].m_dtTime == CFATCommon.m_dtCurTime)
         {
             CFATLogger.output_proc(string.Format("unitTest signal : {0},{1}", m_sLogicID, m_lstUnitTest_signal[i].m_sCmd));
             return((int)TRADER.string2Cmd(m_lstUnitTest_signal[i].m_sCmd));
         }
     }
     return((int)ETRADER_OP.NONE);
 }
Esempio n. 8
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);
                }
            }
        }
Esempio n. 9
0
        private void checkForClose()
        {
            // added by cmh
            if (m_bIsFirstThreadLive || m_bIsSecondThreadLive)
            {
                return;
            }

            if (m_products[_FIRST].m_site.getStatus() == Site.CSite.SITE_STATUS.PROCESSING || m_products[_SECOND].m_site.getStatus() == Site.CSite.SITE_STATUS.PROCESSING)
            {
                return;
            }
            // ---
            if (m_products[_FIRST].getPosCount_vt() == 0)
            {
                return;
            }

            if ((DateTime.Now - m_dtLastFilledTime).TotalSeconds < ex_nPosHoldTimeSec)
            {
                return;
            }


            int        nSignal = getSignal();
            ETRADER_OP nCmd    = m_products[_FIRST].getPosCmd_vt(0);

            double dLots = ex_dLots;

            if (nCmd == ETRADER_OP.BUY && TRADER.isContain(nSignal, (int)ETRADER_OP.BUY_CLOSE))
            {
                if (CFATManager.isOnlineMode())
                {
                    CFATLogger.output_proc("close buy !");
                }
                requestOrder(ETRADER_OP.BUY_CLOSE);
                check3Times_loss();
                return;
            }

            if (nCmd == ETRADER_OP.SELL && TRADER.isContain(nSignal, (int)ETRADER_OP.SELL_CLOSE))
            {
                if (CFATManager.isOnlineMode())
                {
                    CFATLogger.output_proc("close sell !");
                }
                requestOrder(ETRADER_OP.SELL_CLOSE);
                check3Times_loss();
                return;
            }
        }
Esempio n. 10
0
        public string getString()
        {
            string sRet = "";

            sRet = string.Format("{0},{1},{2},{3}," +                                   //request open time, excute open time, request close time, request close time
                                 "{4},{5:0.000},{6:0.000},{7}," +                       // symbol, request lots, excute lots, command
                                 "{8:0.00000},{9:0.00000},{10:0.00000},{11:0.00000}," + // request open price, excute open price, request close price, excute close price
                                 "{12:0.00},{13},{14}",                                 // profit, logic id, comment
                                 m_dtOpenTime_req.ToString("yyyy-MM-dd HH:mm:ss.fff"), m_dtOpenTime_exc.ToString("yyyy-MM-dd HH:mm:ss.fff"),
                                 m_dtCloseTime_req.ToString("yyyy-MM-dd HH:mm:ss.fff"), m_dtCloseTime_exc.ToString("yyyy-MM-dd HH:mm:ss.fff"),
                                 m_sSymbol, m_dLots_req, m_dLots_exc, TRADER.cmd2String(m_nCmd),
                                 m_dOpenPrice_req, m_dOpenPrice_exc, m_dClosePrice_req, m_dClosePrice_exc,
                                 m_dProfit_real, m_sLogicID, m_sComment);
            return(sRet);
        }
        public ActionResult Account(TRADER trader)
        {
            var result = traderDAO.Update(trader);

            if (result)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "Cập nhật thất bại !!!");
                var traderModelState = traderDAO.Details(trader.Id_Trader);
                return(View(traderModelState));
            }
        }
Esempio n. 12
0
        public override bool updateRealPositions()
        {
            if (CFATManager.m_nRunMode != ERUN_MODE.REALTIME)
            {
                return(true);
            }

            TPosItem posItem;

            m_lstPos_real.Clear();

            string sSymbol = "";
            double dPrice  = 0;
            int    nLots   = 0;

            CSHGoldAPI.sg_getPositionList();
            int    nPosCnt = CSHGoldAPI.sg_getPositionCount();
            string sMsg    = string.Format("SHGold Position count = {0}\r\n", nPosCnt);
            string sCmd    = "";

            for (int i = 0; i < nPosCnt; i++)
            {
                CSHGoldAPI.sg_getPositionInfo(i, ref sSymbol, ref dPrice, ref nLots, ref sCmd);
                sMsg += string.Format("symbol = {0}, open price = {1}, lots = {2}\r\n", sSymbol, dPrice, nLots);
                if (nLots == 0)
                {
                    continue;
                }
                posItem                  = new TPosItem();
                posItem.m_sSymbol        = sSymbol;
                posItem.m_dOpenPrice_exc = dPrice;
                posItem.m_nCmd           = TRADER.string2Cmd(sCmd);
                if (sCmd == "BUY")
                {//Buy
                    posItem.m_nCmd      = ETRADER_OP.BUY;
                    posItem.m_dLots_exc = nLots;
                }
                else
                {//Sell
                    posItem.m_nCmd      = ETRADER_OP.SELL;
                    posItem.m_dLots_exc = nLots;
                }

                m_lstPos_real.Add(posItem);
            }
            //CFATLogger.output_proc(sMsg);
            return(true);
        }
Esempio n. 13
0
        private void checkForClose()
        {
            if (m_product_diff.getPosCount_vt() == 0)
            {
                return;
            }

            int        nSignal = getSignal();
            ETRADER_OP nCmd    = m_product_diff.getPosCmd_vt(0);

            if (nCmd == ETRADER_OP.BUY && TRADER.isContain(nSignal, (int)ETRADER_OP.BUY_CLOSE))
            {
                requestOrder(ETRADER_OP.BUY_CLOSE);
            }

            if (nCmd == ETRADER_OP.SELL && TRADER.isContain(nSignal, (int)ETRADER_OP.SELL_CLOSE))
            {
                requestOrder(ETRADER_OP.SELL_CLOSE);
            }
        }
Esempio n. 14
0
        public override EFILLED_STATE reqOrder(string sSymbol, ETRADER_OP nCmd, ref double dLots, ref double dPrice, EORDER_TYPE nOrderType, string sLogicID, string sComment = "",
                                               double dLots_exc = 0, double dPrice_exc = 0, DateTime dtTime_exc = default(DateTime))
        {
            if (CFATManager.m_nRunMode == ERUN_MODE.SIMULATION)
            {
                return(base.reqOrder(sSymbol, nCmd, ref dLots, ref dPrice, nOrderType, sLogicID, sComment, dLots, dPrice, DateTime.Now));
            }

            string sCmd       = TRADER.cmd2String(nCmd);
            double dLots_req  = dLots;
            double dPrice_req = dPrice;

            bool bRet = CSHGoldAPI.sg_newOrder(sSymbol, sCmd, ref dPrice, ref dLots);

            if (!bRet)
            {
                return(EFILLED_STATE.FAIL);
            }

            return(base.reqOrder(sSymbol, nCmd, ref dLots_req, ref dPrice_req, nOrderType, sLogicID, sComment, dLots, dPrice, DateTime.Now));
        }
Esempio n. 15
0
        private void checkForClose()
        {
            if (m_products[ID_SHANGHAI].getPosCount_vt() == 0)
            {
                return;
            }

            ETRADER_OP nCmd      = m_products[ID_SHANGHAI].getPosCmd_vt(0);
            ETRADER_OP nCloseCmd = TRADER.getCloseCmd(nCmd);

            double dProfit = m_products[ID_SHANGHAI].getPosProfit_vt(0);

            setMinMax_forLog();

            if (isMarketCloseTime_forClose())
            {
                //m_products[ID_SHANGHAI].reqCloseAll("Market Time Close");
                requestOrder(nCloseCmd, getMinMaxStr_forLog());
                return;
            }


            int nSignal = getSignal();

            if (nCmd == ETRADER_OP.BUY && TRADER.isContain(nSignal, (int)ETRADER_OP.BUY_CLOSE))
            {
                //m_products[ID_SHANGHAI].reqCloseAll();
                requestOrder(ETRADER_OP.BUY_CLOSE, getMinMaxStr_forLog());
                return;
            }

            if (nCmd == ETRADER_OP.SELL && TRADER.isContain(nSignal, (int)ETRADER_OP.SELL_CLOSE))
            {
                //m_products[ID_SHANGHAI].reqCloseAll();
                requestOrder(ETRADER_OP.SELL_CLOSE, getMinMaxStr_forLog());
                return;
            }
        }
Esempio n. 16
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);
        }
Esempio n. 17
0
        private void requestOrder(ETRADER_OP nCmd, string sComment = "")
        {
            double dLots     = ex_dLots;
            double dPrice    = 0;
            double dCurPrice = 0;

            if (nCmd == ETRADER_OP.BUY || nCmd == ETRADER_OP.SELL_CLOSE)
            {//Buy or SellClose
                dCurPrice = m_dAsk_Shanghai;
                dPrice    = m_dAsk_Shanghai + ex_dSlippage;
                if (nCmd == ETRADER_OP.BUY)
                {
                    m_dOpen_ld_midPrice = m_dMid_London;
                    m_dMaxProfit        = -100;
                    m_dMinProfit        = 100;
                }
                m_dOpen10TickSeconds = get10TickSecond();
            }
            else//Sell or BuyClose
            {
                dCurPrice = m_dBid_Shanghai;
                dPrice    = m_dBid_Shanghai - ex_dSlippage;
                if (nCmd == ETRADER_OP.SELL)
                {
                    m_dOpen_ld_midPrice = m_dMid_London;
                    m_dMaxProfit        = -100;
                    m_dMinProfit        = 100;
                }
                m_dOpen10TickSeconds = get10TickSecond();
            }



            //For BackTest
            if (!CFATManager.isOnlineMode())
            {
                m_products[ID_SHANGHAI].reqOrder(nCmd, ref dLots, ref dPrice, EORDER_TYPE.MARKET, sComment);
                double dLDPrice = m_dMid_London;
                m_products[ID_LONDON].reqOrder(nCmd, ref dLots, ref dLDPrice, EORDER_TYPE.MARKET, sComment);
                return;
            }

            //For RealTime
            if (nCmd == ETRADER_OP.BUY_CLOSE || nCmd == ETRADER_OP.SELL_CLOSE)
            {
                if (ex_nIsNewOrder <= 0)
                {
                    ex_nIsNewOrder = 1;
                }
            }

            if (ex_nIsNewOrder > 0)
            {
                CFATLogger.output_proc(string.Format("Request order, cmd = {0}, current price ={1}, request price = {2}, request lost = {3}", TRADER.cmd2String(nCmd), dCurPrice, dPrice, dLots));
                m_products[ID_SHANGHAI].reqOrder(nCmd, ref dLots, ref dPrice, EORDER_TYPE.MARKET, sComment);
                CFATLogger.output_proc(string.Format("Response order, response price = {0}, response lost = {1}", dPrice, dLots));
                ex_nIsNewOrder--;
                m_bIsNeedCheckPosition = true;
            }
            else
            {
                CFATLogger.output_proc(string.Format("new Signal = {0}, ex_nIsNewOrder = {1}", TRADER.cmd2String(nCmd), ex_nIsNewOrder));
            }
        }
Esempio n. 18
0
        // ---
        private void checkForOpen()
        {
            // added by cmh
            if (m_bIsFirstThreadLive || m_bIsSecondThreadLive)
            {
                return;
            }

            if (m_products[_FIRST].m_site.getStatus() == Site.CSite.SITE_STATUS.PROCESSING || m_products[_SECOND].m_site.getStatus() == Site.CSite.SITE_STATUS.PROCESSING)
            {
                return;
            }
            // ---
            if (m_products[_FIRST].getPosCount_vt() >= ex_nMaxPosCnt)
            {
                return;
            }

            if ((DateTime.Now - m_dtLastFilledTime).TotalSeconds < ex_nNewPosTimeSec)
            {
                return;
            }

            if (m_nTradeRet == ETRADE_RET.NEWORDER)// If position closed at checkForClose with same tick,
            {
                return;
            }


            int nSignal = getSignal();


            if (TRADER.isContain(nSignal, (int)ETRADER_OP.BUY))
            {
                if (m_products[_FIRST].getPosCount_vt() > 0)
                {
                    if (m_products[_FIRST].getPosCmd_vt(0) != ETRADER_OP.BUY)
                    {
                        return;
                    }
                }

                if (ex_nIsNewOrder > 0)
                {
                    if (CFATManager.isOnlineMode())
                    {
                        CFATLogger.output_proc(string.Format("open buy ! bid = {0}, ask = {1}, bid = {2}, ask = {3}",
                                                             m_products[_FIRST].m_dBid, m_products[_FIRST].m_dAsk, m_products[_SECOND].m_dBid, m_products[_SECOND].m_dAsk));
                    }
                    requestOrder(ETRADER_OP.BUY);
                }
                //                 else
                //                     CFATLogger.output_proc(string.Format("{0} : Signal Buy! diff = {1}, bid = {2}, ask = {3}, bid = {4}, ask = {5}",m_sLogicID, m_products[_SECOND].m_dBid - m_products[_FIRST].m_dAsk,
                //                         m_products[_FIRST].m_dBid, m_products[_FIRST].m_dAsk, m_products[_SECOND].m_dBid, m_products[_SECOND].m_dAsk));
            }

            if (TRADER.isContain(nSignal, (int)ETRADER_OP.SELL))
            {
                if (m_products[_FIRST].getPosCount_vt() > 0)
                {
                    if (m_products[_FIRST].getPosCmd_vt(0) != ETRADER_OP.SELL)
                    {
                        return;
                    }
                }

                if (ex_nIsNewOrder > 0)
                {
                    if (CFATManager.isOnlineMode())
                    {
                        CFATLogger.output_proc(string.Format("open sell ! bid = {0}, ask = {1}, bid = {2}, ask = {3}",
                                                             m_products[_FIRST].m_dBid, m_products[_FIRST].m_dAsk, m_products[_SECOND].m_dBid, m_products[_SECOND].m_dAsk));
                    }
                    requestOrder(ETRADER_OP.SELL);
                }
                //                 else
                //                     CFATLogger.output_proc(string.Format("{0} : Signal Sell! diff = {1}, bid = {2}, ask = {3}, bid = {4}, ask = {5}",m_sLogicID, m_products[_FIRST].m_dBid - m_products[_SECOND].m_dAsk,
                //                         m_products[_FIRST].m_dBid, m_products[_FIRST].m_dAsk, m_products[_SECOND].m_dBid, m_products[_SECOND].m_dAsk));
            }
        }
Esempio n. 19
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;
        }