Skip to content

Commit 1bc789b

Browse files
Update ListOptionsChainParams.WithStrikePrice to support comparators (#414)
Co-authored-by: GitHub Action <[email protected]>
1 parent 4813bd5 commit 1bc789b

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Polygon Go Client
2-
![Coverage](https://img.shields.io/badge/Coverage-76.6%25-brightgreen)
2+
![Coverage](https://img.shields.io/badge/Coverage-76.7%25-brightgreen)
33

44
<!-- todo: add a codecov badge -->
55
<!-- todo: figure out a way to show all build statuses -->

rest/example/options/snapshots-options-chain/main.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ func main() {
1818
c := polygon.New(os.Getenv("POLYGON_API_KEY"))
1919

2020
// set params
21-
params := &models.ListOptionsChainParams{
22-
UnderlyingAsset: "AAPL",
23-
}
24-
25-
// make request
21+
params := models.ListOptionsChainParams{
22+
UnderlyingAsset: "SPY",
23+
StrikePriceGTE: new(float64),
24+
StrikePriceLTE: new(float64),
25+
Limit: new(int),
26+
}.WithStrikePrice("gte", 500.00).WithStrikePrice("lte", 600.00).WithLimit(250)
27+
28+
// make the request
2629
iter := c.ListOptionsChainSnapshot(context.Background(), params)
2730

2831
// do something with the result

rest/models/snapshot.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,23 @@ type ListOptionsChainParams struct {
106106
}
107107

108108
// WithStrikePrice sets strike price to params. Strike Price is the price at which a put or call option can be exercised.
109-
func (o ListOptionsChainParams) WithStrikePrice(strikePrice float64) *ListOptionsChainParams {
110-
o.StrikePrice = &strikePrice
109+
// comparator options include EQ, LT, LTE, GT, and GTE.
110+
// expirationDate should be in YYYY-MM-DD format
111+
func (o ListOptionsChainParams) WithStrikePrice(comparator Comparator, strikePrice float64) *ListOptionsChainParams {
112+
switch comparator {
113+
case EQ:
114+
o.StrikePrice = &strikePrice
115+
case LT:
116+
o.StrikePriceLT = &strikePrice
117+
case LTE:
118+
o.StrikePriceLTE = &strikePrice
119+
case GT:
120+
o.StrikePriceGT = &strikePrice
121+
case GTE:
122+
o.StrikePriceGTE = &strikePrice
123+
default:
124+
o.StrikePrice = &strikePrice
125+
}
111126
return &o
112127
}
113128

rest/models/snapshot_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ func TestListOptionsChainParams(t *testing.T) {
6464
order := models.Asc
6565
expect := models.ListOptionsChainParams{
6666
StrikePrice: &strikePrice,
67+
StrikePriceLT: &strikePrice,
68+
StrikePriceLTE: &strikePrice,
69+
StrikePriceGT: &strikePrice,
70+
StrikePriceGTE: &strikePrice,
6771
ContractType: &contractType,
6872
ExpirationDateEQ: &date,
6973
ExpirationDateLT: &date,
@@ -75,7 +79,11 @@ func TestListOptionsChainParams(t *testing.T) {
7579
Order: &order,
7680
}
7781
actual := models.ListOptionsChainParams{}.
78-
WithStrikePrice(strikePrice).
82+
WithStrikePrice(models.EQ, strikePrice).
83+
WithStrikePrice(models.LT, strikePrice).
84+
WithStrikePrice(models.LTE, strikePrice).
85+
WithStrikePrice(models.GT, strikePrice).
86+
WithStrikePrice(models.GTE, strikePrice).
7987
WithContractType(contractType).
8088
WithExpirationDate(models.EQ, date).
8189
WithExpirationDate(models.LT, date).

0 commit comments

Comments
 (0)