From 6e0b26c7ed8f67c4bc90c07971af76cf019080eb Mon Sep 17 00:00:00 2001 From: MarketDataApp Date: Tue, 5 Mar 2024 09:50:19 -0300 Subject: [PATCH] added minask,maxask,minbid,maxbid --- README.md | 2 +- helpers/parameters/OptionParams.go | 44 +++++++++++++++ options_chain.go | 89 ++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2cac7af..7bd81c9 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ [![License](https://img.shields.io/github/license/MarketDataApp/sdk-go.svg)](https://github.com/MarketDataApp/sdk-go/blob/master/LICENSE) ![SDK Version](https://img.shields.io/badge/version-1.0.0-blue.svg) ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/MarketDataApp/sdk-go) -![Lines of Code](https://img.shields.io/badge/lines_of_code-8616-blue) +![Lines of Code](https://img.shields.io/badge/lines_of_code-8688-blue) #### Connect With The Market Data Community diff --git a/helpers/parameters/OptionParams.go b/helpers/parameters/OptionParams.go index 67416ff..fa0c6e0 100644 --- a/helpers/parameters/OptionParams.go +++ b/helpers/parameters/OptionParams.go @@ -25,6 +25,10 @@ type OptionParams struct { StrikeLimit int `query:"strikeLimit" validate:"optional"` MinOpenInterest int `query:"minOpenInterest" validate:"optional"` MinVolume int `query:"minVolume" validate:"optional"` + MinAsk float64 `query:"minAsk" validate:"optional"` + MaxAsk float64 `query:"maxAsk" validate:"optional"` + MinBid float64 `query:"minBid" validate:"optional"` + MaxBid float64 `query:"maxBid" validate:"optional"` MaxBidAskSpread float64 `query:"maxBidAskSpread" validate:"optional"` MaxBidAskSpreadPct float64 `query:"maxBidAskSpreadPct" validate:"optional"` // Percent relative to the underlying } @@ -190,6 +194,46 @@ func (op *OptionParams) SetMaxBidAskSpreadPct(maxBidAskSpreadPct float64) error return nil } +// SetMinAsk sets the MinAsk parameter for the OptionParams. +// It validates that the MinAsk is not negative. +func (op *OptionParams) SetMinAsk(minAsk float64) error { + if minAsk < 0 { + return fmt.Errorf("minAsk cannot be negative") + } + op.MinAsk = minAsk + return nil +} + +// SetMaxAsk sets the MaxAsk parameter for the OptionParams. +// It validates that the MaxAsk is not negative. +func (op *OptionParams) SetMaxAsk(maxAsk float64) error { + if maxAsk < 0 { + return fmt.Errorf("maxAsk cannot be negative") + } + op.MaxAsk = maxAsk + return nil +} + +// SetMinBid sets the MinBid parameter for the OptionParams. +// It validates that the MinBid is not negative. +func (op *OptionParams) SetMinBid(minBid float64) error { + if minBid < 0 { + return fmt.Errorf("minBid cannot be negative") + } + op.MinBid = minBid + return nil +} + +// SetMaxBid sets the MaxBid parameter for the OptionParams. +// It validates that the MaxBid is not negative. +func (op *OptionParams) SetMaxBid(maxBid float64) error { + if maxBid < 0 { + return fmt.Errorf("maxBid cannot be negative") + } + op.MaxBid = maxBid + return nil +} + // SetParams sets the parameters for the OptionParams. // If the parsing and setting of parameters fail, it returns an error. func (op *OptionParams) SetParams(request *resty.Request) error { diff --git a/options_chain.go b/options_chain.go index 7d3b4cb..e3f040e 100644 --- a/options_chain.go +++ b/options_chain.go @@ -486,6 +486,95 @@ func (ocr *OptionChainRequest) MaxBidAskSpreadPct(maxBidAskSpreadPct float64) *O return ocr } +// MinAsk sets the MinAsk parameter for the OptionChainRequest. +// This method is used to specify the minimum ask price for options to be included in the option chain. +// It modifies the optionParams field of the OptionChainRequest instance to store the minimum ask price value. +// +// # Parameters +// +// - float64: A float64 representing the minimum ask price to be included in the result. +// +// # Returns +// +// - *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic. +func (ocr *OptionChainRequest) MinAsk(minAsk float64) *OptionChainRequest { + if ocr.optionParams == nil { + ocr.optionParams = ¶meters.OptionParams{} + } + err := ocr.optionParams.SetMinAsk(minAsk) + if err != nil { + ocr.Error = err + } + return ocr +} + +// MaxAsk sets the MaxAsk parameter for the OptionChainRequest. +// This method is used to specify the maximum ask price for options to be included in the option chain. +// It modifies the optionParams field of the OptionChainRequest instance to store the maximum ask price value. +// +// # Parameters +// +// - float64: A float64 representing the maximum ask price to be included in the result. +// +// # Returns +// +// - *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic. +func (ocr *OptionChainRequest) MaxAsk(maxAsk float64) *OptionChainRequest { + if ocr.optionParams == nil { + ocr.optionParams = ¶meters.OptionParams{} + } + err := ocr.optionParams.SetMaxAsk(maxAsk) + if err != nil { + ocr.Error = err + } + return ocr +} + +// MinBid sets the MinBid parameter for the OptionChainRequest. +// This method is used to specify the minimum bid price for options to be included in the option chain. +// It modifies the optionParams field of the OptionChainRequest instance to store the minimum bid price value. +// +// # Parameters +// +// - float64: A float64 representing the minimum bid price to be included in the result. +// +// # Returns +// +// - *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic. +func (ocr *OptionChainRequest) MinBid(minBid float64) *OptionChainRequest { + if ocr.optionParams == nil { + ocr.optionParams = ¶meters.OptionParams{} + } + err := ocr.optionParams.SetMinBid(minBid) + if err != nil { + ocr.Error = err + } + return ocr +} + +// MaxBid sets the MaxBid parameter for the OptionChainRequest. +// This method is used to specify the maximum bid price for options to be included in the option chain. +// It modifies the optionParams field of the OptionChainRequest instance to store the maximum bid price value. +// +// # Parameters +// +// - float64: A float64 representing the maximum bid price to be included in the result. +// +// # Returns +// +// - *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic. +func (ocr *OptionChainRequest) MaxBid(maxBid float64) *OptionChainRequest { + if ocr.optionParams == nil { + ocr.optionParams = ¶meters.OptionParams{} + } + err := ocr.optionParams.SetMaxBid(maxBid) + if err != nil { + ocr.Error = err + } + return ocr +} + + // getParams packs the OptionChainRequest struct into a slice of interface{} and returns it. // This method is used to gather all the parameters set in the OptionChainRequest into a single slice // for easier manipulation and usage in subsequent requests.