Skip to main content

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).

Project description

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

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

ib-cp-gateway-1.0.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

ib_cp_gateway-1.0.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file ib-cp-gateway-1.0.1.tar.gz.

File metadata

  • Download URL: ib-cp-gateway-1.0.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for ib-cp-gateway-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e9885ad3586becc867f7179178731271d55cbf630f7448f763bc742860325a08
MD5 df574fb69dcb020e54ee057f25f5917b
BLAKE2b-256 3ba173f3a0d23166b79d03c263fad89aad5dfa83ddd530682cfb95c01ad51613

See more details on using hashes here.

File details

Details for the file ib_cp_gateway-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ib_cp_gateway-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d91ff01f2258c2652dcc8c8fd99df48ee472534837824f85fef62930e228ee03
MD5 572d20ea6aa244002b0f7e2680d40e02
BLAKE2b-256 37878093661f05d87ca8f5a63e02269cd860ee8b08c4eefcdae23866e12419bd

See more details on using hashes here.

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