跳转至

SimpleDataPrinterStrategy

This example show a naive market data printer strategy: print out quote and tick data on the given time frequency

#include <SimpleDataPrinterStrategy.h>

using namespace std;
using namespace aats;
using std::chrono::duration_cast;
using std::chrono::milliseconds;
using std::chrono::system_clock;


void SimpleDataPrinterStrategy::init(int msecs){
    _msecs = msecs;
    _start_time = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
    _next_fire_time = _start_time + _msecs;
    cout << "init derivedStrategy" << endl;
}

SimpleDataPrinterStrategy::~SimpleDataPrinterStrategy(){}

void SimpleDataPrinterStrategy::on_notify(NotifyType type){

    if(type == NT_TICK){
        _current_time = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
        if(_current_time>_next_fire_time){
            std::cout << " symbol " << _symbols[_trade_cid]->sym 
            << " tradepx " << _symbols[_trade_cid]->trade_px 
            << " tradeqty " << _symbols[_trade_cid]->trade_qty 
            << " bidpx " << _symbols[_trade_cid]->bid_px 
            << " bidqty " << _symbols[_trade_cid]->bid_qty 
            << " askpx " << _symbols[_trade_cid]->ask_px
            << " askqty " << _symbols[_trade_cid]->ask_qty << endl;  
            _next_fire_time = _current_time + _msecs;
        }
    }
}