Esempio n. 1
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));
            }
            bool bRet = true;

            double dLots_req  = dLots;
            double dPrice_req = dPrice;

            //Send Request newOrder or Close or
            if (nCmd == ETRADER_OP.BUY)
            {
                bRet = m_mt5ApiDLL.mt4_reqNewOrder(sSymbol, "BUY", ref dLots, ref dPrice);
            }

            if (nCmd == ETRADER_OP.SELL)
            {
                bRet = m_mt5ApiDLL.mt4_reqNewOrder(sSymbol, "SELL", ref dLots, ref dPrice);
            }

            if (nCmd == ETRADER_OP.BUY_CLOSE || nCmd == ETRADER_OP.SELL_CLOSE)
            {
                bRet = closeOrder(sSymbol, nCmd, ref dLots, ref dPrice, nOrderType, sLogicID);
            }

            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. 2
0
        // ---

        public int reqOrder_async(ETRADER_OP nCmd, double dLots, double dPrice, EORDER_TYPE nOrderType, int nPriority, string sComment = "")
        {
            m_reqOrder_async.m_bProcessed = false;

            m_reqOrder_async.setProduct(m_sSymbol, m_site, m_sLogicID, m_dContractSize);
            m_reqOrder_async.setVal(nCmd, dLots, dPrice, nOrderType, nPriority, m_sLogicID, sComment);

            return(CSiteMng.registerOrder(m_reqOrder_async));
        }
Esempio n. 3
0
        public void setVal(ETRADER_OP nCmd, double dLots_req, double dPrice_req, EORDER_TYPE nOrderType,
                           int nPriority, string sLogicID, string sComment)
        {
            m_nCmd       = nCmd;
            m_dLots_req  = dLots_req;
            m_dPrice_req = dPrice_req;
            m_nOrderType = nOrderType;
            m_nPriority  = nPriority;
            m_sLogicID   = sLogicID;
            m_sComment   = sComment;

            m_dLots_exc    = 0;
            m_nOrderResult = EFILLED_STATE.FAIL;
            m_dPrice_exc   = 0;
        }
Esempio n. 4
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));
            }
            //Send Request newOrder or Close or
            //MessageBox.Show("CSiteFixMt4::reqOrder !");
            string sOrderID = "FAT" + DateTime.Now.ToString("yyyyMMddHHmmssfff");
            double dAmount  = 0;

            string sCmd = "";

            if (nCmd == ETRADER_OP.BUY || nCmd == ETRADER_OP.SELL_CLOSE)
            {
                sCmd = "BUY";
            }
            if (nCmd == ETRADER_OP.SELL || nCmd == ETRADER_OP.BUY_CLOSE)
            {
                sCmd = "SELL";
            }

            dAmount = dLots * getContractSize(sSymbol);

            //MessageBox.Show("Before QueryEnterOrder!");
            CFATLogger.output_proc(string.Format("Fix req : sym={0},price={1}, amount={2}, order id= {3}, acc = {4}, cmd = {5}", sSymbol, dPrice, dAmount, sOrderID, m_sFixAcc, sCmd));
            double dPrice_req = dPrice;
            double dLots_req  = dLots;
            int    nRet       = m_fixApi_trade.QueryEnterOrder(sSymbol, sCmd, ref dPrice, ref dAmount, sOrderID, m_sFixAcc);

            dLots = dAmount / getContractSize(sSymbol);
            CFATLogger.output_proc(string.Format("Fix response : result = {0}, sym={1},price={2}, amount={3}, ", nRet, sSymbol, dPrice, dAmount));
            //if ( nRet == TORDER_RESULT.FILLED) //HSM_???
            return(base.reqOrder(sSymbol, nCmd, ref dLots_req, ref dPrice_req, nOrderType, sLogicID, sComment, dLots, dPrice, DateTime.Now));
            //return false;
        }
Esempio n. 5
0
        private bool closeOrder(string sSymbol, ETRADER_OP nCmd, ref double dLots, ref double dPrice, EORDER_TYPE nOrderType, string sLogicID, string sComment = "")
        {
            CFATLogger.output_proc(string.Format("close order : site = {0}, sym= {1}, cmd = {2}, lots = {3}", m_sSiteName, sSymbol, nCmd, dLots));
            double   dRemainLots = dLots;
            TPosItem posItem;
            bool     bRet = true;

            for (int i = 0; i < m_lstPos_real.Count; i++)
            {
                posItem = m_lstPos_real[i];

                if (posItem.m_sSymbol != sSymbol)
                {
                    continue;
                }
                //if (posItem.m_nLogicID != nLogicID) continue;

                if (!isValidCloseCommand(posItem.m_nCmd, nCmd))
                {
                    continue;
                }

                if (dRemainLots >= posItem.m_dLots_exc)
                {
                    CFATLogger.output_proc(string.Format("close item : ticket = {0}, lots = {1}", posItem.m_nTicket, posItem.m_dLots_exc));
                    bRet         = m_mt4ApiDLL.mt4_reqCloseOrder(posItem.m_nTicket, ref posItem.m_dLots_exc, ref dPrice);
                    dRemainLots -= posItem.m_dLots_exc;
                }
                else
                {
                    CFATLogger.output_proc(string.Format("close item : ticket = {0}, lots = {1}", posItem.m_nTicket, dRemainLots));
                    bRet        = m_mt4ApiDLL.mt4_reqCloseOrder(posItem.m_nTicket, ref dRemainLots, ref dPrice);
                    dRemainLots = 0;
                }

                if (Math.Abs(dRemainLots) < CFATCommon.ESP)
                {
                    break;
                }
            }

            return(true);
        }
Esempio n. 6
0
        private void closeOrder(string sSymbol, ETRADER_OP nCmd, double dLots, double dPrice, EORDER_TYPE nOrderType, string sLogicID, string sComment = "",
                                double dLots_exc = 0, double dPrice_exc = 0, DateTime dtTime_exc = default(DateTime))
        {
            if (sLogicID == "REQ_MERGE")
            {
                return;
            }
            double   dRemainLots = dLots_exc;
            TPosItem posItem;

            for (int i = 0; i < m_lstPos_vt.Count; i++)
            {
                posItem = m_lstPos_vt[i];

                if (posItem.m_sSymbol != sSymbol)
                {
                    continue;
                }
                if (posItem.m_sLogicID != sLogicID)
                {
                    continue;
                }

                if (!isValidCloseCommand(posItem.m_nCmd, nCmd))
                {
                    continue;
                }

                if (dRemainLots >= posItem.m_dLots_exc - CFATCommon.ESP)
                {
                    m_lstPos_vt.Remove(posItem);
                    i--;
                    posItem.m_sComment       += "@";
                    posItem.m_sComment       += sComment;
                    posItem.m_dClosePrice_exc = dPrice_exc;
                    posItem.m_dtCloseTime_req = m_rates[sSymbol].m_dtTime;
                    posItem.m_dtCloseTime_exc = dtTime_exc;
                    posItem.calcProfit();
                    addToHistoryItem(posItem);
                    dRemainLots -= posItem.m_dLots_exc;
                }
                else
                {
                    posItem.m_dLots_exc -= dRemainLots;
                    posItem.calcProfit();
                    m_lstPos_vt[i] = posItem;

                    posItem.m_dLots_exc       = dRemainLots;
                    posItem.m_sComment       += "@";
                    posItem.m_sComment       += sComment;
                    posItem.m_dClosePrice_exc = dPrice_exc;
                    posItem.m_dtCloseTime_req = m_rates[sSymbol].m_dtTime;
                    posItem.m_dtCloseTime_exc = dtTime_exc;
                    posItem.calcProfit();
                    addToHistoryItem(posItem);
                    dRemainLots = 0;
                }

                if (Math.Abs(dRemainLots) < CFATCommon.ESP)
                {
                    break;
                }
            }
        }
Esempio n. 7
0
 public virtual 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))
 {
     return(register2Vt(sSymbol, nCmd, ref dLots, ref dPrice, nOrderType, sLogicID, sComment, dLots_exc, dPrice_exc, dtTime_exc));
 }
Esempio n. 8
0
        private EFILLED_STATE register2Vt(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 (dLots_exc == 0)
            {
                dLots_exc = dLots;
            }
            if (dPrice_exc == 0)
            {
                dPrice_exc = dPrice;
            }

            if (dtTime_exc == default(DateTime))
            {
                dtTime_exc = m_rates[sSymbol].m_dtTime;
            }

            if (nCmd == ETRADER_OP.BUY || nCmd == ETRADER_OP.SELL)
            {//For new order
                TPosItem posItem = new TPosItem();
                posItem.m_dtOpenTime_req = m_rates[sSymbol].m_dtTime;
                posItem.m_dtOpenTime_exc = dtTime_exc;

                posItem.m_dOpenPrice_req = dPrice;
                posItem.m_dOpenPrice_exc = dPrice_exc;

                posItem.m_dLots_req = dLots;
                posItem.m_dLots_exc = dLots_exc;

                posItem.m_nCmd                = nCmd;
                posItem.m_sSymbol             = sSymbol;
                posItem.m_dProfit_vt          = 0;
                posItem.m_sLogicID            = sLogicID;
                posItem.m_sComment            = sComment;
                posItem.m_dContractSize       = getContractSize(sSymbol);
                posItem.m_dCommission_percent = getCommissionPercent(sSymbol);

                if (sLogicID != "REQ_MERGE")
                {
                    m_lstPos_vt.Add(posItem);
                }
            }

            if (nCmd == ETRADER_OP.BUY_CLOSE || nCmd == ETRADER_OP.SELL_CLOSE)
            {//For close order
                closeOrder(sSymbol, nCmd, dLots, dPrice, nOrderType, sLogicID, sComment, dLots_exc, dPrice_exc, dtTime_exc);
            }

            EFILLED_STATE nRet = EFILLED_STATE.PARTIAL;

            if (Math.Abs(dLots - dLots_exc) < CFATCommon.ESP)
            {
                nRet = EFILLED_STATE.FULL;
            }
            if (Math.Abs(dLots_exc) < CFATCommon.ESP)
            {
                nRet = EFILLED_STATE.FAIL;
            }
            return(nRet);// updateRealPositions();
        }
Esempio n. 9
0
 // modified by cmh
 public EFILLED_STATE reqOrder_withoutEXC(ETRADER_OP nCmd, ref double dLots, ref double dPrice, EORDER_TYPE nOrderType, string sLogicID, string sComment = "")
 {
     return(m_site.reqOrder_withoutEXC(m_sSymbol, nCmd, ref dLots, ref dPrice, nOrderType, sLogicID, sComment));
 }
Esempio n. 10
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. 11
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));
            }

            double dAmount = 0;

            string sCmd = "";

            if (nCmd == ETRADER_OP.BUY || nCmd == ETRADER_OP.SELL_CLOSE)
            {
                sCmd = "BUY";
            }
            if (nCmd == ETRADER_OP.SELL || nCmd == ETRADER_OP.BUY_CLOSE)
            {
                sCmd = "SELL";
            }

            dAmount = dLots * getContractSize(sSymbol);

            CFATLogger.output_proc(string.Format("IB req : sym={0},price={1}, amount={2}, cmd = {3}", sSymbol, dPrice, dAmount, sCmd));
            double dPrice_req = dPrice;
            double dLots_req  = dLots;
            bool   bRet       = apiIB.reqOrder(sSymbol, sCmd, ref dAmount, ref dPrice);

            dLots = dAmount / getContractSize(sSymbol);
            CFATLogger.output_proc(string.Format("IB response : result = {0}, sym={1},price={2}, amount={3}, ", bRet, sSymbol, dPrice, dAmount));
            //if ( nRet == TORDER_RESULT.FILLED) //HSM_???
            if (!bRet)
            {
                return(EFILLED_STATE.FAIL);
            }
            return(base.reqOrder(sSymbol, nCmd, ref dLots_req, ref dPrice_req, nOrderType, sLogicID, sComment, dLots, dPrice, DateTime.Now));
            //return false;
        }
Esempio n. 12
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))
        {
            EFILLED_STATE nRet      = EFILLED_STATE.FULL;
            ETRADER_OP    nCmd_req  = nCmd;
            double        dLots_req = dLots;

            available_lots_cmd(sSymbol, ref nCmd_req, ref dLots_req);

            if (Math.Abs(dLots_req - dLots) > CFATCommon.ESP)
            {
                nRet  = EFILLED_STATE.PARTIAL;
                dLots = dLots_req;
            }

            base.reqOrder(sSymbol, nCmd_req, ref dLots_req, ref dPrice, nOrderType, sLogicID, sComment, dLots_req, dPrice, CFATCommon.m_dtCurTime);
            return(nRet);
        }