nautechsystems / nautilus_trader

A high-performance algorithmic trading platform and event-driven backtester
https://nautilustrader.io
GNU Lesser General Public License v3.0
2.12k stars 479 forks source link

Unclean exit when running TradingNode in async main function #1004

Closed limx0 closed 1 year ago

limx0 commented 1 year ago

Bug Report

We currently don't have a clean, working solution for running nautilus inside an async main function (like examples/live/betfair.py). Ideally users should be able to do this because they may need to make some async things (such as requests to get instruments before defining strategies) before starting a TradingNode.

Expected Behavior

TradingNode should exit cleanly when used within an async function.

Actual Behavior

TradingNode either exits before full cleanup has occurred or hangs indefinitely.

Steps to Reproduce the Problem

  1. Run examples/live/betfair.py
cjdsellers commented 1 year ago

Now improved from 373fa29d23ed50b6f3be9db85d7703a3d7b52e69.

The TradingNode exposes the following methods:

So the coroutine versions make the node easier to call within an async context.