Example #1
0
UINT __cdecl DoReadTickThread(LPVOID param)
{
    // we need a queue object
    TLServer_WM* tl = (TLServer_WM*)param;
    // ensure it's present
    if (tl==NULL)
    {
        return OK;
    }

    // process until quick req
    while (tl->_go)
    {
        // process ticks in queue
        while (tl->_go && (tl->_readticks < tl->_tickcache.size()))
        {
            // if we're done reading, quit trying
            if ((tl->_readticks>=tl->_writeticks) && !tl->_tickflip)
                break;
            // read next tick from cache
            TLTick k;
            k = tl->_tickcache[tl->_readticks++];
            // send it
            tl->SrvGotTick(k);
            // if we hit end of cache buffer, ring back around to start
            if (tl->_readticks>=tl->_tickcache.size())
            {
                tl->_readticks = 0;
                tl->_tickflip = false;
            }

            // this is from asyncresponse, but may not be same
            // functions because it doesn't appear to behave as nicely
            //ResetEvent(tl->_tickswaiting);
            //WaitForSingleObject(tl->_tickswaiting,INFINITE);
        }
        Sleep(100);
    }
    // mark thread as terminating
    tl->_startthread = false;
    // end thread
    return OK;
}
Example #2
0
static void __stdcall Basics()
{
	// we need this line here in order to create windows from the cfix 
	// console application that runs our tests
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
		return;

	// setup our objects
	TLServer_WM s;
	s.Start();
	TestClient c;
	TestClient c2;
	char* sym = "TST";
	int size = 200;
	double price = 100;
	TLMarketBasket mb;
	mb.Add(sym);
	c.Subscribe(mb);

	// initial tests
	CFIX_ASSERT(c.ticks+c.fills+c.orders==0);

	// Tick test
	TLTick k;
	symcp(k.sym,sym);
	//k.sym = sym;
	k.trade = price;
	k.size = size;
	s.SrvGotTick(k); // send tick
	CFIX_ASSERT(c.ticks==1); 
	// test output
	// cout<<strcat(c.lasttick.sym,k.sym)<<endl;
	CFIX_ASSERT(isstrsame(c.lasttick.sym,k.sym));
	CFIX_ASSERT(c.lasttick.trade==k.trade);
	// make sure ticks were not copied to other clients
	CFIX_ASSERT(c.ticks!=c2.ticks);

	// Fill test
	TLTrade f;
	f.symbol = sym;
	f.xprice = price;
	f.xsize = size;
	f.xdate = 20081220;
	f.xtime = 1556;
	f.side = true;
	s.SrvGotFill(f);
	CFIX_ASSERT(c.fills==1);
	CFIX_ASSERT(c.lastfill.symbol==f.symbol);
	CFIX_ASSERT(c.lastfill.xprice==f.xprice);
	// make sure fills were copiedto other clients
	CFIX_ASSERT(c.fills==c2.fills);

	// Order test
	TLOrder o;
	o.symbol = sym;
	o.price = price;
	o.size = size;
	s.SrvGotOrder(o);
	CFIX_ASSERT(c.orders==1);
	CFIX_ASSERT(c.lastorder.symbol==o.symbol);
	CFIX_ASSERT(c.lastorder.price==o.price);
	// make sure orders were copied to other clients
	CFIX_ASSERT(c.orders==c2.orders);

	// performance test ticks

	// reset ticks
	c.ticks = 0;
	// get random ticks
	const int MAXTICKS = 1000;
	vector<TLTick> ticks;
	for (int i = 0; i<MAXTICKS; i++)
	{
		TLTick k;
		symcp(k.sym,sym);
		k.size = size;
		k.trade = rand();
		ticks.push_back(k);
	}
	// start timer
	unsigned long start = GetTickCount();
	// send ticks to clients
	for (unsigned int i =0; i<ticks.size(); i++)
		s.SrvGotTick(ticks[i]);
	// stop timer
	unsigned long stop = GetTickCount();
	// elapased time
	int elap = (stop - start);
	// ticks per second
	int rate = (MAXTICKS / elap)*1000;
	CFIX_LOG(L"Performance elap (ms): %i",elap);
	CFIX_LOG(L"Performance (ticks/sec): %i",rate);
	// make sure it took reasonable time
	CFIX_ASSERT(elap<200);


	
}