Setting Up a Raspberry Pi Trading Bot with TradingBoat

This article guides installing TBOT on Raspberry Pi for TradingBoat, detailing environment setup, IP configuration, and clientID assignment for connecting to TradingBoat's network. It emphasizes correct IP addressing and firewall settings for successful TBOT operation.

Introducing TBOT on Raspberry Pi

 

This article explains the process of installing TBOT on a Raspberry Pi to set up a Trading Robot.

TradingBoat is designed in modular blocks as shown in the block diagram below. These modules can operate independently and on different networks:

  • IB Gateway can run on a different network.
  • Multiple instances of TBOT can run on different networks.
  • Redis can run on different networks, supporting multiple instances.

As per previous articles, you can launch TradingBoat Docker on your computer, or use Terraform automation to launch it on AWS.

Once Redis and IB Gateway are running, you can launch an additional standalone instance of TBOT on Raspberry Pi.

 Installation of TBOT on Raspberry Pi

Follow the installation guide from GitHub: GitHub - PlusGenie/tbot-tradingboat: Converting TradingView PineScript Alerts into Interactive Brokers Orders

 

Configuring TBOT for TradingBoat

After installation, update the following environment variables to reflect the IP addresses of Redis and IB Gateway, and the clientID for TBOT on Raspberry Pi:

  • TBOT_REDIS_HOST=X.X.X.X: Replace X.X.X.X with the IP address of the Redis instance connected to TradingBoat.
  • TBOT_IBKR_IPADDR=X.X.X.X: Replace X.X.X.X with the IP address of your IB Gateway.
  • TBOT_IBKR_CLIENTID=2: This sets the clientID for your TBOT instance to 2.

 Ensure that your network settings, particularly the firewall, are configured correctly. The firewall should allow network connections from the Raspberry Pi to the TradingBoat network for seamless communication.

Upon successful configuration and execution, TBOT will be operational on your Raspberry Pi. For additional information about the clientId and its role in communication with the TWS API, consult the TWS API v9.72+: Execution Class Reference. Remember, the clientId is crucial for routing messages and commands to the correct instance in the TWS API.

clientId:TWS API v9.72+: Execution Class Reference

Install Web Interface on Raspberry Pi

With TBOT running, you can monitor stock transactions related to TBOT on Raspberry Pi. Install the customized TVWB as per the guide on :

GitHub - PlusGenie/tradingview-webhooks-bot: Converting TradingView PineScript Alerts into Interactive Brokers Orders

 

Sending Webhook Messages from TradingView

Use the PineScript library PineTradingbotWebhook PineTradingbotWebhook — Library by AlphaCentauri66367 Set clientId to 2 to differentiate it from other TBOT instances. This ensures messages from Redis are channeled correctly for TBOT on Raspberry Pi.

Example PineScript with clientId=2:

  
    //@version=5
strategy('Hello World, Supertrend', overlay=true)

atrPeriod = input(10, 'ATR Length')
factor = input(3, 'Factor')

import AlphaCentauri66367/PineTradingbotWebhook/7 as tv // TBOT
webhookKey = "WebhookReceived:8c43d5" // TBOT
qty=100  // TBOT

[supertrend, direction] = ta.supertrend(factor, atrPeriod)
plot(direction < 0 ? supertrend : na, "Up direction", color = color.green, style=plot.style_linebr)
plot(direction > 0 ? supertrend : na, "Down direction", color = color.red, style=plot.style_linebr)

if ta.change(supertrend)  > 0
    msg = tv.makeWebhookJson(webhookKey, 'Long#1', 'strategy.entrylong', qty, clientId=2) // TBOT
    strategy.entry('Long#1', strategy.long, alert_message=msg) // TBOT

if ta.change(supertrend) < 0
    msg
     = tv.makeWebhookJson(webhookKey, 'Short#1', 'strategy.entryshort', qty, clientId=2) // TBOT
    strategy.entry('Short#1', strategy.short, alert_message=msg) //TBOT
  

Further details and procedures, I highly recommend referring to the comprehensive Udemy course available here: Link to Udemy Course.

Subscribe to TBOT on TradingBoat

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe