@@ -34,6 +34,7 @@ import (
34
34
"strconv"
35
35
"sync"
36
36
"time"
37
+ "context"
37
38
38
39
"github.com/go-resty/resty/v2"
39
40
_ "github.com/joho/godotenv/autoload"
@@ -349,7 +350,7 @@ func (c *MarketDataClient) updateRateLimit(resp *resty.Response) {
349
350
350
351
// prepareAndExecuteRequest prepares the request based on the provided baseRequest and executes it.
351
352
// It returns the response from the server or an error if the request preparation or execution fails.
352
- func (c * MarketDataClient ) prepareAndExecuteRequest (br * baseRequest , result interface {}) (* resty.Response , error ) {
353
+ func (c * MarketDataClient ) prepareAndExecuteRequest (ctx context. Context , br * baseRequest , result interface {}) (* resty.Response , error ) {
353
354
354
355
// Check for any errors in the base request.
355
356
if err := br .getError (); err != nil {
@@ -385,6 +386,9 @@ func (c *MarketDataClient) prepareAndExecuteRequest(br *baseRequest, result inte
385
386
return nil , err
386
387
}
387
388
389
+ // Use the provided context for the request
390
+ req = req .SetContext (ctx )
391
+
388
392
// Execute the GET request to the specified path.
389
393
resp , err := req .Get (path )
390
394
if err != nil {
@@ -419,9 +423,9 @@ func (c *MarketDataClient) prepareAndExecuteRequest(br *baseRequest, result inte
419
423
//
420
424
// - A pointer to a resty.Response object containing the response from the server.
421
425
// - An error object if an error occurred during the request execution or if the response contains an error.
422
- func (c * MarketDataClient ) getFromRequest (br * baseRequest , result interface {}) (* resty.Response , error ) {
426
+ func (c * MarketDataClient ) getFromRequest (ctx context. Context , br * baseRequest , result interface {}) (* resty.Response , error ) {
423
427
// Execute the prepared request and capture the response and any error.
424
- resp , err := c .prepareAndExecuteRequest (br , result )
428
+ resp , err := c .prepareAndExecuteRequest (ctx , br , result )
425
429
if err != nil {
426
430
// Return the response and the error if an error occurred during request execution.
427
431
return resp , err
@@ -442,14 +446,15 @@ func (c *MarketDataClient) getFromRequest(br *baseRequest, result interface{}) (
442
446
//
443
447
// # Parameters
444
448
//
449
+ // - ctx: A context.Context object to control the request's lifecycle.
445
450
// - br: A pointer to a baseRequest object containing the request details.
446
451
//
447
452
// # Returns
448
453
//
449
454
// - A pointer to a resty.Response object containing the raw response from the server.
450
455
// - An error object if an error occurred during the request execution.
451
- func (c * MarketDataClient ) getRawResponse (br * baseRequest ) (* resty.Response , error ) {
452
- return c .prepareAndExecuteRequest (br , nil )
456
+ func (c * MarketDataClient ) getRawResponse (ctx context. Context , br * baseRequest ) (* resty.Response , error ) {
457
+ return c .prepareAndExecuteRequest (ctx , br , nil )
453
458
}
454
459
455
460
// GetClient checks for an existing instance of MarketDataClient and returns it.
0 commit comments