Skip to content
This repository has been archived by the owner on Jan 20, 2020. It is now read-only.

Commit

Permalink
Simplify auth object to key, secret, passphrase (#151)
Browse files Browse the repository at this point in the history
This more consistent usage allows an AuthenticatedClient instance to be used
in place of an auth object
  • Loading branch information
rmm5t authored and fb55 committed Dec 24, 2017
1 parent 913cd31 commit 17619ca
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ the API URI (defaults to `https://api.gdax.com`).

```js
const key = 'your_api_key';
const b64secret = 'your_b64_secret';
const secret = 'your_b64_secret';
const passphrase = 'your_passphrase';

const apiURI = 'https://api.gdax.com';
const sandboxURI = 'https://api-public.sandbox.gdax.com';

const authedClient = new Gdax.AuthenticatedClient(key, b64secret, passphrase, apiURI);
const authedClient = new Gdax.AuthenticatedClient(key, secret, passphrase, apiURI);
```

Like `PublicClient`, all API methods can be used with either callbacks or will
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ declare module 'gdax' {
}

export class AuthenticatedClient {
constructor(key: string, b64secret: string, passphrase: string, apiURI: string);
constructor(key: string, secret: string, passphrase: string, apiURI: string);

getCoinbaseAccounts(callback: callback<CoinbaseAccount[]>)
getCoinbaseAccounts(): Promise<CoinbaseAccount[]>;
Expand Down
11 changes: 3 additions & 8 deletions lib/clients/authenticated.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const { signRequest } = require('../../lib/request_signer');
const PublicClient = require('./public.js');

class AuthenticatedClient extends PublicClient {
constructor(key, b64secret, passphrase, apiURI) {
constructor(key, secret, passphrase, apiURI) {
super('', apiURI);
this.key = key;
this.b64secret = b64secret;
this.secret = secret;
this.passphrase = passphrase;
}

Expand All @@ -29,12 +29,7 @@ class AuthenticatedClient extends PublicClient {
}

_getSignature(method, relativeURI, opts) {
const auth = {
key: this.key,
secret: this.b64secret,
passphrase: this.passphrase,
};
const sig = signRequest(auth, method, relativeURI, opts);
const sig = signRequest(this, method, relativeURI, opts);

if (opts.body) {
opts.body = JSON.stringify(opts.body);
Expand Down
11 changes: 1 addition & 10 deletions lib/orderbook_sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@ class OrderbookSync extends WebsocketClient {
authenticatedClient = null,
{ heartbeat = false } = {}
) {
let auth = null;
if (authenticatedClient) {
auth = {
key: authenticatedClient.key,
secret: authenticatedClient.b64secret,
passphrase: authenticatedClient.passphrase,
};
}

super(productIDs, websocketURI, auth, { heartbeat });
super(productIDs, websocketURI, authenticatedClient, { heartbeat });
this.apiURI = apiURI;
this.authenticatedClient = authenticatedClient;

Expand Down

0 comments on commit 17619ca

Please sign in to comment.