Skip to content

Commit b2132df

Browse files
committed
Add File Path Issue Fix
1 parent 8913b6c commit b2132df

File tree

6 files changed

+404
-269
lines changed

6 files changed

+404
-269
lines changed

README.md

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
- [Overview](#overview)
44
- [What's in the API](#whats-in-the-api)
5-
- [Requirements](#requirements)
6-
- [API Key & Credentials](#api-key-and-credentials)
7-
- [Installation](#installation)
5+
- [Setup Requirements](#setup-requirements)
6+
- [Setup Client Portal](#setup-client-portal)
7+
- [Setup API Key & Credentials](#setup-api-key-and-credentials)
8+
- [Setup Installation](#setup-installation)
9+
- [Setup Writing Account Information](#setup-writing-account-information)
810
- [Usage](#usage)
911
- [Features](#features)
1012
- [Documentation & Resources](#documentation-and-resources)
@@ -31,24 +33,64 @@ Interactive Broker offers multiple APIs for their clients. If you would like to
3133
- Portfolio Analysis Endpoints
3234
- Web Streaming
3335

34-
## Requirements
36+
## Setup Requirements
3537

3638
The following requirements must be met to use this API:
3739

3840
- A Interactive Broker account, you'll need your account password and account number to use the API.
3941
- [Java 8](https://developers.redhat.com/products/openjdk/download) update 192 or higher installed (gateway is compatible with higher Java versions including OpenJDK 11).
40-
- Download the [Client Portal Gateway](https://www.interactivebrokers.com/en/index.php?f=45185)
42+
- Download the [Beta Client Portal Gateway](https://www.interactivebrokers.com/en/index.php?f=45185)
4143

42-
## API Key and Credentials
44+
## Setup Client Portal
45+
46+
Once you've downloaded the latest client portal or if you chose to use the one provided by the repo. You need to unzip the folder and place it in the repo where this code is stored.
47+
48+
## Setup API Key and Credentials
4349

4450
The API does not require any API keys to use it, all of the authentication is handled by the Client Portal Gateway. Everytime a user starts a new session with the API they will need to proivde their login credentials for the account they wish to use. The Interactive Broker Web API does offer the ability to use the API using a paper account.
4551

4652
**Important:** Your account number and account password should be kept secret.
4753

48-
## Installation
54+
## Setup Installation
4955

5056
PLACE HOLDER FOR PIP INSTALLATION
5157

58+
## Setup Writing Account Information
59+
60+
The Client needs specific account information to create a and validate a new session. Where you choose to store this information is up to you, but I'll layout some options here.
61+
62+
**Write a Config File:**
63+
64+
It's common in Python to have a config file that contains information you need to use during the setup of a script. Additionally, you can make this file in a standard way so that way it's easy to read everytime. In Python, there is a module called `configparser` which can be used to create config files that mimic that of Windows INI files.
65+
66+
To create a config file using hte `configparser` module, run the script below in a separate file or go to the [Resources Folder](https://github.com/areed1192/interactive-broker-python-api/tree/master/resources) and run the `write_config.py` file.
67+
68+
```python
69+
import pathlib
70+
from configparser import ConfigParser
71+
72+
config = ConfigParser()
73+
74+
config.add_section('main')
75+
76+
config.set('main', 'REGULAR_ACCOUNT', 'YOUR_ACCOUNT_NUMBER')
77+
config.set('main', 'REGULAR_PASSWORD', 'YOUR_ACCOUNT_PASSWORD')
78+
config.set('main', 'REGULAR_USERNAME', 'YOUR_ACCOUNT_USERNAME')
79+
80+
config.set('main', 'PAPER_ACCOUNT', 'YOUR_ACCOUNT_NUMBER')
81+
config.set('main', 'PAPER_PASSWORD', 'YOUR_ACCOUNT_PASSWORD')
82+
config.set('main', 'PAPER_USERNAME', 'YOUR_ACCOUNT_USERNAME')
83+
84+
new_directory = pathlib.Path("config/").mkdir(parents=True, exist_ok=True)
85+
86+
with open('config/config.ini', 'w+') as f:
87+
config.write(f)
88+
```
89+
90+
**Store the Variables in the Script:**
91+
92+
If you plan to not share the script with anyone else, then you can store the account info inside the script itself. However, please make sure that you do not make the file public to individuals you don't know.
93+
5294
## Usage
5395

5496
This example demonstrates how to login to the API and demonstrates sending a request using the `market_data_history` endpoint, using your API key.
@@ -57,11 +99,10 @@ This example demonstrates how to login to the API and demonstrates sending a req
5799
from ibw.client import IBClient
58100

59101
REGULAR_ACCOUNT = 'MY_ACCOUNT_NUMBER'
60-
REGULAR_PASSWORD = 'MY_ACCOUNT_PASSWORD'
61102
REGULAR_USERNAME = 'MY_ACCOUNT_USERNAME'
62103

63104
# Create a new session of the IB Web API.
64-
ib_session = IBClient(username = REGULAR_USERNAME, password = REGULAR_PASSWORD, account = REGULAR_ACCOUNT)
105+
ib_session = IBClient(username=REGULAR_USERNAME, account=REGULAR_ACCOUNT)
65106

66107
# create a new session.
67108
ib_client.create_session()
@@ -73,7 +114,7 @@ account_data = ib_client.portfolio_accounts()
73114
print(account_data)
74115

75116
# Grab historical prices.
76-
aapl_prices = ib_client.market_data_history(conid = ['265598'], period = '1d', bar = '5min')
117+
aapl_prices = ib_client.market_data_history(conid=['265598'], period='1d', bar='5min')
77118

78119
# print the prices.
79120
print(aapl_prices)

0 commit comments

Comments
 (0)