Exemplo n.º 1
0
static void __stdcall SerializeDeserialize()
{
	// serialize
	const CString sym = "CLZ8";
	const CString ex = "NYMEX";
	TLOrder o;
	o.id = 2;
	o.symbol = sym;
	o.exchange = ex;
	o.date = 20081201;
	o.time = 153100;
	o.price = 0;
	o.size = -100;
	o.side = false;
	// flatten it
	CString m = o.Serialize();

	// convert it back to object
	TLOrder d = TLOrder::Deserialize(m);
	CFIX_ASSERT(o.symbol==d.symbol);
	CFIX_ASSERT(o.price==d.price);
	CFIX_ASSERT(o.size==d.size);
	CFIX_ASSERT(o.side==d.side);
	CFIX_ASSERT(o.exchange==d.exchange);
	CFIX_ASSERT(o.date==d.date);
	CFIX_ASSERT(o.time==d.time);
	CFIX_ASSERT(o.id==d.id);

}
Exemplo n.º 2
0
	void TLServer_IP::SrvGotOrder(TLOrder order)
	{
		if (order.symbol=="") return;
		for (size_t i = 0; i<client.size(); i++)
			if (client[i]!="")
				TLSend(ORDERNOTIFY,order.Serialize(),client[i]);
	}
Exemplo n.º 3
0
void TLServer_WM::SrvGotOrder(TLOrder order)
{
    if (!order.isValid())
        return;
    for (size_t i = 0; i<client.size(); i++)
        if (client[i]!="")
            TLSend(ORDERNOTIFY,order.Serialize(),client[i]);
}
Exemplo n.º 4
0
UINT __cdecl DoOrderResend(LPVOID param)
{
    // we need a queue object
    LS_TLWM* tl = (LS_TLWM*)param;
    // ensure it's present
    if (tl==NULL)
    {
        return OK;
    }

    while (tl->_go)
    {
        if (tl->_resends!=0)
        {
            // process every valid order in queue
            for (uint i = 0; i<tl->resend.size(); i++)
            {
                // get tradelink order
                TLOrder ord = tl->resend[i];
                // skip if invalid
                if (!ord.isValid())
                    continue;
                // mark as invalid
                TLOrder blank;
                tl->resend[i] = blank;
                tl->_resends--;
                // resend it
                tl->SendOrder(ord);
                // notify
                CString tmp;
                tmp.Format("%s Resending order: %s",ord.symbol,ord.Serialize());
                tl->D(tmp);
                // wait briefly
                Sleep(25);
            }
        }
        Sleep(100);
    }
    return OK;
}
Exemplo n.º 5
0
	int TLClient_WM::SendOrder(TLOrder o)
	{
		return TLSend(SENDORDER,o.Serialize(),_him);
	}
Exemplo n.º 6
0
int LS_TLWM::SendOrder(TLOrder o)
{
    if (accounts.size()==0)
        return INVALID_ACCOUNT;
    // if order id is set and not-unique, reject order
    if ((o.id!=0) && (!IdIsUnique(o.id)))
        return DUPLICATE_ORDERID;


    L_Summary* summary = preload(o.symbol);
    L_Account* account = NULL;
    for (uint i = 0; i<accounts.size(); i++)
    {
        if (CString(accounts[i]->L_TraderId())==o.account)
            account = accounts[i];
    }
    if (account==NULL)
        account = accounts[0];


    // do maximum size account check
    if (_hasmaxaccountpospct)
    {
        double totalbp = account->L_BuyingPower();
        L_Position* pos = account->L_FindPosition(o.symbol);
        if (pos)
        {
            double poscost = pos->L_DollarValue();
            double pospcttotal = totalbp==0 ? 1 : poscost/totalbp;
            if (pospcttotal>_maxaccountpospct)
            {
                CString tmp;
                tmp.Format("%s rejecting for position size exceeded: %s",o.symbol,o.Serialize());
                D(tmp);
                return REJECTEDACCOUNTSAFETY;
            }
        }
    }
    if (_hasmaxaccount)
    {
        double bpinuse = account->L_BuyingPowerInUse();
        if (abs(bpinuse)>=_sendordermaxaccount)
        {
            CString tmp;
            tmp.Format("%s rejecting for account BP safety:  %s",o.symbol,o.Serialize());
            D(tmp);
            return REJECTEDACCOUNTSAFETY;
        }
    }
    if (_hasmaxconnectorshares)
    {
        if (_curconnectorshares >= _maxconnectorshares)
        {
            CString tmp;
            tmp.Format("%s rejecting for max api/connector shares:  %s",o.symbol,o.Serialize());
            D(tmp);
            return REJECTEDACCOUNTSAFETY;
        }
    }
    if (_hasmaxpositionsize)
    {
        L_Position* pos = account->L_FindPosition(o.symbol);
        // only run check if we have a position
        if (pos)
        {
            long size = pos->L_Shares();
            if (abs(size)>_maxpositionsize)
            {
                CString tmp;
                tmp.Format("%s rejecting for max position size:  %s",o.symbol,o.Serialize());
                D(tmp);
                return REJECTEDACCOUNTSAFETY;
            }
        }
    }



    CString ex = o.exchange;
    CString ex2 = NULL;
    if (o.exchange.FindOneOf("+")!=-1)
    {
        std::vector<CString> exr;
        gsplit(o.exchange,CString("+"),exr);
        ex = exr[0];
        ex2 = exr[1];
    }
    // check for loading
    if (!summary || !summary->L_IsValid() || !summary->L_IsInit())
    {
        if (!_resendsummarynotloaded)
            return SYMBOL_NOT_LOADED;
        CString tmp;
        tmp.Format("%s Not loaded yet, Queing for resend:  %s",o.symbol,o.Serialize());
        D(tmp);
        resend.push_back(o);
        _resends++;
        return 0;
    }


    //convert the arguments
    char side = o.side ? L_Side::BUY : L_Side::SELL;

    double price = o.isStop() ? o.stop : o.price;
    // get correlation id
    long corid = 0;

    // associate order id and correlation id
    uint coridx = lscorrelationid.size();
    lscorrelationid.push_back(corid);
    tlcorrelationid.push_back(o.id);
    // associate blank ids for orders
    lsorderid1.push_back(0);
    lsorderid2.push_back(0);
    lsorderidfinal.push_back(0);
    // save order
    tlorders.push_back(o);

    if (!_noverb)
    {
        CString tmp;
        tmp.Format("%s received api order tlid: %lld lscorid: %i ord: %s",o.symbol,o.id,corid,o.Serialize());
        v(tmp);
    }

    // get appropriate tif
    long tif = gettif(o);
    long type = gettype(o);




    // prepare to receive the result
    L_Order** orderSent = NULL;
    L_Order** orderSent2 = NULL;
    // send the order
    account->L_SendOrder(
        summary,
        type,
        side,
        abs(o.size),
        price,
        ex,
        tif,
        false,
        abs(o.size),
        0,ex2,&corid);

    lscorrelationid[coridx] = corid;




    // return result
    return 0;

}
Exemplo n.º 7
0
TLOrder LS_TLWM::ProcessOrder(L_Order* order)
{
    TLOrder o;
    long lsid = order->L_ReferenceId();
    // ensure it exists
    if (order)
    {

        // udpate order information
        CTime ct = CTime(order->L_CreateTime());
        o.symbol = CString(order->L_Symbol());
        o.time = (ct.GetHour()*10000)+(ct.GetMinute()*100)+ct.GetSecond();
        o.date = (ct.GetYear()*10000)+(ct.GetMonth()*100)+ct.GetDay();
        o.exchange = CString(order->L_OriginalMarket());
        o.price = order->L_AveragePrice();
        o.side = order->L_TradeSide()=='B';
        o.stop = order->L_SecondaryPrice();
        o.size = (o.side ? 1 : -1) * abs(order->L_ActiveShares());
        o.account = CString(accounts[0]->L_TraderId());
        // try to save this order
        bool isnew = saveOrder(order,0);
        // if it fails, we already have it so get the id
        // if it succeeds, we should be able to get the id anyways
        int64 tlid = fetchOrderId(order);
        o.id = tlid;
        if (!_noverb)
        {
            if (isnew)
            {
                CString tmp;
                tmp.Format("%s new order tlid: %lld lsid: %i ord: %s",o.symbol,o.id,lsid,o.Serialize());
                v(tmp);
            }
            else
            {
                CString tmp;
                tmp.Format("%s processed order tlid: %lld lsid: %i ord: %s",o.symbol,tlid,lsid,o.Serialize());
                v(tmp);
            }
        }
    }
    else
    {
        CString tmp;
        tmp.Format("%i order id not found.",lsid);
        D(tmp);
    }
    return o;
}