This repository was archived by the owner on Aug 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathMain_updated.java
More file actions
248 lines (179 loc) · 7.36 KB
/
Copy pathMain_updated.java
File metadata and controls
248 lines (179 loc) · 7.36 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import com.ib.client.*;
/**
* Created by IntelliJ IDEA.
* User: Jerry Sy a.k.a. AutoTrader
* Date: Feb 17, 2003
* Time: 10:11:59 PM
* Updated by Keith Kee 2005-04-16 for new TWSAPI
* Updated by Gene Livingston 2011-05-16 for new TWSAPI
* To change this template use Options | File Templates.
*/
public class Main implements EWrapper{
EClientSocket m_client = new EClientSocket(this);
int id = 0;
public Main(String[] args) {
String twsIPAddr = "192.168.1.67";
m_client.eConnect(twsIPAddr,7496, 0xF00E);
int count = 0;
while (!m_client.isConnected()) {
try {
Thread.sleep(500);
count++;
if (count >10)
break;
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
}
if (!m_client.isConnected()) {
System.exit(-1);
}
System.out.println("Sample TWS API Client Java code to print market data");
System.out.println("getting quotes for AAPL STK");
System.out.println("Press CTRL-C to quit");
Contract contract = new Contract();
contract.m_symbol="AAPL";
contract.m_secType="STK";
contract.m_exchange="SMART";
contract.m_currency="USD";
String gtl = "";
boolean ss = true;
//contract.expiry="200303";
m_client.reqMktData(id,contract,gtl,ss);
Thread.yield();
}
//public synchronized void reqMktData(int tickerId, Contract contract,
// String genericTickList, boolean snapshot)
public static void main(String[] args) {
Main main = new Main(args);
}
public void tickPrice(int tickerId, int field, double price,int canAutoExecute ) {
switch (field){
case 1: //bid
System.out.println("Bid Price = "+String.valueOf(price));
break;
case 2: //ask
System.out.println("Ask Price = "+String.valueOf(price));
break;
case 4: //last
System.out.println("Last Price = "+String.valueOf(price));
break;
case 6: //high
System.out.println("High Price = "+String.valueOf(price));
break;
case 7: //low
System.out.println("Low Price = "+String.valueOf(price));
break;
case 9: //close
System.out.println("Close Price = "+String.valueOf(price));
break;
}
}
public void tickSize(int tickerId, int field, int size) {
switch (field){
case 0: //bid
System.out.println("Bid Size = "+String.valueOf(size));
break;
case 3: //ask
System.out.println("Ask Size = "+String.valueOf(size));
break;
case 5: //last
System.out.println("Last Size = "+String.valueOf(size));
break;
case 8: //volume
System.out.println("Volume = "+String.valueOf(size));
break;
}
}
public void orderStatus( int orderId, String status, int filled, int remaining,
double avgFillPrice, int permId, int parentId, double lastFillPrice, int clientId){
}
public void openOrder(int orderId, Contract contract, Order order) {
}
public void error(String str) {
}
public void connectionClosed() {
}
public void updateAccountValue(String key, String value, String currency, String accountName){
}
public void updatePortfolio(Contract contract, int position, double marketPrice, double marketValue) {
}
public void updateAccountTime(String timeStamp) {
}
public void nextValidId(int orderId) {
id = orderId;
}
public void contractDetails(ContractDetails contractDetails) {
}
public void execDetails(int orderId, Contract contract, Execution execution) {
}
public void error(int id, int errorCode, String errorMsg) {
System.out.println("Error id = "+String.valueOf(id)+" Error Code = "+String.valueOf(errorCode)+" "+errorMsg);
}
public void updateMktDepth(int tickerId, int position, int operation, int side, double price, int size) {
}
public void updateMktDepthL2(int tickerId, int position, String marketMaker, int operation, int side, double price, int size) {
}
public void updateNewsBulletin( int msgId, int msgType, String message, String origExchange){
}
public void managedAccounts( String accountsList){
}
public void receiveFA(int faDataType, String xml){
}
public void intradayData(int reqId, String date, double open, double high, double low, double close, int volume, double WAP, boolean hasGaps){
}
public void updatePortfolio(Contract contract, int position, double marketPrice, double marketValue, double averageCost, double unrealizedPNL, double realizedPNL, String accountName){
}
//bug stomp
public void tickSnapshotEnd(int tk){
}
public void deltaNeutralValidation(int reqId, UnderComp underComp) {
}
public void fundamentalData(int reqId, String data) {
}
public void currentTime(long time) {
}
public void realtimeBar(int reqId, long time, double open, double high, double low, double close, long volume, double wap, int count) {
}
public void scannerDataEnd(int reqId) {
}
public void scannerData(int reqId, int rank, ContractDetails contractDetails, String distance,
String benchmark, String projection, String legsStr) {
}
public void scannerParameters(String xml) {
}
public void historicalData(int reqId, String date, double open, double high, double low,
double close, int volume, int count, double WAP, boolean hasGaps) {
}
public void execDetailsEnd( int reqId) {
}
public void contractDetailsEnd(int reqId) {
}
public void bondContractDetails(int reqId, ContractDetails contractDetails) {
}
public void contractDetails(int reqId, ContractDetails contractDetails) {
}
public void accountDownloadEnd(String accountName) {
}
public void openOrderEnd() {
}
public void openOrder( int orderId, Contract contract, Order order, OrderState orderState) {
}
public void orderStatus( int orderId, String status, int filled, int remaining,
double avgFillPrice, int permId, int parentId, double lastFillPrice,
int clientId, String whyHeld) {
}
public void tickEFP(int tickerId, int tickType, double basisPoints,
String formattedBasisPoints, double impliedFuture, int holdDays,
String futureExpiry, double dividendImpact, double dividendsToExpiry) {
}
public void tickString(int tickerId, int tickType, String value) {
}
public void tickGeneric(int tickerId, int tickType, double value) {
}
public void tickOptionComputation( int tickerId, int field, double impliedVol,
double delta, double modelPrice, double pvDividend) {
}
public void error( Exception e) {
}
}