void TLClient_WM::Subscribe(TLMarketBasket mb) { CString basket = mb.Serialize(); CString m; m.Format("%s+%s",_me,basket); TLSend(REGISTERSTOCK,m,_him); }
static void __stdcall Create() { // some stocks char* list[] = { "LVS", "WAG","GM","MHS" }; const uint count = 4; vector<CString> secs(list,list+count); // initial basket with our stocks TLMarketBasket mb; mb.Add(secs); // test to make sure our basket got them all bool match = true; for (uint i = 0; i<count; i++) { match = mb[i].sym.CompareNoCase(list[i])==0; if (!match) break; } CFIX_ASSERT(match); }
static void __stdcall SerializeDeserialize() { // some stocks char* list[] = { "LVS", "WAG","GM","MHS" }; vector<CString> secs(list,list+4); // initial basket with our stocks TLMarketBasket mb; mb.Add(secs); // serialize it CString msg = mb.Serialize(); // undo it TLMarketBasket mb2 = TLMarketBasket::Deserialize(msg); // test to make sure our basket got them all bool match = true; for (uint i = 0; i<mb2.Count(); i++) { match &= mb2[i].sym == secs[i]; } CFIX_ASSERT(match); }
void TLMarketBasket::Add(TLMarketBasket basket) { for (unsigned int i = 0; i<basket.Count(); i++) Add(basket[i]); }
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); }