-
Notifications
You must be signed in to change notification settings - Fork 59
/
contract.go
136 lines (119 loc) · 3.53 KB
/
contract.go
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
package ibapi
import "fmt"
//Contract describes an instrument's definition
type Contract struct {
ContractID int64
Symbol string
SecurityType string
Expiry string
Strike float64
Right string
Multiplier string
Exchange string
Currency string
LocalSymbol string
TradingClass string
PrimaryExchange string // pick an actual (ie non-aggregate) exchange that the contract trades on. DO NOT SET TO SMART.
IncludeExpired bool
SecurityIDType string // CUSIP;SEDOL;ISIN;RIC
SecurityID string
// combos les
ComboLegsDescription string
ComboLegs []ComboLeg
// UnderComp *UnderComp
DeltaNeutralContract *DeltaNeutralContract
}
func (c Contract) String() string {
basicStr := fmt.Sprintf("Contract<CondID: %d, Symbol: %s, SecurityType: %s, Exchange: %s, Currency: %s",
c.ContractID,
c.Symbol,
c.SecurityType,
c.Exchange,
c.Currency)
switch c.SecurityType {
case "FUT":
basicStr += fmt.Sprintf(", Expiry: %s, Multiplier: %s, SecurityID: %s, SecurityIDType: %s>", c.Expiry, c.Multiplier, c.SecurityID, c.SecurityIDType)
case "OPT":
basicStr += fmt.Sprintf(", Expiry: %s, Strike: %f, Right: %s, SecurityID: %s, SecurityIDType: %s>", c.Expiry, c.Strike, c.Right, c.SecurityID, c.SecurityIDType)
default:
basicStr += fmt.Sprint(">")
}
for i, leg := range c.ComboLegs {
basicStr += fmt.Sprintf("-Leg<%d>: %s", i, leg)
}
if c.DeltaNeutralContract != nil {
basicStr += fmt.Sprintf("-%s", c.DeltaNeutralContract)
}
return basicStr
}
// DeltaNeutralContract is Delta-Neutral Contract
type DeltaNeutralContract struct {
ContractID int64
Delta float64
Price float64
}
func (c DeltaNeutralContract) String() string {
return fmt.Sprintf("DeltaNeutralContract<CondID: %d , Delta: %f, Price: %f>",
c.ContractID,
c.Delta,
c.Price)
}
// ContractDetails contain a Contract and other details about this contract, can be request by ReqContractDetails
type ContractDetails struct {
Contract Contract
MarketName string
MinTick float64
OrderTypes string
ValidExchanges string
PriceMagnifier int64
UnderContractID int64
LongName string
ContractMonth string
Industry string
Category string
Subcategory string
TimezoneID string
TradingHours string
LiquidHours string
EVRule string
EVMultiplier int64
MdSizeMultiplier int64
AggGroup int64
UnderSymbol string
UnderSecurityType string
MarketRuleIDs string
SecurityIDList []TagValue
RealExpirationDate string
LastTradeTime string
StockType string
// BOND values
Cusip string
Ratings string
DescAppend string
BondType string
CouponType string
Callable bool
Putable bool
Coupon int64
Convertible bool
Maturity string
IssueDate string
NextOptionDate string
NextOptionType string
NextOptionPartial bool
Notes string
}
func (c ContractDetails) String() string {
return fmt.Sprintf("ContractDetails<Contract: %s, MarketName: %s, UnderContractID: %d, LongName: %s>", c.Contract, c.MarketName, c.UnderContractID, c.LongName)
}
// ContractDescription includes contract and DerivativeSecTypes
type ContractDescription struct {
Contract Contract
DerivativeSecTypes []string
}
// NewComboLeg create a default comboleg
func NewComboLeg() ComboLeg {
comboLeg := ComboLeg{}
comboLeg.ExemptCode = -1
return comboLeg
}