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(); }
public override bool updateRealPositions() { if (CFATManager.m_nRunMode != ERUN_MODE.REALTIME) { return(true); } List <TMT4PosItem> lstPosMT4 = m_mt4ApiDLL.mt4_getPositions(); TPosItem posItem; m_lstPos_real.Clear(); //string sLog = string.Format("update position : {0}\r\n", m_sSiteName); for (int i = 0; i < lstPosMT4.Count; i++) { if (isHedgePosition(lstPosMT4[i].m_sSymbol, lstPosMT4[i].m_dLots, (ETRADER_OP)lstPosMT4[i].m_nCmd)) { continue; } posItem = new TPosItem(); posItem.m_nTicket = lstPosMT4[i].m_nTicket; posItem.m_sSymbol = lstPosMT4[i].m_sSymbol; posItem.m_dOpenPrice_exc = lstPosMT4[i].m_dOpenPrice; posItem.m_dLots_exc = lstPosMT4[i].m_dLots; posItem.m_dCommission = lstPosMT4[i].m_dCommission; posItem.m_nCmd = (ETRADER_OP)lstPosMT4[i].m_nCmd; m_lstPos_real.Add(posItem); //sLog += string.Format("ticket={0}, symbol={1}, cmd = {2}, openPrice={3}, lots={4}, commission={5}\r\n", // posItem.m_nTicket, posItem.m_sSymbol, posItem.m_nCmd, posItem.m_dOpenPrice, posItem.m_dLots, posItem.m_dCommission); } //CFATLogger.output_proc(sLog); return(true); }
public bool publishTradeHistory() { if (m_nPublishedPosCnt == m_lstPosHistory_vt.Count) { return(false); } string sMsg = ""; sMsg = m_sSiteName; sMsg += "@"; sMsg += m_sID; sMsg += "@"; sMsg += CFATCommon.m_dtCurTime.ToString("yyyy/MM/dd HH:mm:ss.fff"); sMsg += "@"; TPosItem posItem = null; for (int i = m_nPublishedPosCnt; i < m_lstPosHistory_vt.Count; i++) { posItem = m_lstPosHistory_vt[i]; sMsg += posItem.getString(); sMsg += "@"; } m_nPublishedPosCnt = m_lstPosHistory_vt.Count; CMQClient.publish_msg(sMsg, CFATCommon.MQ_TOPIC_POSHISTORY); return(true); }
public override bool updateRealPositions() { if (CFATManager.m_nRunMode != ERUN_MODE.REALTIME) { return(true); } List <TMPPosItem> lstPosMT4 = m_mpApiDLL.MP_getPositions(); TPosItem posItem; m_lstPos_real.Clear(); for (int i = 0; i < lstPosMT4.Count; i++) { posItem = new TPosItem(); posItem.m_sTicket = lstPosMT4[i].m_sTicket; posItem.m_sSymbol = lstPosMT4[i].m_sSymbol; posItem.m_dOpenPrice_exc = lstPosMT4[i].m_dOpenPrice; posItem.m_dLots_exc = lstPosMT4[i].m_dLots; posItem.m_dCommission = lstPosMT4[i].m_dCommission; posItem.m_nCmd = (ETRADER_OP)lstPosMT4[i].m_nCmd; m_lstPos_real.Add(posItem); } return(true); }
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); }
public override bool updateRealPositions() { if (CFATManager.m_nRunMode != ERUN_MODE.REALTIME) { return(true); } apiIB.getPositons(); TPosItem posItem; m_lstPos_real.Clear(); //string sLog = string.Format("update position : {0}\r\n", m_sSiteName); foreach (TIBPositionItem ibPosItem in CIBApi.g_lstPositions) { if (Math.Abs(ibPosItem.dLots) < CFATCommon.ESP) { continue; } posItem = new TPosItem(); posItem.m_sSymbol = ibPosItem.sSymbol; posItem.m_dOpenPrice_exc = ibPosItem.dOpenPrice; if (ibPosItem.dLots > 0) { posItem.m_dLots_exc = ibPosItem.dLots / getContractSize(ibPosItem.sSymbol); posItem.m_nCmd = ETRADER_OP.BUY; } else { posItem.m_dLots_exc = ibPosItem.dLots * (-1) / getContractSize(ibPosItem.sSymbol); posItem.m_nCmd = ETRADER_OP.SELL; } m_lstPos_real.Add(posItem); //sLog += string.Format("ticket={0}, symbol={1}, cmd = {2}, openPrice={3}, lots={4}, commission={5}\r\n", // posItem.m_nTicket, posItem.m_sSymbol, posItem.m_nCmd, posItem.m_dOpenPrice, posItem.m_dLots, posItem.m_dCommission); } //CFATLogger.output_proc(sLog); return(true); }
private void addToHistoryItem(TPosItem posItem) { posItem.m_dtCloseTime_exc = m_rates[posItem.m_sSymbol].m_dtTime; m_lstPosHistory_vt.Add(posItem); m_report.m_dProfit += posItem.m_dProfit_real; //Update Profit }