示例#1
0
QList<Transaction*> AccountTradeInfo::CreateTransaction(Order const*pOrder,QDateTime const& oTimestamp,size_t nQuantity,double dPrice)
{
    QMutexLocker oLocker(&m_mLock);
    OrderOperator oOperator;
    QList<Transaction*> lTransactions;
    auto iPos = m_lPositions.begin();
    while(iPos != m_lPositions.begin())
    {
        Position *pPosition = *iPos;
        Transaction* pTransaction = oOperator.Close(pPosition,pOrder,oTimestamp,nQuantity,dPrice);
        lTransactions.append(pTransaction);
        if(pPosition->GetQuantity() == 0)
        {
            iPos = m_lPositions.erase(iPos);
            RemovePosition(pPosition);
        }
        else
        {
            break;
        }
    }
    m_lTradeDayTransactions.append(lTransactions);
    UpdateOrder(const_cast<Order*>(pOrder));
    SaveTransaction(lTransactions);
    return lTransactions;
}
示例#2
0
size_t AccountTradeInfo::GetPositionQuantity(Direction eDirection,HedgeFlag eHedgeFlag) const
{
    QMutexLocker oLocker(&m_mLock);
    size_t nQuantity = 0;
    for(auto iPos = m_lPositions.begin() ; iPos != m_lPositions.end() ; iPos++)
    {
        Position *pPosition = *iPos;
        if(pPosition->GetDirection() == eDirection && pPosition->GetHedgeFlag() == eHedgeFlag)
        {
            nQuantity += pPosition->GetQuantity();
        }
    }
    return nQuantity;
}