Coder Social home page Coder Social logo

plusgenie / tbot-tradingboat Goto Github PK

View Code? Open in Web Editor NEW
36.0 8.0 8.0 100 KB

Converting TradingView PineScript Alerts into Interactive Brokers Orders

Home Page: https://tbot.plusgenie.com

License: Other

Python 98.57% Shell 1.43%
ib-insync interactive-brokers-api tradingview pinescript

tbot-tradingboat's Introduction

tbot-tradingboat

An Overview of TBOT: Purpose and Architecture

The Purpose of TBOT

The purpose of TBOT (TradingBoat) is to serve as a trading robot application that integrates with TradingView's strategy or indicator tools and Interactive Brokers' trading platform. TBOT acts as the control center within the broader TradingBoat platform, decoding alert messages received from TradingView and placing corresponding orders with Interactive Brokers.

Here are the key aspects of TBOT's purpose and functionality:

  • Integration with TradingView: TBOT receives alert messages containing trading strategies or indicators from TradingView. These messages are sent via Redis Pub/Sub or Redis Stream, and TBOT decodes them in real-time.

  • Interactive Brokers integration: TBOT uses the ib_insync API to interact with Interactive Brokers' trading platform. It establishes a connection with Interactive Brokers to place orders based on the decoded alert messages.

  • Order placement and tracking: TBOT validates and places orders with Interactive Brokers based on the decoded alert messages. It supports various order types such as market orders, stop orders, limit orders, stop-limit orders, bracket orders, and attached orders. TBOT also tracks the status of placed orders and provides monitoring and management capabilities.

  • Event handling and database management: TBOT utilizes the event handling functionality of ib_insync to track order status updates and handle errors reported by Interactive Brokers. It uses a database (e.g., SQLite3) to store and manage information related to alerts, orders, and errors, allowing for effective order tracking and error handling.

Overall, TBOT enhances the capabilities of Interactive Brokers by integrating with TradingView and providing back-testing and forward-testing functionalities. It enables traders to develop and execute trading strategies based on TradingView's tools while leveraging the execution capabilities of Interactive Brokers.

The Architecture of TBOT

TBOT is built using a combination of the Subscriber of the Pub/Sub pattern and the Observer pattern. It uses the Subscriber to receive messages from a Redis Stream or Pub/Sub and the Observer to deliver messages to Interactive Brokers, message applications, and the watchdog. TBOT is designed to be a flexible and extensible system that can be customized to meet the needs of various trading strategies and workflows. The architecture of TBOT enables it to be easily integrated with other systems and services, making it a powerful tool for automating trading processes.

The-Architecture-of-TBOT

TBOT on TradingBoat

TradingBoat is a platform that includes Nginx/Ngrok, Flask, Redis, TBOT, and IB Gateway.

TBOT serves as the message decoder and order placement tool, and is the brain of TradingBoat. We can refer to it as TBOT on TradingBoat.

TBOT-on-TradingBoat

If you install TradingBoat using Docker from https://github.com/PlusGenie/ib-gateway-docker, the TBOT application will be automatically installed within Docker containers.

This page provides instructions for standalone installation of the TBOT application.

If you are new to the TBOT application, we recommend considering the Docker installation from https://github.com/PlusGenie/ib-gateway-docker to gain an overall understanding.

Preparing for Installation of TBOT Application

To begin, follow the steps below to download, install, set up environment variables, and run the TBOT application.

Set up the Environment

Start by installing Python +3.9, assuming you are using Ubuntu 22.04.

apt-get install -y python3.9 python3.9-venv python3.9-dev python3.9-distutils python3-pip

It is recommended to install the libtmux and loguru libraries globally if you plan to use tbottmux.

pip install libtmux loguru

Create a Non-Root User

Create a non-root user with a home directory using the following command:

useradd -m tbot

Downloading and Setting Up TBOT Application

Create a Python Virtual Environment

Create the necessary directory structure and clone the TBOT repository:

mkdir -p /home/tbot/develop/github
git clone https://github.com/PlusGenie/tbot-tradingboat.git

Navigate to the TBOT directory and set up a Python virtual environment:

cd /home/tbot/develop/github/tbot-tradingboat
python3 -m venv .venv
source .venv/bin/activate

Install Dependencies

pip install -r requirements.txt

Install Dependencies

Install TBOT as an editable package using the following command:

pip install -e .

Configuring the TBOT Application

To configure the default environment variables for TBOT, copy the example dotenv file:

tbot_tradingboat_environment

cp src/tbot_tradingboat/utils/examples/dotenv ~/.env

Open the .env file and update the necessary environment variables. For example, you may need to update TBOT_IBKR_PORT and TBOT_IBKR_IPADDR based on your setup.

For more details, please refer to the chapter How to Use a DotEnv File to Control TradingBoat

Running the TBOT Application

To start the TBOT application, use the following command:

python src/tbot_tradingboat/main.py

Conclusion

By following these steps, you should now have the TBOT application installed and running. Feel free to explore and configure additional features based on your requirements. For more details on utilizing a DotEnv file to control TradingBoat, please refer to the corresponding chapter.

TBOT Warning: For Educational Purposes Only

All software provided here is intended for educational purposes only. Please be aware that any financial trading involves inherent risks and may result in financial losses. This is for educational purposes only. We strongly advise testing it solely with an Interactive Brokers Paper Account.

Reference


Udemy

tbot-tradingboat's People

Contributors

plusgenie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tbot-tradingboat's Issues

Question: Weekly IBKR 2FA Log In?

Hello again.

I see that many other users/developers have this unsolvable challenge that IBKR logs users out once every week, requiring a full log in with 2FA (on mobile phone).

Has this project found a solution to that? Or is it also a shared limitation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.