-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2. Contract Details.py
More file actions
95 lines (70 loc) · 2.38 KB
/
2. Contract Details.py
File metadata and controls
95 lines (70 loc) · 2.38 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from threading import Thread
import time
##-------------------------------------------------------------------------
### Create Class
class Strategy (EClient, EWrapper):
def __init__(self):
EWrapper.__init__(self)
EClient.__init__(self,self)
#Receive contract details in TWS (in thread)
#Use EClient class to receive response
def contractDetails(self, reqId, contractDetails):
print(' \nReqId: ', reqId, '\nContract Details: ', contractDetails)
def contractDetailsEnd(self, reqId):
print(' \nReqId: ', reqId, 'Contract Details Ended')
##-------------------------------------------------------------------------
### Create Object
application = Strategy()
application.connect(host= 'localhost', port= 7497, clientId= 1)
time.sleep(1)
#Thread
Thread(target= application.run, daemon= True).start()
print('Connection?', application.isConnected())
#Create object for contract
usd_jpy = Contract()
#find the contract details via TWS -> Financial Instrucment Description
#forex pair: JPY.USD
usd_jpy.symbol = 'USD'
usd_jpy.currency = 'JPY'
usd_jpy.secType = 'CASH'
usd_jpy.exchange = 'IDEALPRO'
#Request Contract details
application.reqContractDetails(reqId=101, contract= usd_jpy)
time.sleep(10)
#Disconnect after completion
application.disconnect()
##-------------------------------------------------------------------------
###For other asset types
# Equity
# contract = Contract()
# contract.symbol = "MSFT"
# contract.secType = "STK"
# contract.currency = "USD"
# contract.exchange = "SMART"
# contract.primaryExchange = "ISLAND"
# Index
# contract = Contract()
# contract.symbol = 'NIFTY50'
# contract.secType = 'IND'
# contract.currency = 'INR'
# contract.exchange = 'NSE'
# Futures Contract
# contract = Contract()
# contract.symbol = 'ES'
# contract.secType = 'FUT'
# contract.currency = 'USD'
# contract.exchange = 'GLOBEX'
# contract.lastTradeDateOrContractMonth = '202101'
# Options Contract
# contract = Contract()
# contract.symbol = 'GOOG'
# contract.secType = 'OPT'
# contract.exchange = 'SMART'
# contract.currency = 'USD'
# contract.lastTradeDateOrContractMonth = '20201023'
# contract.strike = 1555
# contract.right = 'C'
# contract.multiplier = '100'