void Z_DC_Spread_Policy::OnNewFutureMD(MarketDataField* pMD)
{
	if(IsCallAuction(pMD)){
		return;
	}
	UpdateMD(pMD);
	if(m_bStopOnClose && m_MyTradeA.m_nLongPos<1 && m_MyTradeA.m_nShortPos<1 && m_MyTradeB.m_nLongPos<1 && m_MyTradeB.m_nShortPos<1){
		m_nCurrentStage = 0;
		m_nPositiveAddedFlag = 0;
		m_nPositiveAddEnableFlag = 0;
		m_nNegativeAddedFlag = 0;
		m_nNegativeAddEnableFlag = 0;
		m_MyTradeA.m_fBasePrice = 0;
		m_MyTradeB.m_fBasePrice = 0;
		m_nTotalAddTimes = 0;
		m_nTotalSubTimes = 0;
		SetAttr("totalAddtimes",m_nTotalAddTimes);
		SetAttr("totalSubTimes",m_nTotalSubTimes);
		SetAttr("current_stage",m_nCurrentStage);
		SetAttr("Padded_flag",m_nPositiveAddedFlag);
		SetAttr("Nadded_flag",m_nNegativeAddedFlag);
		SetAttr("Paddenable_flag",m_nPositiveAddEnableFlag);
		SetAttr("Naddenable_flag",m_nNegativeAddEnableFlag);
		SetAttr("base_price_a",0);
		SetAttr("base_price_b",0);
		Stop();
		ShowInfo(&m_MyTradeA,"Close stop.",0);
		return;
	}
	//if(m_MyTradeA.m_pLastMD != NULL && m_MyTradeB.m_pLastMD !=NULL){
		//m_fCurrentPriceDisparity = abs( m_MyTradeA.m_pLastMD->LastPrice - m_MyTradeB.m_pLastMD->LastPrice);
	//}
	if(!m_bStopOnClose && m_MyTradeA.m_pLastMD != NULL && m_MyTradeB.m_pLastMD !=NULL){
	/*	if(strcmp(pMD->InstrumentID, m_MyTradeA.m_InstrumentID)==0){	//For Test
			cout<<m_MyTradeA.m_pLastMD->UpdateTime<<" "<<m_MyTradeB.m_pLastMD->UpdateTime<<endl;
		}*/
		//cout<<(strcmp(pMD->InstrumentID, m_MyTradeA.m_InstrumentID) == 0)<<" "<<GetTimeInterval(m_MyTradeA.m_pLastMD->UpdateTime,m_MyTradeB.m_pLastMD->UpdateTime)<<" "<<m_nCurrentStage<<" "<<m_MyTradeA.m_nLongPos<<" "<<m_MyTradeB.m_nShortPos<<endl;
		if(strcmp(pMD->InstrumentID, m_MyTradeA.m_InstrumentID)==0 && GetTimeInterval(m_MyTradeA.m_pLastMD->UpdateTime,m_MyTradeB.m_pLastMD->UpdateTime)){
			if(m_nCurrentStage == 0 && m_MyTradeA.m_nLongPos==0 && m_MyTradeB.m_nShortPos == 0 && !IsTradeLimit(true)){//m_nCurrentStage == 0 &&
				ShowInfo(&m_MyTradeA,"Set Up Base Pos!",0);
				OpenLong(&m_MyTradeA);
				OpenShort(&m_MyTradeB);
				m_MyTradeA.m_fBasePrice = m_MyTradeA.m_pLastMD->LastPrice;
				m_MyTradeB.m_fBasePrice = m_MyTradeB.m_pLastMD->LastPrice;
				m_nCurrentStage = 1;

				SetBaseFlag(&m_MyTradeA);
				SetAttr("base_price_a",m_MyTradeA.m_fBasePrice);
				SetAttr("base_price_b",m_MyTradeB.m_fBasePrice);
				SetAttr("current_stage",m_nCurrentStage);
			}

			//判断当前盈利状况
			if(!this->GetBarCloseFlag(m_MyTradeA.m_pSeries,pMD,5)){//收盘前五秒没有买卖信号判断
				ManageRateSingal();
			}
			//if(m_MyTradeA.m_pLastMD!=NULL && m_MyTradeB.m_pLastMD!=NULL){
			CalProfit();
			//}
		}
	}

}
Exemplo n.º 2
0
_SEntityDefProperties* CDefParser::ReadProperty(SEntityDef* pDef, TiXmlElement* node)
{
    _SEntityDefProperties* pProp = new _SEntityDefProperties;
    pProp->m_name.assign(node->Value());

    TiXmlElement* field_attri = node->FirstChildElement("Type");
    if(field_attri)
    {
        const char* szTypeName = field_attri->GetText();
        VTYPE vt = GetVTypeByStr(szTypeName);
        if(vt != V_TYPE_ERR)
        {
            pProp->m_nType = vt;
        }
        //else if(strcmp(szTypeName, "ARRAY") == 0)
        //{
        //    //array of ***特殊处理
        //}
        else
        {
            //未定义的类型
            ThrowException(-1, "Property '%s' has unsupported type: '%s'.", 
                pProp->m_name.c_str(), szTypeName);
        }
    }

    //Flags
    pProp->m_nFlags = 0;
	field_attri = node->FirstChildElement("Flags");
	if(field_attri)
	{
		const char* _szFlag = field_attri->GetText();
		if(UpperStrCmp(_szFlag, "BASE"))
		{
			SetBaseFlag(pProp->m_nFlags);
		}
		else if(UpperStrCmp(_szFlag, "BASE_AND_CLIENT"))
		{
			SetBaseFlag(pProp->m_nFlags);
			SetClientFlag(pProp->m_nFlags);
		}
		else if(UpperStrCmp(_szFlag, "CELL"))
		{
			SetCellFlag(pProp->m_nFlags);
		}
		else if(UpperStrCmp(_szFlag, "CELL_AND_CLIENT"))
		{
			SetCellFlag(pProp->m_nFlags);
			SetClientFlag(pProp->m_nFlags);
			pDef->m_bHasCellClient = true;
		}
        else if(UpperStrCmp(_szFlag, "ALL_CLIENTS"))
        {
            SetCellFlag(pProp->m_nFlags);
            SetClientFlag(pProp->m_nFlags);
            SetOtherClientsFlag(pProp->m_nFlags);
            pDef->m_bHasCellClient = true;
        }
        else if(UpperStrCmp(_szFlag, "OTHER_CLIENTS"))
        {
            //注意和all_clients的区别
            SetCellFlag(pProp->m_nFlags);
            //setClientFlag(pProp->m_nFlags);
            SetOtherClientsFlag(pProp->m_nFlags);
            //pDef->m_bHasCellClient = false;
        }
		else
		{
			ThrowException(-1, "unknown properties flag:%s", _szFlag);
		}
	}

	//该字段是否base和cell共有的字段
	field_attri = node->FirstChildElement("BaseAndCell");
	if(field_attri)
	{
		if(UpperStrCmp(field_attri->GetText(), "TRUE"))
		{
			SetCellFlag(pProp->m_nFlags);
			SetBaseFlag(pProp->m_nFlags);
		}
	}

    //该字段是否保存到数据库
    field_attri = node->FirstChildElement("Persistent");
    if(field_attri)
    {
		if(UpperStrCmp(field_attri->GetText(), "TRUE"))
        {
            pProp->m_bSaveDb = true;

			//cell属性不能有存盘标记(除非是cell和base共有的属性)
			if(IsCellFlag(pProp->m_nFlags) && !IsBaseFlag(pProp->m_nFlags))
			{
				ThrowException(-1, "CELL(but Base) properties cant set Persistent to TRUE");
			}
        }
        else
        {
            pProp->m_bSaveDb = false;
        }
    }
    else
    {
        pProp->m_bSaveDb = false;
    }

    //该字段是否有缺省值
    field_attri = node->FirstChildElement("Default");
    if(field_attri)
    {
        pProp->m_defaultValue.assign(field_attri->GetText());
    }
    else
    {
        pProp->m_defaultValue.assign("");
    }

    //该字段是否创建唯一索引
    field_attri = node->FirstChildElement("UniqueIndex");
    if(field_attri)
    {
        if(pDef->m_strUniqueIndex.empty())
        {
            pDef->m_strUniqueIndex.assign(node->Value());
        }
        else
        {
            //多个字段申明了唯一索引
            ThrowException(-1, "At least two properties set unique_index, '%s' vs '%s'", \
                pDef->m_strUniqueIndex.c_str(), node->Value());
        }
    }

    return pProp;
}