This repository was archived by the owner on Mar 31, 2026. It is now read-only.
forked from ib-ruby/ib-ruby
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathContract.java
More file actions
143 lines (119 loc) · 4.27 KB
/
Copy pathContract.java
File metadata and controls
143 lines (119 loc) · 4.27 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
/*
* Contract.java
*
*/
package com.ib.client;
import java.util.Vector;
public class Contract implements Cloneable {
public int m_conId;
public String m_symbol;
public String m_secType;
public String m_expiry;
public double m_strike;
public String m_right;
public String m_multiplier;
public String m_exchange;
public String m_currency;
public String m_localSymbol;
public String m_primaryExch; // pick a non-aggregate (ie not the SMART exchange) exchange that the contract trades on. DO NOT SET TO SMART.
public boolean m_includeExpired; // can not be set to true for orders.
// COMBOS
public String m_comboLegsDescrip; // received in open order version 14 and up for all combos
public Vector m_comboLegs = new Vector();
// delta neutral
public UnderComp m_underComp;
public Contract() {
m_conId = 0;
m_strike = 0;
m_includeExpired = false;
}
public Object clone() throws CloneNotSupportedException {
Contract retval = (Contract)super.clone();
retval.m_comboLegs = (Vector)retval.m_comboLegs.clone();
return retval;
}
public Contract(int p_conId, String p_symbol, String p_secType, String p_expiry,
double p_strike, String p_right, String p_multiplier,
String p_exchange, String p_currency, String p_localSymbol,
Vector p_comboLegs, String p_primaryExch, boolean p_includeExpired) {
m_conId = p_conId;
m_symbol = p_symbol;
m_secType = p_secType;
m_expiry = p_expiry;
m_strike = p_strike;
m_right = p_right;
m_multiplier = p_multiplier;
m_exchange = p_exchange;
m_currency = p_currency;
m_includeExpired = p_includeExpired;
m_localSymbol = p_localSymbol;
m_comboLegs = p_comboLegs;
m_primaryExch = p_primaryExch;
}
public boolean equals(Object p_other) {
if (this == p_other) {
return true;
}
if (p_other == null || !(p_other instanceof Contract)) {
return false;
}
Contract l_theOther = (Contract)p_other;
if (m_conId != l_theOther.m_conId) {
return false;
}
if (m_comboLegs.size() != l_theOther.m_comboLegs.size()) {
return false;
}
if (Util.StringCompare(m_secType, l_theOther.m_secType) != 0) {
return false;
}
if (Util.StringCompare(m_symbol, l_theOther.m_symbol) != 0 ||
Util.StringCompare(m_exchange, l_theOther.m_exchange) != 0 ||
Util.StringCompare(m_primaryExch, l_theOther.m_primaryExch) != 0 ||
Util.StringCompare(m_currency, l_theOther.m_currency) != 0) {
return false;
}
if (!Util.NormalizeString(m_secType).equals("BOND")) {
if (m_strike != l_theOther.m_strike) {
return false;
}
if (Util.StringCompare(m_expiry, l_theOther.m_expiry) != 0 ||
Util.StringCompare(m_right, l_theOther.m_right) != 0 ||
Util.StringCompare(m_multiplier, l_theOther.m_multiplier) != 0 ||
Util.StringCompare(m_localSymbol, l_theOther.m_localSymbol) != 0) {
return false;
}
}
if (m_comboLegs.size() > 0) {
// compare the combo legs
int comboLegsSize = m_comboLegs.size();
boolean[] alreadyMatchedSecondLeg = new boolean[comboLegsSize];
for (int ctr1 = 0; ctr1 < comboLegsSize; ++ctr1) {
ComboLeg l_thisComboLeg = (ComboLeg) m_comboLegs.get(ctr1);
int ctr2 = 0;
for (; ctr2 < comboLegsSize; ++ctr2) {
if (alreadyMatchedSecondLeg[ctr2]) {
continue;
}
if (l_thisComboLeg.equals(l_theOther.m_comboLegs.get(ctr2))) {
alreadyMatchedSecondLeg[ctr2] = true;
break;
}
}
if (ctr2 >= comboLegsSize) {
// no matching leg found
return false;
}
}
}
if (m_underComp != l_theOther.m_underComp) {
if (m_underComp == null || l_theOther.m_underComp == null) {
return false;
}
if (!m_underComp.equals(l_theOther.m_underComp)) {
return false;
}
}
return true;
}
}