get next time

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



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

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; 
}
for getnexttime(), consider (not tried):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
string OrderBook::getNextTime(const string& timestamp) {
	string next_timestamp;

	for (const auto& e : orders)
		if (e.timestamp > timestamp) {
			next_timestamp = e.timestamp;
			break;
		}

	if (next.timestamp.empty() && !orders.empty())
		next_timestamp = orders[0].timestamp;

	return next_timestamp;
}

@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.
Topic archived. No new replies allowed.