예제 #1
0
/**
**  Cancel the training of an unit.
**
**  @param unit  pointer to unit.
**  @param slot  slot number to cancel.
**  @param type  Unit-type to cancel.
*/
void CommandCancelTraining(CUnit *unit, int slot, const CUnitType *type)
{
	DebugPrint("Cancel %d type: %s\n" _C_ slot _C_
		type ? type->Ident.c_str() : "-any-");

	ClearSavedAction(unit);

	//
	// Check if unit is still training 'slot'? (NETWORK!)
	//

	if (slot == -1) {
		// Cancel All training
		while (unit->Orders[0]->Action == UnitActionTrain) {
			unit->Player->AddCostsFactor(
				unit->Orders[0]->Type->Stats[unit->Player->Index].Costs,
				CancelTrainingCostsFactor);
			RemoveOrder(unit, 0);
		}
		unit->Data.Train.Ticks = 0;
		if (unit->Player == ThisPlayer && unit->Selected) {
			SelectedUnitChanged();
		}
	} else if (unit->OrderCount <= slot) {
		// Order has moved
		return;
	} else if (unit->Orders[slot]->Action != UnitActionTrain) {
		// Order has moved, we are not training
		return;
	} else if (unit->Orders[slot]->Action == UnitActionTrain) {
		// Still training this order, same unit?
		if (type && unit->Orders[slot]->Type != type) {
			// Different unit being trained
			return;
		}

		DebugPrint("Cancel training\n");

		unit->Player->AddCostsFactor(
			unit->Orders[slot]->Type->Stats[unit->Player->Index].Costs,
			CancelTrainingCostsFactor);

	
		if (!slot) { // Canceled in work slot
			unit->Data.Train.Ticks = 0;
		}
		RemoveOrder(unit, slot);

		//
		// Update interface.
		//
		if (unit->Player == ThisPlayer && unit->Selected) {
			SelectedUnitChanged();
		}
	}
}
예제 #2
0
파일: command.cpp 프로젝트: meiavy/Wyrmgus
/**
**  Cancel Building researching.
**
**  @param unit  Pointer to unit.
*/
void CommandCancelResearch(CUnit &unit)
{
	// Check if unit is still researching? (NETWORK!)
	if (unit.CurrentAction() == UnitActionResearch) {
		unit.CurrentOrder()->Cancel(unit);
		RemoveOrder(unit, 0);
		if (!Selected.empty()) {
			SelectedUnitChanged();
		}
	}
	ClearSavedAction(unit);
}
예제 #3
0
/**
**  Cancel building upgrading to.
**
**  @param unit  pointer to unit.
*/
void CommandCancelUpgradeTo(CUnit &unit)
{
	// Check if unit is still upgrading? (NETWORK!)
	if (unit.CurrentAction() == UnitActionUpgradeTo) {
		unit.CurrentOrder()->Cancel(unit);
		RemoveOrder(unit, 0);
		if (Selected) {
			SelectedUnitChanged();
		}
	}
	ClearSavedAction(unit);
}
예제 #4
0
파일: command.cpp 프로젝트: meiavy/Wyrmgus
/**
**  Cancel the training of an unit.
**
**  @param unit  pointer to unit.
**  @param slot  slot number to cancel.
**  @param type  Unit-type to cancel.
*/
void CommandCancelTraining(CUnit &unit, int slot, const CUnitType *type)
{
	DebugPrint("Cancel %d type: %s\n" _C_ slot _C_
			   type ? type->Ident.c_str() : "-any-");

	ClearSavedAction(unit);

	// Check if unit is still training 'slot'? (NETWORK!)
	if (slot == -1) {
		// Cancel All training
		while (unit.CurrentAction() == UnitActionTrain) {
			unit.CurrentOrder()->Cancel(unit);
			RemoveOrder(unit, 0);
		}
		if (unit.Player == ThisPlayer && unit.Selected) {
			SelectedUnitChanged();
		}
	} else if (unit.Orders.size() <= static_cast<size_t>(slot)) {
		// Order has moved
		return;
	} else if (unit.Orders[slot]->Action != UnitActionTrain) {
		// Order has moved, we are not training
		return;
	} else if (unit.Orders[slot]->Action == UnitActionTrain) {
		COrder_Train &order = *static_cast<COrder_Train *>(unit.Orders[slot]);
		// Still training this order, same unit?
		if (type && &order.GetUnitType() != type) {
			// Different unit being trained
			return;
		}
		order.Cancel(unit);
		RemoveOrder(unit, slot);

		// Update interface.
		if (unit.Player == ThisPlayer && unit.Selected) {
			SelectedUnitChanged();
		}
	}
}
예제 #5
0
void CStrategyGrid::OnOrderReturn(int orderref,int ordersystemid,char orderstatus,char bs,char kp,char * ins) 
{
	//如果有撤单需要删除对应的报单引用
	if(isExistRef(orderref,bs,kp,ins))
	{
		if(orderstatus=='5' || orderstatus=='6')
		{
			CString s;
			s.Format("[撤单回报] 删除对应指令,报单引用:%d",orderref);
			m_orderinfo.erase(orderref);
			RemoveOrder(orderref);
			AddLog(s.GetBuffer(0));
		}
	}

}
예제 #6
0
/*
处理成交回报
买入方式:
开仓成交-------------立即挂止赢单
平仓成交-------------立即挂开仓单
*/
void CStrategyGrid::OnTradeReturn(char * ins,char * time,int orderref,int localorderid,char direction,char offsetflag,int vol,double price)
{
	//判断是否属于本策略的报单
	bool bt = false;

	for(int i = 0;i<m_listOrderRef.GetSize();i++)
	{
		if( orderref == m_listOrderRef[i] )
		{
			bt = true;
			break;
		}
	}

	bt = isExistRef(orderref,direction,offsetflag,ins);

	char msg[256];

	if( bt )
	{
		if( offsetflag == '0' )//开仓
		{
			//if( m_TradeDirection == 0 )
			if(direction == '0')
			{		
				
				sprintf_s(msg,256,"[回报]开仓成交 成交价格%.3f,数量%d,报单引用:%d",price,vol,orderref);

				AddLog(msg);

				if(m_kp==0)
					m_nTradeCountSum += vol;

				double newprice = m_orderinfo[orderref].orderprice + m_J1;

				//需要累加成交数量
				m_orderinfo[orderref].tradecount += vol;
				//已经全部成交,删除
				if(m_orderinfo[orderref].ordercount==m_orderinfo[orderref].tradecount)
				{
					RemoveOrder(orderref);	
					m_orderinfo.erase(orderref);
					sprintf_s(msg,256,"全部成交,删除列表引用:%d,",orderref);
					AddLog(msg);
				}


				//这里判断先平后开的最大成交数量
				if( m_nTradeCountSum  >= m_nMaxTradeCount && m_kp==1)
				{
					sprintf_s(msg,256,"成交数量 %d 超过门限%d,不再下单 ",m_nTradeCountSum,m_nMaxTradeCount);

					AddLog(msg);

					return;
				}

				if(m_bRun)
				{
					//开仓回报回来肯定是平今
					int closeorderref = CloseSale(m_strInstrument.GetBuffer(0),vol,newprice,m_fundAccount.GetBuffer(0),CLOSEFLAG_CLOSE_TODAY);

					COrderInfo *order = new COrderInfo();
					strcpy(order->szInstrument,m_strInstrument.GetBuffer(0));
					order->ref = closeorderref;
					order->ordercount = vol;
					order->orderprice = newprice;
					order->bs = '1';
					order->kp = '3';
					order->tradecount = 0;
					m_orderinfo[closeorderref] = *order;
					delete order;
				

					//记录开仓的仓位
					TPosition * pos = new TPosition;

					m_arPosition.Add(pos);

					strcpy_s(pos->ins,ins);

					pos->count = vol;

					pos->price  = price;

					pos->direction = direction;

					m_listOrderRef.Add(closeorderref);

					sprintf_s(msg,256,"止盈单生成 价格%.3f 数量%d orderref=%d ",newprice,vol,closeorderref);

					AddLog(msg);
				}

			}
			else
			{
				sprintf_s(msg,256,"[回报]开仓成交 成交价格%.3f,数量%d,报单引用:%d",price,vol,orderref);

				AddLog(msg);

				if(m_kp==0)
					m_nTradeCountSum += vol;

				double newprice = m_orderinfo[orderref].orderprice - m_J1;

				//需要累加成交数量
				m_orderinfo[orderref].tradecount += vol;
				//已经全部成交,删除
				if(m_orderinfo[orderref].ordercount==m_orderinfo[orderref].tradecount)
				{
					RemoveOrder(orderref);	
					m_orderinfo.erase(orderref);
					sprintf_s(msg,256,"全部成交,删除列表引用:%d,",orderref);
					AddLog(msg);
				}


				//这里判断初始平仓的最大成交数量
				if( m_nTradeCountSum  >= m_nMaxTradeCount && m_kp==1)
				{
					sprintf_s(msg,256,"成交数量 %d 超过门限%d,不再下单 ",m_nTradeCountSum,m_nMaxTradeCount);

					AddLog(msg);

					return;
				}

				if(m_bRun)
				{
					int closeorderref = CloseBuy(m_strInstrument.GetBuffer(0),vol,newprice,m_fundAccount.GetBuffer(0),CLOSEFLAG_CLOSE_TODAY);

					COrderInfo *order = new COrderInfo();
					strcpy(order->szInstrument,m_strInstrument.GetBuffer(0));
					order->ref = closeorderref;
					order->ordercount = vol;
					order->orderprice = newprice;
					order->bs = '0';
					order->kp = '3';
					order->tradecount = 0;
					m_orderinfo[closeorderref] = *order;
					delete order;

					//记录开仓的仓位
					TPosition * pos = new TPosition;

					m_arPosition.Add(pos);

					strcpy_s(pos->ins,ins);

					pos->count = vol;

					pos->price  = price;

					pos->direction = direction;
				
					m_listOrderRef.Add(closeorderref);

					sprintf_s(msg,256,"止盈单生成 价格%.3f 数量%d orderref=%d ",newprice,vol,closeorderref);

					AddLog(msg);
				}

			}

		}
		else//平仓
		{
			CalCloseProfit(direction,price,vol);

			//if( m_TradeDirection == 0 )
			if(direction == '1')
			{
				sprintf_s(msg,256,"[回报]平仓成交 成交价格%.3f,数量%d,报单引用:%d",price,vol,orderref);

				AddLog(msg);

				if(m_kp==1)
					m_nTradeCountSum += vol;

				double newprice = m_orderinfo[orderref].orderprice - m_J1;

				//需要累加成交数量
				m_orderinfo[orderref].tradecount += vol;
				//已经全部成交,删除
				if(m_orderinfo[orderref].ordercount==m_orderinfo[orderref].tradecount)
				{
					RemoveOrder(orderref);
					m_orderinfo.erase(orderref);
					sprintf_s(msg,256,"全部成交,删除列表引用:%d,",orderref);
					AddLog(msg);
				}

				//这里判断初始开仓的最大成交数量
				if( m_nTradeCountSum  >= m_nMaxTradeCount && m_kp==0)
				{
					sprintf_s(msg,256,"成交数量 %d 超过门限%d,不再下单 ",m_nTradeCountSum,m_nMaxTradeCount);

					AddLog(msg);

					return;
				}

				if( m_bRun )
				{
					int orderref = OpenBuy(m_strInstrument.GetBuffer(0),vol,newprice,m_fundAccount.GetBuffer(0));

					m_listOrderRef.Add(orderref);

					COrderInfo *order = new COrderInfo();
					strcpy(order->szInstrument,m_strInstrument.GetBuffer(0));
					order->ref = orderref;
					order->ordercount = vol;
					order->orderprice = newprice;
					order->bs = '0';
					order->kp = '0';
					order->tradecount = 0;
					m_orderinfo[orderref] = *order;
					delete order;


					sprintf_s(msg,256,"开仓单生成 价格%.2f 数量%d orderref=%d ",newprice,vol,orderref);

					AddLog(msg);
				}


			}
			else
			{
				sprintf_s(msg,256,"[回报]平仓成交 成交价格%.2f,数量%d,报单引用:%d",price,vol,orderref);

				AddLog(msg);

				if(m_kp==1)
					m_nTradeCountSum += vol;

				double newprice = m_orderinfo[orderref].orderprice + m_J1;

				//需要累加成交数量
				m_orderinfo[orderref].tradecount += vol;
				//已经全部成交,删除
				if(m_orderinfo[orderref].ordercount==m_orderinfo[orderref].tradecount)
				{
					RemoveOrder(orderref);
					m_orderinfo.erase(orderref);
					sprintf_s(msg,256,"全部成交,删除列表引用:%d,",orderref);
					AddLog(msg);
				}

				//这里判断初始开仓的最大成交数量
				if( m_nTradeCountSum  >= m_nMaxTradeCount && m_kp==0)
				{
					sprintf_s(msg,256,"成交数量 %d 超过门限%d,不再下单 ",m_nTradeCountSum,m_nMaxTradeCount);

					AddLog(msg);

					return;
				}

				if( m_bRun )
				{
					int orderref = OpenSale(m_strInstrument.GetBuffer(0),vol,newprice,m_fundAccount.GetBuffer(0));

					m_listOrderRef.Add(orderref);

					COrderInfo *order = new COrderInfo();
					strcpy(order->szInstrument,m_strInstrument.GetBuffer(0));
					order->ref = orderref;
					order->ordercount = vol;
					order->orderprice = newprice;
					order->bs = '1';
					order->kp = '0';
					order->tradecount = 0;
					m_orderinfo[orderref] = *order;
					delete order;

					sprintf_s(msg,256,"开仓单生成 价格%.3f 数量%d orderref=%d ",newprice,vol,orderref);

					AddLog(msg);
				}

			}
		}
	}
}