Skip to main content

IB Client Portal Gateway API

PyPI PyPI - Downloads PyPI - Python Version PyPI - Wheel GitHub contributors GitHub issues GitHub Action GitHub

This is a simple IB Client Portal Gateway RESTFul api, IB Client Portal Gateway can be run on Raspberry Pi or any other ARM machine(IB Gateway and TWS are not able to run on ARM). If the api get error, it will return None rather than throw exception.

Install

pip install ib-cp-gateway

or

pip install --upgrade ib-cp-gateway

Usage

  • Login/Authentication You need go login through https://localhost:5000 before using this api. To run the IB Client Portal Gateway, you can use docker. For ARM architecture,
docker run -d -it --restart=always --name cpgateway-docker -p 5000:5000 hurinhu/ib-clientportal-gateway:RPI4

For others,

docker run -d -it --restart=always --name cpgateway-docker -p 5000:5000 hurinhu/ib-clientportal-gateway
  • Initializing
from IB import API
ib = API(url="https://localhost:5000", ssl=False)
  • Check version
print(ib.getVersion())
  • Check validate session
ib.get_validate()
  • Ping server to keep alive
ib.ping_server()
  • Get gateway status
ib.get_status()
  • Re authentication
ib.reauthenticate()
  • Logout
ib.logout()
  • Get future conids
ib.get_future_conids(symbol)
  • Get stock conids
ib.get_stock_conids(symbol,contract_filters={"isUS": True})
  • Find conids details
ib.find_conids(conids)
  • Get history data
ib.get_history(conid, period='1w',bar='id',outsideRth=False)

or

ib.get_history_beta(conid, period='1w',bar='id',outsideRth=False)
  • Get snapshot data
ib.get_snapshot(conids,since,fields)

or

ib.get_snapshot_beta(conids,fields)
  • Get account information
ib.get_accounts()
  • Get account meta
ib.get_account_meta(accountId)
  • Get account summary
ib.get_account_summary(accountId)
  • Get account PDT
ib.get_account_PDT()
  • Get account ledger (balance information)
ib.get_account_ledger(account)
  • Get account trades
ib.get_trades()
  • Get orders (filters: cancelled, filled, submitted)
ib.get_orders(filters=[])

or

ib.get_order_by_id(orderId)
  • Create order (side: BUY, SELL)
ib.create_order(accountId, conid, price, quantity, side, orderType='LMT', outsideRTH=True, tif='GTC', useAdaptive=True, isCcyConv=False)
  • Cancel order
ib.cancel_order(accountId, orderId)

Example

order = ib.create_order('UXXXXX', 72539702, 41.20, 200, 'BUY', 'LMT', True, 'GTC', True, False)
orderId = order['order_id']
ib.cancel_order('UXXXXX',orderId)
orders = ib.get_orders()
orders[0]['status'] # this is the last order status, it should be 'Cancelled' after cancel order

Release files for ib-cp-gateway 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ib-cp-gateway 1.0.1
File Size Uploaded
ib-cp-gateway-1.0.1.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ib-cp-gateway 1.0.1
File Interpreter ABI Platform
ib_cp_gateway-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / ib-cp-gateway-1.0.1.tar.gz

Download URL ib-cp-gateway-1.0.1.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e9885ad3586becc867f7179178731271d55cbf630f7448f763bc742860325a08
BLAKE2b-256 checksum
How to use checksums
3ba173f3a0d23166b79d03c263fad89aad5dfa83ddd530682cfb95c01ad51613
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Release files / ib_cp_gateway-1.0.1-py3-none-any.whl

Download URL ib_cp_gateway-1.0.1-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d91ff01f2258c2652dcc8c8fd99df48ee472534837824f85fef62930e228ee03
BLAKE2b-256 checksum
How to use checksums
37878093661f05d87ca8f5a63e02269cd860ee8b08c4eefcdae23866e12419bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page