Issue with order generation with realtime aggregate database having 1 min bars

I am using realtime aggregate db with bar_size=1min, sometimes I when a strategy tries to create an order, I see the error:

MoonshotError: No 14:21:00 data found in prices Dataframe for signal date 2023-10-29, is the underlying data up-to date (max time for 2023-10-29 is 13:07:00)

I suspect this happens because when the last time minute data was collected, the minute moved up 1 by the time an attempt to created an order was made.

What do you recommend to do in such a case?

The error message says the max time is 13:07 while it's expecting 14:21. That's a big difference so I don't think it's just being one minute out of sync. Are you continuously collecting minute data in the background while running the strategy? How many stocks are in your universe and are they liquid? If you can share the commands you're running on your crontab for real-time data collection and moonshot as well as your real-time tick and aggregate db configs, I should be able to help more.

We Are continuously collecting minute data in the background while running the strategy. There is only security in our universe. And follwing is the error that we are getting

msg: no 14:10:00 data found in prices DataFrame for signal date 2023-12-05, is the
underlying data up-to-date? (max time for 2023-12-05 is 14:09:00)
status: error

Real Time Db config:
{'universes': ['ibkr-fx-eurusd-tick'],
'vendor': 'ibkr',
'fields': ['BidPrice', 'AskPrice']}

aggregate db config

{'tick_db_code': 'ibkr-fx-eurusd-tick',
'bar_size': '1m',
'fields': ['AskPriceClose', 'BidPriceClose]
}

For collecting real time data we are executing the following code we are not doing it via crontab.

from quantrocket.realtime import collect_market_data
collect_market_data(codes="ibkr-fx-eurusd-tick", 
                    sids=["FXEURUSD"], 
                    universes=["ibkr-fx-eurusd-tick"], until="2h")

How are you running the Moonshot strategy? Is that on the crontab? This may be a race condition where the Moonshot strategy is running faster than the aggregate db is being updated with data for the new minute. For example, maybe at 14:10 the Moonshot strategy runs but it takes a few seconds for the tick and/or aggregate db to populate with 14:10 data so Moonshot only sees 14:09 data. IBKR only sends BidPrice and AskPrice when they change, so even though EURUSD is very liquid, perhaps the bid and ask are stable at times so no ticks arrive for a few seconds.

The easiest fix might be to try putting a sleep before running Moonshot. For example:

* 10-15 * * mon-fri sleep 5; quantrocket moonshot trade 'my-strategy'  

You can also query the tick and aggregate db directly after this happens to make sure data is there and is flowing. But I bet it will be and that it's the race condition.