Skip to content

Commit

Permalink
Update ListOptionsChainParams.WithStrikePrice to support comparators (#…
Browse files Browse the repository at this point in the history
…414)

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
justinpolygon and actions-user authored May 8, 2024
1 parent 4813bd5 commit 1bc789b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Polygon Go Client
![Coverage](https://img.shields.io/badge/Coverage-76.6%25-brightgreen)
![Coverage](https://img.shields.io/badge/Coverage-76.7%25-brightgreen)

<!-- todo: add a codecov badge -->
<!-- todo: figure out a way to show all build statuses -->
Expand Down
13 changes: 8 additions & 5 deletions rest/example/options/snapshots-options-chain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ func main() {
c := polygon.New(os.Getenv("POLYGON_API_KEY"))

// set params
params := &models.ListOptionsChainParams{
UnderlyingAsset: "AAPL",
}

// make request
params := models.ListOptionsChainParams{
UnderlyingAsset: "SPY",
StrikePriceGTE: new(float64),
StrikePriceLTE: new(float64),
Limit: new(int),
}.WithStrikePrice("gte", 500.00).WithStrikePrice("lte", 600.00).WithLimit(250)

// make the request
iter := c.ListOptionsChainSnapshot(context.Background(), params)

// do something with the result
Expand Down
19 changes: 17 additions & 2 deletions rest/models/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,23 @@ type ListOptionsChainParams struct {
}

// WithStrikePrice sets strike price to params. Strike Price is the price at which a put or call option can be exercised.
func (o ListOptionsChainParams) WithStrikePrice(strikePrice float64) *ListOptionsChainParams {
o.StrikePrice = &strikePrice
// comparator options include EQ, LT, LTE, GT, and GTE.
// expirationDate should be in YYYY-MM-DD format
func (o ListOptionsChainParams) WithStrikePrice(comparator Comparator, strikePrice float64) *ListOptionsChainParams {
switch comparator {
case EQ:
o.StrikePrice = &strikePrice
case LT:
o.StrikePriceLT = &strikePrice
case LTE:
o.StrikePriceLTE = &strikePrice
case GT:
o.StrikePriceGT = &strikePrice
case GTE:
o.StrikePriceGTE = &strikePrice
default:
o.StrikePrice = &strikePrice
}
return &o
}

Expand Down
10 changes: 9 additions & 1 deletion rest/models/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func TestListOptionsChainParams(t *testing.T) {
order := models.Asc
expect := models.ListOptionsChainParams{
StrikePrice: &strikePrice,
StrikePriceLT: &strikePrice,
StrikePriceLTE: &strikePrice,
StrikePriceGT: &strikePrice,
StrikePriceGTE: &strikePrice,
ContractType: &contractType,
ExpirationDateEQ: &date,
ExpirationDateLT: &date,
Expand All @@ -75,7 +79,11 @@ func TestListOptionsChainParams(t *testing.T) {
Order: &order,
}
actual := models.ListOptionsChainParams{}.
WithStrikePrice(strikePrice).
WithStrikePrice(models.EQ, strikePrice).
WithStrikePrice(models.LT, strikePrice).
WithStrikePrice(models.LTE, strikePrice).
WithStrikePrice(models.GT, strikePrice).
WithStrikePrice(models.GTE, strikePrice).
WithContractType(contractType).
WithExpirationDate(models.EQ, date).
WithExpirationDate(models.LT, date).
Expand Down

0 comments on commit 1bc789b

Please sign in to comment.