GithubHelp home page GithubHelp logo

tradingview-interactive-brokers's Introduction

tradingview-interactive-brokers

TradingView Interactive Brokers Integration using Webhooks

Demo Video:

https://www.youtube.com/watch?v=zsYKfzCNPPU

Support My Work

Visit Interactive Brokers

https://www.interactivebrokers.com/mkt/?src=ptlg&url=%2Fen%2Findex.php%3Ff%3D1338

Buy Me a Coffee

https://buymeacoffee.com/parttimelarry

Diagram

Diagram

Prerequisites

  • Requires redis, Python3, and packages installed
pip3 install -r requirements.txt

export FLASK_APP=webapp
export FLASK_ENV=development
flask run

References, Tools, and Libraries Used:

tradingview-interactive-brokers's People

Contributors

hackingthemarkets 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  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  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

tradingview-interactive-brokers's Issues

ib.connect() returns connect call failed error

I tried your code, with the same instructions as in the video, installed virtual environment for VS Code and WSL, ran webapp and the file, but it fails to connect. Please advise and solve the problem. This was the error message

API connection failed: ConnectionRefusedError(111, "Connect call failed ('127.0.0.1', 7497)")
Make sure API port on TWS/IBG is open
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.10/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/trendbot.py", line 15, in <module>
    app.connect(host="127.0.0.1", port=7497, clientId=1)
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/ib_insync/ib.py", line 269, in connect
    return self._run(self.connectAsync(
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/ib_insync/ib.py", line 308, in _run
    return util.run(*awaitables, timeout=self.RequestTimeout)
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/ib_insync/util.py", line 341, in run
    result = loop.run_until_complete(task)
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/nest_asyncio.py", line 90, in run_until_complete
    return f.result()
  File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "/usr/lib/python3.10/asyncio/tasks.py", line 232, in __step
    result = coro.send(None)
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/ib_insync/ib.py", line 1674, in connectAsync
    await self.client.connectAsync(host, port, clientId, timeout)
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/ib_insync/client.py", line 211, in connectAsync
    await asyncio.wait_for(self.conn.connectAsync(host, port), timeout)
  File "/usr/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
    return fut.result()
  File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "/usr/lib/python3.10/asyncio/tasks.py", line 234, in __step
    result = coro.throw(exc)
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/ib_insync/connection.py", line 39, in connectAsync
    self.transport, _ = await loop.create_connection(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection
    sock = await self._connect_sock(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect
    return await fut
  File "/usr/lib/python3.10/asyncio/futures.py", line 285, in __await__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.10/asyncio/tasks.py", line 304, in __wakeup
    future.result()
  File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "/usr/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 7497)

broker.py lost connection after TWS/IBGateway restarted

After TWS/IBGateway restarted, broker.py will lost connection with TWS/IBGateway api. (same IP & Port)

I have to kill broker.py and run it again to make it work.

I am not familiar with coding. Is it possible to keep connection even TWS/IBGateway restarted?

ib.run() not called

First off, thanks for sharing this Larry. This is a fun code snippet. I'm using in testing now.

For some reason, ib.run() is never executed

Disconnects w/out Notice

After long durations (~>4 hours) the code continues to run but no trades are executed. It seems IBKR is disconnecting.

Test:

  • Run the code for ~>4 hours
  • Close IBKR

Expected:

  • Program should crash

Actual:

  • IBKR disconnection is not noticed

I was able to fix this by removing the async code and then using a loop to periodically call ib.sleep() and ib.positions() on a loop. I've been unable to get ib.sleep() to work within async. I'd love to see how to remedy this.

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.