Sample python trading application utilizing the Ironbeam Futures API V2
This trading application was built to manage many of the repetitive parts of building a python trading system utilizing the Ironbeam API V2. Namely, auth.py authenticates with server to generate the token needed to run all other parts of the application. Constants.py is where we store symbols, API URL's, and environment files for secretly storing credentials. This system utilizes a .env file to store credentials for both demo and live accounts. Most importantly, our switch between live and demo environments is inside the .env - flag in "False" mode is utilizes the demo environment, flag in "True" mode will take the system live. You can switch between these environments by opening the .env file in a terminal in the app folder by entering nano .env From here, enter credentials and switch the flag as desired, ctrl o, enter, to save ctrl x to exit.
Next, the streamID_handler is built to first obtain a streamID for the websocket_handler, and should the connection to the websocket be broken, it will automatically refresh the streamID, store it in self, and allow the new websocket connection to be established, seamlessly. The websocket connection as designed receives historical and live tick data and stores it to a dataframe. The data_aggregator then runs over our raw data and can create any desired time bars your trade app may require. These bars are readable into the indicators.py tab where you should program your desired indicators. Trading_logic is where you should enter your trading strategy based off your indicators. You may calls the methods in the order_entry.py module from trading strategy to manage entry, exit, stop loss, trades and modifications. Note that you should update the websocket handler to request data relavent to your purposes. All symbols are called from constants.py, so try to use this centralized hardcoding from all other modules. You will need to include your own trading logic, data type requests, and personal credentials (which can only be provided via contacting Ironbeam Support). Be sure to install all requirements. This app was built in Anaconda on Linux (Ubuntu) utilizing the Spyder IDE. If you enjoy using Anaconda this app should work very well with it -- I am considering adding it as a package to their repo in the future.
Finally, several modules have been setup to be tested independently of the app in entirety. After you have cloned this repo, created a local environment, stored your personal credentials in the .env file and are ready to test connectivity, navigate to the trading_app parent directory in the command line and simply run pytest tests/ If your app credentials are valid all test should pass. Note - no trading logic is included in the test folder. This is simply a way to manage auth/contsants/streamID/websocketConnection and data aggregation are working properly.
This app is still in development but should satisfy the basic suggested functionality. It is intended as a jumping off point for others to not need to rewrite and help you interate your ideas faster. Keep in mind, I'm not a genius and I do make mistakes. Please feel free to fork and extend this code as you wish. I'll likely enjoy any improvements or suggestions you make, so please go for it! Hope this helps the trading community get moving faster with Ironbeam Futures. Feel free to reach out and pay it forward when you can!
Cheers, DP