IB Client Portal Gateway API
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
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ib-cp-gateway-1.0.1.tar.gz | 4.8 kB | Without provenance | Details for ib-cp-gateway-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ib_cp_gateway-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for ib_cp_gateway-1.0.1-py3-none-any.whl |
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
|
Security for ib-cp-gateway 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.