SimpleTakerStrategy
This examples provides a naive taker strategy which places IOC order on fixed time interval
#include <SimpleTakerStrategy.h>
using namespace std;
using namespace aats;
using std::chrono::duration_cast;
using std::chrono::milliseconds;
using std::chrono::system_clock;
void SimpleTakerStrategy::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;
}
SimpleTakerStrategy::~SimpleTakerStrategy(){}
void SimpleTakerStrategy::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){
double qpx = _symbols[_trade_cid]->trade_px;
double qty = 1000.0 / qpx;
send_order("BINANCE", "BTCUSDT", qpx, qty, "sell", "IOC");
_next_fire_time = _current_time + _msecs;
}
}
}
void SimpleTakerStrategy::send_order(std::string exchange, std::string symbol, double price, double size, string side, std::string tif){
LOrder *ord = new LOrder();
ord->exchange = exchange;
ord->symbol = symbol;
ord->order_id = _order_id;
ord->px = price;
ord->qty = size;
ord->side = side;
ord->tif = tif;
place_order(ord);
_order_id += 1;
}
void SimpleTakerStrategy::cancel_order(LOrder* order){
BaseStrategy::cancel_order(order);
}