I have tried to move the next time frame by Bot (automat) I have implemented the getNextTime on Orderbook class but I dont understand why it doesnt goes to next time window, it is back to the same as before
OrderBook.cpp place bids and asks
[code]
string OrderBook::getEarliestTime(){
//*******************************
// how to find assume that orders are sorted and return first one
cout<< orders[0].timestamp<< endl;
return orders[0].timestamp;
}
string OrderBook::getNextTime(string timestamp){
// iterate over the orderbooks from the begining as soon as i see one that is greater in time than that one, so i know that's the next one that comes after that
//************************************
//*****************************
string next_timestamp = "";
for(OrderBookEntry& e :orders){
if(e.timestamp > timestamp){
next_timestamp = e.timestamp;
break;
}
}
// if there is no next timestamp ? wrapp the simulation around back to the begining again, keep looping the simulation ///******************** find solution here
if (next_timestamp == ""){
// basically wrap it back around, get to end, wrap it back around
next_timestamp = orders[0].timestamp;
}
return next_timestamp;
}
MerkelBot.cpp MainBot
void MerkelBot::init(){
while(1){
this_thread::sleep_for(chrono::milliseconds(2000));
cout<< "Is MerkelBot created"<< endl;
int input;
// set current time in init
currentTime = orderBook.getEarliestTime();
cout<< "currentTime "<< currentTime << endl;
BotMarketstats();
cout<< "BotMarketstats called "<< endl;
goingToNextTimeFrame();
cout<< "NextTimeFrameBot called "<< endl;
}
}
void MerkelBot::BotMarketstats(){
// print known of list of products in markets
// // *************** effient for lopp
//OrderBook.InitialOrders(orders);
for(string const& p : orderBook.getKnownproducts()){
cout << "Product: " << p << endl;
// how many there are of that product- pull up orderbookentry using new function that
// match ask and product we are after print of the message
vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookType::ask,
p, currentTime);
//vector<OrderBookEntry> entries1 = orderBook.getOrders(OrderBookType::ask,
//p, nextTime);
cout << "Asks seen: " << entries.size() << endl;
cout << "Max ask: " << OrderBook::getHighPrice(entries) << endl;
cout << "Min ask: " << OrderBook::getLowPrice(entries) << endl;
}
}
void MerkelBot::goingToNextTimeFrame(){
cout << "Going to next time frame" << endl;
/////////****************** remove for if possible check it
for (string p : orderBook.getKnownproducts()){
cout << "matching " << p << std::endl;
//next time step, tell it to do a match one product for now, call orderBook.Match- get result of that which is array or vector create vector then itreate over sales for loop
vector<OrderBookEntry> sales = orderBook.matchAskToBids("ETH/BTC", currentTime);
cout << "Sales: " << sales.size() << endl;
// itreat over sale and then comeback
for(OrderBookEntry& sale : sales){
cout << "Sale price: " << sale.price << " amount " << sale.amount << endl;
if(sale.username == "simuser"){
// update wallet
wallet.processSale(sale);
}
}
}
// itreat next time frame, passing current time that the simulation is stuck on, itreate over all of its orders find next time and return it
currentTime = orderBook.getNextTime(currentTime);
cout<<"getNextTime"<< currentTime<<endl;
}
@seeplus thanks. How to move to the next time frame automat ? it doesnt goes to next time window, I used getNextTime function to implement moving through time in the simulation, but it doesnt goes automatically and I can see there is current time and next time in window in console log but i want to do it automatically. I need a help.