# Interactive Brokers

## Video tutorial :

{% embed url="<https://youtu.be/LvJ0OPbL2jM>" %}

## Text tutorial :&#x20;

3 steps:

* Setup Ngrok
* Setup TraderWorkstation
* Setup Swiss33

{% hint style="info" %}
Make sure to have a working Interactive Brokers account :  <https://www.interactivebrokers.com/>

This tutorial works for both MacOS and Windows.
{% endhint %}

### 1. Setup Ngrok

* Go to <https://ngrok.com/>
* Sign up, verify your e-mail address, download an install [ngrok](https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-windows-amd64.zip)
* You must get this page :&#x20;

<figure><img src="https://2148543285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMQ7C6EOuUwW9qS3ZrFPo%2Fuploads%2FR0wxmJRSImzvlQEwwv4l%2Fimage.png?alt=media&#x26;token=0a29ebb1-ac07-48cc-ad89-dbfb12e7fd98" alt=""><figcaption></figcaption></figure>

* In a terminal, enter :&#x20;

```bash
ngrok config add-authtoken YOUR_PRIVATE_TOKEN
```

* It must echo :&#x20;

```
Authtoken saved to configuration file : path\to\file\ngrok.yml
```

### 2. Setup TradeWorkstation

* Download, install and launch [TWS](https://www.interactivebrokers.co.uk/fr/trading/tws.php)
* If you want to trade with virtual money, log in to the paper mode, else in the live mode
* In the TWS, go to Settings > API > Settings
* Check "Enable ActiveX and Socket Clients"
* Uncheck "Read-Only API"
* Remember the socket port (7497 by default for paper trading, 7496 for live trading)
* Click on "Apply"
* Go to your terminal and enter :&#x20;

```
ngrok tcp 7497
```

if your modified the socket port to 6666, for instance, it should be :&#x20;

```
ngrok tcp 6666
```

* copy the link that starts with "tcp", in the format `tcp://x.tcp.xx.ngrok.io:xxxxx`

### 3. Setup Swiss33

* Go to the model's page of [Swiss33](https://www.swiss33.com/models)
* Create a model, by choosing the algorithm you want and of course Interactive Brokers as a data source
* You will be asked to enter the link you copied right before :&#x20;

<figure><img src="https://2148543285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMQ7C6EOuUwW9qS3ZrFPo%2Fuploads%2FvG4UkBV3PERPHo8dXsEr%2Fimage.png?alt=media&#x26;token=c27bbeb2-81e7-4f23-aa87-bee5aa89c09d" alt=""><figcaption></figcaption></figure>

* So, enter your link `tcp://x.tcp.xx.ngrok.io:xxxxx` in "Trader Workstation's connection"

Done !

You can the train your model, backtest it, deploy it as a bot like for any other broker.

{% hint style="info" %}
Don't forget that while you handle data from Interactive Brokers, your TWS and Ngrok must be on, otherwise it will stop.
{% endhint %}
