Skip to main content

Use SQL to instantly query your online brokers (IBKR and more).

Project description

BrokerQL Logo

BrokerQL is the database interface to Brokers and Finance Market. Use SQL to query quotes, positions, query or place orders, and find investing or trading ideas.

BrokerQL is built with ❤ by trader, and built for traders, portfolio managers, and financial advisors who knows a little about SQL, to decrease daily job of portfolio management.

BrokerQL is inspired by Steampipe.

With BrokerQL you can:

  • Query → Use SQL to query (and join across!) from your Brokers.

  • Modify → Update multiple order's price and quantity with SQL.

BrokerQL CLI: The SQL console for Online Brokers.

The BrokerQL community has grown a suite of plugins that map Brokers to tables.

US Brokers IBKR

The interactive query shell is one way you can query those tables.

You can also use mysql-client, mycli, DataGrip, or any client that can connect to MySQL.

Get started with the CLI

Install BrokerQL

The download page shows you how but tl;dr:

Linux or Windows or macOS

pip install BrokerQL

macOS only

brew tap BrokerQL/tap
brew install broker-ql
Run BrokerQL query

Make sure your IBKR TWS is running on localhost, and listen to port 7496 for API.

Launch the interactive shell.

broker-ql --cli

Run your first query!

select * from tws.positions;
Learn more about the CLI
  • It's just SQL

  • You can run queries on the command line and include them in scripts.

Build and develop the CLI

Prerequisites:

  • Python Version 3.9.

Clone:

git clone git@github.com:BrokerQL/BrokerQL
cd BrokerQL

Create virtualenv, and run the pip command

python -m venv venv
source venv/bin/activate
pip install .
pip install -r requirements-dev.txt

Check the version

$ broker-ql -v
BrokerQL v0.0.1

Try it!

broker-ql --cli
connecting to tws...
tws connected
BrokerQL (none)> nopager
Pager disabled.
Time: 0.000s
BrokerQL (none)> show databases
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| tws                |
+--------------------+
3 rows in set
Time: 0.036s
BrokerQL (none)> use tws
You are now connected to database "tws" as user "panjiabang"
Time: 0.001s
BrokerQL tws> show tables
+---------------+
| Table_name    |
+---------------+
| orders        |
| positions     |
| quotes        |
| subscriptions |
+---------------+
4 rows in set
Time: 0.033s
BrokerQL tws> select * from positions
+-----------+--------+----------+--------------------+
| account   | symbol | position | avg_cost           |
+-----------+--------+----------+--------------------+
| U11739578 | ADBE   |  6.0     | 579.3533333333334  |
| U11739578 | PDD    | 32.0     | 119.65125          |
| U11739578 | URNM   | 62.0     |  49.18850806451613 |
| U11739578 | QQQ    | 27.0     | 385.82703703703703 |
| U11739578 | MSFT   | 12.0     | 378.9533333333333  |
| U11739578 | MHO    | 40.0     | 103.19500000000001 |
+-----------+--------+----------+--------------------+
12 rows in set
Time: 0.037s

Community

We thrive on feedback and community involvement!

Have a question? → Join our Github Discussions or open a GitHub issue.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

BrokerQL-0.0.2.tar.gz (32.0 kB view hashes)

Uploaded Source

Built Distribution

BrokerQL-0.0.2-py3-none-any.whl (34.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page