request

package
v0.0.0-...-eb07c7e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2019 License: MIT Imports: 14 Imported by: 0

README

GoCryptoTrader package Request

Build Status Software License GoDoc Coverage Status Go Report Card

This request package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progresss on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Current Features for request

  • This package services the exchanges package with request handling.
    • Throttling of requests for an individual exchange
Please click GoDocs chevron above to view current GoDoc information for this package

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidMethod

func IsValidMethod(method string) bool

IsValidMethod returns whether the supplied method is supported

Types

type Job

type Job struct {
	Request       *http.Request
	Method        string
	Path          string
	Headers       map[string]string
	Body          io.Reader
	Result        interface{}
	JobResult     chan *JobResult
	AuthRequest   bool
	Verbose       bool
	HTTPDebugging bool
}

Job holds a request job

type JobResult

type JobResult struct {
	Error  error
	Result interface{}
}

JobResult holds a request job result

type RateLimit

type RateLimit struct {
	Duration time.Duration
	Rate     int
	Requests int
	Mutex    sync.Mutex
}

RateLimit struct

func NewRateLimit

func NewRateLimit(d time.Duration, rate int) *RateLimit

NewRateLimit creates a new RateLimit

func (*RateLimit) GetDuration

func (r *RateLimit) GetDuration() time.Duration

GetDuration gets the duration for the ratelimit

func (*RateLimit) GetRate

func (r *RateLimit) GetRate() int

GetRate returns the ratelimit rate

func (*RateLimit) GetRequests

func (r *RateLimit) GetRequests() int

GetRequests returns the number of requests for the ratelimit

func (*RateLimit) SetDuration

func (r *RateLimit) SetDuration(d time.Duration)

SetDuration sets the duration for the ratelimit

func (*RateLimit) SetRate

func (r *RateLimit) SetRate(rate int)

SetRate sets the ratelimit rate

func (*RateLimit) SetRequests

func (r *RateLimit) SetRequests(l int)

SetRequests sets requests counter for the rateliit

func (*RateLimit) ToString

func (r *RateLimit) ToString() string

ToString returns the rate limiter in string notation

type Requester

type Requester struct {
	HTTPClient  *http.Client
	UnauthLimit *RateLimit
	AuthLimit   *RateLimit
	Name        string
	UserAgent   string
	Cycle       time.Time

	Jobs chan Job

	WorkerStarted bool
	Nonce         nonce.Nonce
	// contains filtered or unexported fields
}

Requester struct for the request client

func New

func New(name string, authLimit, unauthLimit *RateLimit, httpRequester *http.Client) *Requester

New returns a new Requester

func (*Requester) DecrementRequests

func (r *Requester) DecrementRequests(auth bool)

DecrementRequests decrements the ratelimiter request counter for either auth or unauth requests

func (*Requester) DoRequest

func (r *Requester) DoRequest(req *http.Request, path string, body io.Reader, result interface{}, authRequest, verbose, httpDebug bool) error

DoRequest performs a HTTP/HTTPS request with the supplied params

func (*Requester) GetNonce

func (r *Requester) GetNonce(isNano bool) nonce.Value

GetNonce returns a nonce for requests. This locks and enforces concurrent nonce FIFO on the buffered job channel

func (*Requester) GetNonceMilli

func (r *Requester) GetNonceMilli() nonce.Value

GetNonceMilli returns a nonce for requests. This locks and enforces concurrent nonce FIFO on the buffered job channel this is for millisecond

func (*Requester) GetRateLimit

func (r *Requester) GetRateLimit(auth bool) *RateLimit

GetRateLimit gets the request Requester ratelimiter

func (*Requester) IncrementRequests

func (r *Requester) IncrementRequests(auth bool)

IncrementRequests increments the ratelimiter request counter for either auth or unauth requests

func (*Requester) IsRateLimited

func (r *Requester) IsRateLimited(auth bool) bool

IsRateLimited returns whether or not the request Requester is rate limited

func (*Requester) IsValidCycle

func (r *Requester) IsValidCycle(auth bool) bool

IsValidCycle checks to see whether the current request cycle is valid or not

func (*Requester) RequiresRateLimiter

func (r *Requester) RequiresRateLimiter() bool

RequiresRateLimiter returns whether or not the request Requester requires a rate limiter

func (*Requester) SendPayload

func (r *Requester) SendPayload(method, path string, headers map[string]string, body io.Reader, result interface{}, authRequest, nonceEnabled, verbose, httpDebugging bool) error

SendPayload handles sending HTTP/HTTPS requests

func (*Requester) SetProxy

func (r *Requester) SetProxy(p *url.URL) error

SetProxy sets a proxy address to the client transport

func (*Requester) SetRateLimit

func (r *Requester) SetRateLimit(auth bool, duration time.Duration, rate int)

SetRateLimit sets the request Requester ratelimiter

func (*Requester) SetTimeoutRetryAttempts

func (r *Requester) SetTimeoutRetryAttempts(n int) error

SetTimeoutRetryAttempts sets the amount of times the job will be retried if it times out

func (*Requester) StartCycle

func (r *Requester) StartCycle()

StartCycle restarts the cycle time and requests counters

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL