mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-21 15:10:12 +00:00
context: Add authenticated HTTP credentials (#892)
* gRPC: context overide * exchanges: continue update * exchange: Update context handling *Add setter methods for API credentials *Shift credentials functionality to its own file in exchanges package *Add tests *Refactor function DeployCredentialsToContext for library usage *Add function to process credential metadata from API boundary to internal use context value. *Add OTP rpc handling * exchanges: reverts to old style in GetFeeByType, reverts some code I accidently deleted. Plus things and other. XD * template: update * exchanges: fix linter issues * REMOVE THAT AWESOME NEW LINE! * gct: fix some tests * I cant spell :( * exchanges/gctscript: fix more tests * coinnut: fix tests * Update exchanges/credentials.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * Update exchanges/credentials.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * Update exchanges/credentials.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * Update exchanges/credentials.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * Update exchanges/credentials.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * glorious: nits * exchanges/gctcli: stop applying empty credentials * fix linters * exchanges: add test * rpceserver: actually check error for errors * rpcserver: fix up tests * Update exchanges/credentials.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * exchanges/creds: move tests to corresponding files, add protection and segration for Credentials struct & ptr values * exchanges/creds: allow subaccount to override default credentials via gRPC * exchanges/credentials: don't return nil in GetCredentials * creds: spelling * exchanges: fix glorious NITS! * credentials: Add in test and refactor IsEmpty method. * credentials: change type positioning (glorious) * exchange_template: Fix template changes * DOCS: Refresh * docs: fix spelling * DOCS: fix alignment and add package * DOCS: ALIGN! Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
@@ -40,7 +40,7 @@ supplied meet the requirements to make an authenticated request.
|
||||
```go
|
||||
var b bitstamp.Bitstamp
|
||||
b.SetDefaults()
|
||||
ticker, err := b.FetchTicker(currency.NewPair(currency.BTC, currency.USD), asset.Spot)
|
||||
ticker, err := b.FetchTicker(context.Background(), currency.NewPair(currency.BTC, currency.USD), asset.Spot)
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
@@ -53,9 +53,26 @@ supplied meet the requirements to make an authenticated request.
|
||||
var b bitstamp.Bitstamp
|
||||
b.SetDefaults()
|
||||
|
||||
b.API.Credentials.Key = "your_key"
|
||||
b.API.Credentials.Secret = "your_secret"
|
||||
b.API.Credentials.ClientID = "your_clientid"
|
||||
// Set default keys
|
||||
b.API.SetKey("your_key")
|
||||
b.API.SetSecret("your_secret")
|
||||
b.API.SetClientID("your_clientid")
|
||||
b.API.SetPEMKey("your_PEM_key")
|
||||
b.API.SetSubAccount("your_specific_subaccount")
|
||||
|
||||
// Set client/strategy/subsystem specific credentials that will override
|
||||
// default credentials.
|
||||
// Make a standard context and add credentials to it by using exchange
|
||||
// package helper function DeployCredentialsToContext
|
||||
ctx := context.Background()
|
||||
ctx = exchange.DeployCredentialsToContext(ctx, &exchange.Credentials{
|
||||
Key: "your_key",
|
||||
Secret: "your_secret",
|
||||
ClientID: "your_clientid",
|
||||
PEMKey: "your_PEM_key",
|
||||
SubAccount: "your_specific_subaccount",
|
||||
})
|
||||
|
||||
|
||||
o := &order.Submit{
|
||||
Pair: currency.NewPair(currency.BTC, currency.USD),
|
||||
@@ -65,7 +82,9 @@ supplied meet the requirements to make an authenticated request.
|
||||
Amount: 0.1,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
resp, err := b.SubmitOrder(o)
|
||||
|
||||
// Context will be intercepted when sending an authenticated HTTP request.
|
||||
resp, err := b.SubmitOrder(ctx, o)
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user