forked from gofinance/ib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
option.go
45 lines (39 loc) · 791 Bytes
/
option.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
package ib
import (
"time"
)
// OptionChains .
type OptionChains map[time.Time]*OptionChain
// OptionChain .
type OptionChain struct {
Expiry time.Time
Strikes map[float64]*OptionStrike
}
func (o *OptionChain) update(c *ContractData) {
if strike, ok := o.Strikes[c.Contract.Summary.Strike]; ok {
// strike exists
strike.update(c)
} else {
// no strike exists
strike := &OptionStrike{
expiry: o.Expiry,
Price: c.Contract.Summary.Strike,
}
o.Strikes[c.Contract.Summary.Strike] = strike
strike.update(c)
}
}
// OptionStrike .
type OptionStrike struct {
expiry time.Time
Price float64
Put *ContractData
Call *ContractData
}
func (o *OptionStrike) update(c *ContractData) {
if c.Contract.Summary.Right == "C" {
o.Call = c
} else {
o.Put = c
}
}