-
Notifications
You must be signed in to change notification settings - Fork 3
/
Stock_Symbol_Matching.py
53 lines (41 loc) · 1.51 KB
/
Stock_Symbol_Matching.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# __Author__ = 'Elizabeth Zhang'
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.common import *
from ibapi.contract import *
import pandas as pd
import pandas_datareader as reader
import numpy as np
# ================================ Part 1 ===================================
# read input files
path = '/Users/Elizabeth.Ke.Zhang/Desktop/Oct/Germany_Equities.csv'
f = pd.read_csv(filepath_or_buffer=path, sep=',')
col_index = [f.columns[0], f.columns[4]]
df = f[col_index]
df.columns = ['Symbol', 'Exchange']
Tickers = np.asarray(df['Symbol'])
Exchanges = np.asarray(df['Exchange'])
print(Tickers, Exchanges)
# ================================ Part 2 ===================================
# Get access to IB
class TestApp(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
def error(self, reqId: TickerId, errorCode: int, errorString: str):
print('Error:', reqId, ' ', errorCode, ' ', errorString)
def contractDetails(self, reqId: int, contractDetails: ContractDetails):
print('ContractDetails:', reqId, ' ', contractDetails)
def main():
for i in range(1472):
app = TestApp()
app.connect('127.0.0.1', 7497, 0)
contract = Contract()
contract.symbol = Tickers[i]
contract.exchange = Exchanges[i]
contract.secType = "STK"
contract.currency = 'EUR'
contract.primaryExchange = Exchanges[i]
app.reqContractDetails(i, contract)
app.run()
if __name__ == '__main__':
main()