Skip to content

market data problems #80

@Diqingling

Description

@Diqingling

I tried to use the following code to subscribe to the latest market data each time the 5-min MGC K-bar updates:

class Strategy:
    def __init__(self, trading_suite: TradingSuite, symbol: str):
        self.suite = trading_suite
        self.data_manager = trading_suite[symbol].data
    
    async def _on_new_bar(self, event: Any):
        await self._calculate_and_trade()
    
     async def _calculate_and_trade_macd(self):
        current_data = await self.data_manager.get_data("5min")
        print(current_data)

async def main():
    suite = await TradingSuite.create(
    "MGC",
    timeframes=["5min"],
    initial_days=3,
    )
    strategy = Strategy(suite, "MGC")

if __name__ == "__main__":
    asyncio.run(main())

but it seems that every piece of K-bar data obtained after the program starts executing is inaccurate(circled in the picture), while the data before the program executing is accurate:

Image Image

Is my use of event mechanism incorrect? Is there any way to solve it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions