Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update options snapshot example with params #405

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions rest/example/options/snapshots-options-chain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ func main() {
c := polygon.New(os.Getenv("POLYGON_API_KEY"))

// set params
params := &models.ListOptionsChainParams{
UnderlyingAsset: "AAPL",
}
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 request
iter := c.ListOptionsChainSnapshot(context.Background(), params)
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
Loading