Skip to content

Commit

Permalink
added raw() method and docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
MarketDataApp committed Feb 16, 2024
1 parent 44945ed commit bab0149
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 1 deletion.
17 changes: 17 additions & 0 deletions markets_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/MarketDataApp/sdk-go/helpers/parameters"
"github.com/MarketDataApp/sdk-go/models"
"github.com/go-resty/resty/v2"
)

// MarketStatusRequest represents a request to the [/v1/markets/status/] endpoint for market status information.
Expand Down Expand Up @@ -166,6 +167,22 @@ func (msr *MarketStatusRequest) Countback(q int) *MarketStatusRequest {
return msr
}

// Raw executes the MarketStatusRequest and returns the raw *resty.Response.
// This method optionally accepts a *MarketDataClient to use for the request, replacing the default client if provided.
// The *resty.Response can be directly used to access the raw JSON or *http.Response for further processing.
//
// # Parameters
//
// - ...*MarketDataClient: An optional variadic parameter that can accept a *MarketDataClient pointer. If provided, this client is used for the request instead of the default.
//
// # Returns
//
// - *resty.Response: The raw HTTP response from the executed MarketStatusRequest.
// - error: An error object if the MarketStatusRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (msr *MarketStatusRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error) {
return msr.baseRequest.Raw(optionalClients...)
}

// Packed sends the MarketStatusRequest and returns the MarketStatusResponse.
// This method checks if the MarketStatusRequest receiver is nil, returning an error if true.
// An optional MarketDataClient can be passed to replace the client used in the request.
Expand Down
17 changes: 17 additions & 0 deletions options_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/MarketDataApp/sdk-go/helpers/parameters"
"github.com/MarketDataApp/sdk-go/models"
"github.com/go-resty/resty/v2"
)

// OptionChainRequest represents a request to the [/v1/options/chain/] endpoint.
Expand Down Expand Up @@ -502,6 +503,22 @@ func (ocr *OptionChainRequest) getParams() ([]parameters.MarketDataParam, error)
return params, nil
}

// Raw executes the OptionChainRequest and returns the raw *resty.Response.
// This method allows for an optional MarketDataClient to be passed. If provided, it replaces the default client
// used for this request. The *resty.Response can be directly used to access the raw JSON or *http.Response.
//
// # Parameters
//
// - ...*MarketDataClient: A variadic parameter that can accept an optional *MarketDataClient pointer. If provided, this client is used for the request instead of the default.
//
// # Returns
//
// - *resty.Response: The raw HTTP response from the executed OptionChainRequest.
// - error: An error object if the OptionChainRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (ocr *OptionChainRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error) {
return ocr.baseRequest.Raw(optionalClients...)
}

// Packed sends the OptionChainRequest and returns the OptionChainResponse.
// This method checks if the OptionChainRequest receiver is nil, returning an error if true.
// An optional MarketDataClient can be passed to replace the client used in the request.
Expand Down
17 changes: 17 additions & 0 deletions options_expirations.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/MarketDataApp/sdk-go/helpers/parameters"
"github.com/MarketDataApp/sdk-go/models"
"github.com/go-resty/resty/v2"
)

// OptionsExpirationsRequest represents a request for retrieving options expirations data from the [/v1/options/expirations/] endpoint.
Expand Down Expand Up @@ -124,6 +125,22 @@ func (o *OptionsExpirationsRequest) getParams() ([]parameters.MarketDataParam, e
return params, nil
}

// Raw executes the OptionsExpirationsRequest and returns the raw *resty.Response.
// This method allows for an optional MarketDataClient to be passed. If provided, it replaces the default client
// used for this request. The *resty.Response can be used to directly access the raw JSON or *http.Response.
//
// # Parameters
//
// - ...*MarketDataClient: A variadic parameter that can accept an optional *MarketDataClient pointer. If provided, this client is used for the request instead of the default.
//
// # Returns
//
// - *resty.Response: The raw HTTP response from the executed OptionsExpirationsRequest.
// - error: An error object if the OptionsExpirationsRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (oer *OptionsExpirationsRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error) {
return oer.baseRequest.Raw(optionalClients...)
}

// Packed sends the OptionsExpirationsRequest and returns the OptionsExpirationsResponse.
// An optional MarketDataClient can be passed to replace the client used in the request.
//
Expand Down
17 changes: 17 additions & 0 deletions options_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/MarketDataApp/sdk-go/helpers/parameters"
"github.com/MarketDataApp/sdk-go/models"
"github.com/go-resty/resty/v2"
)

// OptionsLookupRequest represents a request to the [/v1/options/lookup/] endpoint for retrieving an OCC-formatted option symbol based on user input.
Expand Down Expand Up @@ -80,6 +81,22 @@ func (o *OptionLookupRequest) getParams() ([]parameters.MarketDataParam, error)
return params, nil
}

// Raw executes the OptionLookupRequest and returns the raw *resty.Response.
// This method optionally accepts a *MarketDataClient to use for the request, replacing the default client if provided.
// The *resty.Response allows access to the raw JSON or *http.Response for further processing.
//
// # Parameters
//
// - ...*MarketDataClient: An optional variadic parameter that can accept a *MarketDataClient pointer. If provided, this client is used for the request instead of the default.
//
// # Returns
//
// - *resty.Response: The raw HTTP response from the executed OptionLookupRequest.
// - error: An error object if the request fails due to being nil, the MarketDataClient being nil, or other execution errors.
func (olr *OptionLookupRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error) {
return olr.baseRequest.Raw(optionalClients...)
}

// Packed sends the OptionLookupRequest and returns the OptionsLookupResponse.
// An optional MarketDataClient can be passed to replace the client used in the request.
//
Expand Down
17 changes: 17 additions & 0 deletions options_quotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/MarketDataApp/sdk-go/helpers/parameters"
"github.com/MarketDataApp/sdk-go/models"
"github.com/go-resty/resty/v2"
)

// OptionQuotesRequest represents a request to the [/v1/options/quotes/] endpoint for retrieving options quotes.
Expand Down Expand Up @@ -151,6 +152,22 @@ func (oqr *OptionQuoteRequest) getParams() ([]parameters.MarketDataParam, error)
return params, nil
}

// Raw executes the OptionQuoteRequest and returns the raw *resty.Response.
// This method allows for an optional MarketDataClient to be passed. If provided, it replaces the default client
// used for the request. The *resty.Response can be used to access the raw JSON or *http.Response directly.
//
// # Parameters
//
// - ...*MarketDataClient: A variadic parameter that can accept an optional *MarketDataClient pointer. If provided, this client is used for the request instead of the default.
//
// # Returns
//
// - *resty.Response: The raw HTTP response from the executed request.
// - error: An error object if the OptionQuoteRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (oqr *OptionQuoteRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error) {
return oqr.baseRequest.Raw(optionalClients...)
}

// Packed sends the OptionQuoteRequest and returns the OptionQuotesResponse.
// An optional MarketDataClient can be passed to replace the client used in the request.
//
Expand Down
17 changes: 17 additions & 0 deletions options_strikes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/MarketDataApp/sdk-go/helpers/parameters"
"github.com/MarketDataApp/sdk-go/models"
"github.com/go-resty/resty/v2"
)

// OptionStrikesRequest represents a request to the [/v1/options/strikes/] endpoint.
Expand Down Expand Up @@ -114,6 +115,22 @@ func (o *OptionStrikesRequest) getParams() ([]parameters.MarketDataParam, error)
return params, nil
}

// Raw executes the OptionStrikesRequest and returns the raw *resty.Response.
// This method allows for an optional MarketDataClient to be passed. If provided, this client replaces the one currently
// attached to the OptionStrikesRequest. The *resty.Response can be used to directly access the raw JSON or *http.Response.
//
// # Parameters
//
// - ...*MarketDataClient: A variadic parameter that can accept an optional *MarketDataClient pointer. If provided, this client is used for the request instead of the default.
//
// # Returns
//
// - *resty.Response: The raw HTTP response from the executed OptionStrikesRequest.
// - error: An error object if the OptionStrikesRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (osr *OptionStrikesRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error) {
return osr.baseRequest.Raw(optionalClients...)
}

// Packed sends the OptionStrikesRequest and returns the OptionStrikesResponse.
// An optional MarketDataClient can be passed to replace the client used in the request.
//
Expand Down
17 changes: 17 additions & 0 deletions stocks_bulkcandles.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/MarketDataApp/sdk-go/helpers/parameters"
"github.com/MarketDataApp/sdk-go/models"
"github.com/go-resty/resty/v2"
)

// BulkStockCandlesRequest represents a request to the [/v1/stocks/bulkcandles/] endpoint.
Expand Down Expand Up @@ -159,6 +160,22 @@ func (bscr *BulkStockCandlesRequest) getParams() ([]parameters.MarketDataParam,
return params, nil
}

// Raw executes the request and returns the raw *resty.Response.
// This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client that is currently
// attached to the request. Using the *resty.Response, it is possible to obtain the raw JSON or *http.Response.
//
// # Parameters
//
// - ...*MarketDataClient: A variadic parameter that can accept an optional *MarketDataClient pointer. If provided, it replaces the current *MarketDataClient for this request.
//
// # Returns
//
// - *resty.Response: The raw response from the executed request.
// - error: An error object if the request is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (bscr *BulkStockCandlesRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error) {
return bscr.baseRequest.Raw(optionalClients...)
}

// Packed sends the BulkStockCandlesRequest and returns the StockCandlesResponse.
// An optional MarketDataClient can be passed to replace the client used in the request.
//
Expand Down
11 changes: 11 additions & 0 deletions stocks_bulkcandles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,14 @@ func ExampleBulkStockCandlesRequest_get() {
// Candle{Symbol: MSFT, Date: 2024-02-06, Open: 405.88, High: 407.97, Low: 402.91, Close: 405.49, Volume: 18382624}

}

func ExampleBulkStockCandlesRequest_raw() {
symbols := []string{"AAPL", "META", "MSFT"}
bscr, err := BulkStockCandles().Resolution("D").Symbols(symbols).Date("2024-02-06").Raw()
if err != nil {
fmt.Print(err)
return
}
fmt.Println(bscr)
// Output: {"s":"ok","symbol":["AAPL","META","MSFT"],"o":[186.86,464.0,405.88],"h":[189.31,467.12,407.97],"l":[186.7695,453.0,402.91],"c":[189.3,454.72,405.49],"v":[43490759,21653114,18382624],"t":[1707195600,1707195600,1707195600]}
}
17 changes: 17 additions & 0 deletions stocks_bulkquotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/MarketDataApp/sdk-go/helpers/parameters"
"github.com/MarketDataApp/sdk-go/models"
"github.com/go-resty/resty/v2"
)

// BulkStockQuotesRequest represents a request to the [v1/stocks/bulkquotes/] endpoint.
Expand Down Expand Up @@ -95,6 +96,22 @@ func (bs *BulkStockQuotesRequest) getParams() ([]parameters.MarketDataParam, err
return params, nil
}

// Raw executes the request for BulkStockQuotesRequest and returns the raw *resty.Response.
// This method allows for an optional MarketDataClient to be passed. If provided, this client replaces the one currently
// attached to the BulkStockQuotesRequest. The *resty.Response enables access to the raw JSON or *http.Response.
//
// # Parameters
//
// - ...*MarketDataClient: A variadic parameter that can accept an optional *MarketDataClient pointer. If provided, this client replaces the current *MarketDataClient for this BulkStockQuotesRequest.
//
// # Returns
//
// - *resty.Response: The raw response from the executed BulkStockQuotesRequest.
// - error: An error object if the BulkStockQuotesRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (bsqr *BulkStockQuotesRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error) {
return bsqr.baseRequest.Raw(optionalClients...)
}

// Packed sends the BulkStockQuotesRequest and returns the StockQuotesResponse.
// An optional MarketDataClient can be passed to replace the client used in the request.
//
Expand Down
80 changes: 79 additions & 1 deletion stocks_bulkquotes_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,89 @@
package client

import (
"encoding/json"
"fmt"
"log"
"testing"
"time"
)

func ExampleBulkStockQuotesRequest_get() {
// This example demonstrates how to create a BulkStockQuotesRequest, set its parameters,
// and perform an actual request to fetch stock quotes for multiple symbols.

// Initialize a new BulkStockQuotesRequest and fetch stock quotes for "AAPL", "META", and "MSFT".
symbols := []string{"AAPL", "META", "MSFT"}
bsqr, err := BulkStockQuotes().Symbols(symbols).Get()
if err != nil {
log.Fatalf("Failed to get bulk stock quotes: %v", err)
}

// Check if the response contains the symbols.
for _, quote := range bsqr {
fmt.Printf("Symbol: %s\n", quote.Symbol)
}
// Output: Symbol: AAPL
// Symbol: META
// Symbol: MSFT
}

func ExampleBulkStockQuotesRequest_packed() {
// This example demonstrates how to create a BulkStockQuotesRequest, set its parameters,
// and perform an actual request to fetch stock quotes for multiple symbols: "AAPL", "META", and "MSFT".

// Initialize a new BulkStockQuotesRequest and fetch stock quotes for the specified symbols.
symbols := []string{"AAPL", "META", "MSFT"}
bsqr, err := BulkStockQuotes().Symbols(symbols).Packed()
if err != nil {
log.Fatalf("Failed to get bulk stock quotes: %v", err)
}

// Iterate and print all the symbols in the response.
for _, symbol := range bsqr.Symbol {
fmt.Printf("Symbol: %s\n", symbol)
}
// Output: Symbol: AAPL
// Symbol: META
// Symbol: MSFT
}

func ExampleBulkStockQuotesRequest_raw() {
// This example demonstrates how to create a BulkStockQuotesRequest, set its parameters,
// and perform an actual request to fetch stock quotes for multiple symbols: "AAPL", "META", and "MSFT".
// The response is converted to a raw string and we print out the string at the end of the test.

// Initialize a new BulkStockQuotesRequest and fetch stock quotes for "AAPL", "META", and "MSFT".
symbols := []string{"AAPL", "META", "MSFT"}
bsqr, err := BulkStockQuotes().Symbols(symbols).Raw()
if err != nil {
log.Fatalf("Failed to get bulk stock quotes: %v", err)
}

// Convert the response to a string.
jsonStr := bsqr.String()

// Define a struct to match the JSON structure
type Response struct {
Symbol []string `json:"symbol"`
}

// Unmarshal the JSON into the struct
var resp Response
err = json.Unmarshal([]byte(jsonStr), &resp)
if err != nil {
log.Fatalf("Failed to parse JSON: %v", err)
}

// Print the symbols
for _, symbol := range resp.Symbol {
fmt.Printf("Symbol: %s\n", symbol)
}
// Output: Symbol: AAPL
// Symbol: META
// Symbol: MSFT
}

func TestBulkStockQuotesRequest_packed(t *testing.T) {
//client, _ := GetClient()
//client.Debug(true)
Expand All @@ -29,4 +107,4 @@ func TestBulkStockQuotesRequest_packed(t *testing.T) {
t.Errorf("Quote for symbol %s was not updated within the last 7 days", quote.Symbol)
}
}
}
}
17 changes: 17 additions & 0 deletions stocks_candles.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/MarketDataApp/sdk-go/helpers/parameters"
"github.com/MarketDataApp/sdk-go/models"
"github.com/go-resty/resty/v2"
)

// StockCandlesRequest represents a request to the [/v1/stocks/candles/] endpoint.
Expand Down Expand Up @@ -255,6 +256,22 @@ func (scr *StockCandlesRequest) getParams() ([]parameters.MarketDataParam, error
return params, nil
}

// Raw executes the StockCandlesRequest and returns the raw *resty.Response.
// This method optionally accepts a *MarketDataClient to use for the request, replacing the default client if provided.
// The *resty.Response allows access to the raw JSON or *http.Response for further processing.
//
// # Parameters
//
// - ...*MarketDataClient: An optional variadic parameter that can accept a *MarketDataClient pointer. If provided, this client is used for the request instead of the default.
//
// # Returns
//
// - *resty.Response: The raw HTTP response from the executed request.
// - error: An error object if the request fails due to being nil, the MarketDataClient being nil, or other execution errors.
func (scr *StockCandlesRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error) {
return scr.baseRequest.Raw(optionalClients...)
}

// Packed sends the StockCandlesRequest and returns the StockCandlesResponse.
// An optional MarketDataClient can be passed to replace the client used in the request.
//
Expand Down
Loading

0 comments on commit bab0149

Please sign in to comment.