Skip to content

Commit

Permalink
Update to gdax 0.6.0 (coinbase#155)
Browse files Browse the repository at this point in the history
* Update to [email protected].

The 0.5.1 wasn't tagged in git, however, the commit with a message of
'v0.5.1' is b708da1.

$ git log 32360ad..b708da1

The most complicated commit is 7c536d9 which normalizes PublicClient
with AuthenticatedClient.

* Update to [email protected].
  • Loading branch information
blair authored and CjS77 committed Mar 13, 2018
1 parent ebb9ca6 commit de88809
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 81 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"bintrees": "1.0.1",
"ccxt": "1.10.641",
"commander": "2.9.0",
"gdax": "https://github.com/coinbase/gdax-node.git#32360ad73517f168054585a1b0fd6ae3d7e12a77",
"gdax": "0.6.0",
"limiter": "git://github.com/jhurliman/node-rate-limiter.git#58ce2fda6b5c2bc4ccb81ba3768c5b1bc06c91a5",
"node-bittrex-api": "0.7.7",
"pushbullet": "2.0.0",
Expand Down
31 changes: 7 additions & 24 deletions src/exchanges/gdax/GDAXExchangeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,13 @@ interface OrderPage {
orders: BaseOrderInfo[];
}

interface PublicClients {
default: PublicClient;

[product: string]: PublicClient;
}

export class GDAXExchangeAPI implements PublicExchangeAPI, AuthenticatedExchangeAPI, ExchangeTransferAPI {
owner: string;
quoteCurrency: string;
baseCurrency: string;
private coinbaseAccounts: CoinbaseAccount[];
private _apiURL: string;
private publicClients: PublicClients;
private publicClient: PublicClient;
private authClient: AuthenticatedClient;
private auth: GDAXAuthConfig;
private logger: Logger;
Expand All @@ -61,8 +55,7 @@ export class GDAXExchangeAPI implements PublicExchangeAPI, AuthenticatedExchange
if (this.auth) {
this.authClient = new AuthenticatedClient(this.auth.key, this.auth.secret, this.auth.passphrase, this._apiURL);
}
this.publicClients = {default: new PublicClient('BTC-USD', this._apiURL)};
this.publicClients['BTC-USD'] = this.publicClients.default;
this.publicClient = new PublicClient(this._apiURL);
}

get apiURL(): string {
Expand All @@ -77,7 +70,7 @@ export class GDAXExchangeAPI implements PublicExchangeAPI, AuthenticatedExchange
}

loadProducts(): Promise<Product[]> {
return this.getPublicClient().getProducts()
return this.publicClient.getProducts()
.then((products: ProductInfo[]) => {
return products.map((prod: ProductInfo) => {
return {
Expand Down Expand Up @@ -117,7 +110,7 @@ export class GDAXExchangeAPI implements PublicExchangeAPI, AuthenticatedExchange

loadGDAXOrderbook(options: OrderbookEndpointParams): Promise<any> {
const {product, ...params} = options;
return this.getPublicClient(product).getProductOrderBook(params)
return this.publicClient.getProductOrderBook(product, params)
.then((orders) => {
if (!(orders.bids && orders.asks)) {
return Promise.reject(new HTTPError(`Error loading ${product} orderbook from GDAX`, {status: 200, body: orders}));
Expand All @@ -129,7 +122,7 @@ export class GDAXExchangeAPI implements PublicExchangeAPI, AuthenticatedExchange
}

loadTicker(product: string): Promise<Ticker> {
return this.getPublicClient(product).getProductTicker()
return this.publicClient.getProductTicker(product)
.then((ticker: ProductTicker) => {
return {
productId: product,
Expand All @@ -138,7 +131,7 @@ export class GDAXExchangeAPI implements PublicExchangeAPI, AuthenticatedExchange
price: Big(ticker.price || 0),
size: Big(ticker.size || 0),
volume: Big(ticker.volume || 0),
time: new Date(ticker.time || new Date()),
time: ticker.time ? new Date(ticker.time) : new Date(),
trade_id: ticker.trade_id ? ticker.trade_id.toString() : '0'
};
}).catch((err: GDAXHTTPError) => {
Expand All @@ -151,7 +144,7 @@ export class GDAXExchangeAPI implements PublicExchangeAPI, AuthenticatedExchange
if (!product) {
return Promise.reject(new Error('No product ID provided to loadCandles'));
}
return this.getPublicClient(product).getProductHistoricRates({
return this.publicClient.getProductHistoricRates(product, {
granularity: IntervalInMS[options.interval] * 0.001,
limit: options.limit || 350
}).then((data: any[][]) => {
Expand Down Expand Up @@ -529,16 +522,6 @@ export class GDAXExchangeAPI implements PublicExchangeAPI, AuthenticatedExchange
};
});
}

private getPublicClient(product?: string): PublicClient {
if (!product) {
return this.publicClients.default;
}
if (!this.publicClients[product]) {
this.publicClients[product] = new PublicClient(product, this._apiURL);
}
return this.publicClients[product];
}
}

function GDAXOrderResultToOrder(order: OrderResult): LiveOrder {
Expand Down
106 changes: 50 additions & 56 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ [email protected]:
version "4.0.2"
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-4.0.2.tgz#2d1dc37ee5968867ecea90b6da4d16e68608d21d"

bignumber.js@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-5.0.0.tgz#fbce63f09776b3000a83185badcde525daf34833"

bindings@~1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.2.1.tgz#14ad6113812d2d37d72e67b4cacb4bb726505f11"
Expand All @@ -360,6 +364,10 @@ [email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/bintrees/-/bintrees-1.0.1.tgz#0e655c9b9c2435eaab68bf4027226d2b55a34524"

bintrees@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/bintrees/-/bintrees-1.0.2.tgz#49f896d6e858a4a499df85c38fb399b9aff840f8"

bl@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/bl/-/bl-1.1.2.tgz#fdca871a99713aa00d19e3bbba41c44787a65398"
Expand Down Expand Up @@ -945,14 +953,14 @@ fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"

"gdax@https://github.com/coinbase/gdax-node.git#32360ad73517f168054585a1b0fd6ae3d7e12a77":
version "0.5.0"
resolved "https://github.com/coinbase/gdax-node.git#32360ad73517f168054585a1b0fd6ae3d7e12a77"
gdax@0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/gdax/-/gdax-0.6.0.tgz#185184852035f5b8607abbd9468e0678fcf0881f"
dependencies:
bintrees "1.0.1"
num "0.3.0"
request "2.81.0"
ws "3.0.0"
bignumber.js "^5.0.0"
bintrees "^1.0.1"
request "^2.81.0"
ws "^4.0.0"

generate-function@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -1228,10 +1236,6 @@ ini@^1.3.4:
version "1.3.4"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.4.tgz#0537cb79daf59b59a1a517dff706c86ec039162e"

[email protected]:
version "0.2.0"
resolved "https://registry.yarnpkg.com/int/-/int-0.2.0.tgz#589f05b03b8d8c08c918c8884784cb62a94ef47e"

interpret@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.0.3.tgz#cbc35c62eeee73f19ab7b10a801511401afc0f90"
Expand Down Expand Up @@ -1921,12 +1925,6 @@ npm-run-path@^2.0.0:
dependencies:
path-key "^2.0.0"

[email protected]:
version "0.3.0"
resolved "https://registry.yarnpkg.com/num/-/num-0.3.0.tgz#a82e2a9b1fc52fbab313358cdf92905e6f03f287"
dependencies:
int "0.2.0"

number-is-nan@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"
Expand Down Expand Up @@ -2302,33 +2300,6 @@ repeating@^2.0.0:
dependencies:
is-finite "^1.0.0"

[email protected], request@^2.79.0:
version "2.81.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0"
dependencies:
aws-sign2 "~0.6.0"
aws4 "^1.2.1"
caseless "~0.12.0"
combined-stream "~1.0.5"
extend "~3.0.0"
forever-agent "~0.6.1"
form-data "~2.1.1"
har-validator "~4.2.1"
hawk "~3.1.3"
http-signature "~1.1.0"
is-typedarray "~1.0.0"
isstream "~0.1.2"
json-stringify-safe "~5.0.1"
mime-types "~2.1.7"
oauth-sign "~0.8.1"
performance-now "^0.2.0"
qs "~6.4.0"
safe-buffer "^5.0.1"
stringstream "~0.0.4"
tough-cookie "~2.3.0"
tunnel-agent "^0.6.0"
uuid "^3.0.0"

"request@>= 2.35.0":
version "2.74.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.74.0.tgz#7693ca768bbb0ea5c8ce08c084a45efa05b892ab"
Expand All @@ -2355,7 +2326,7 @@ [email protected], request@^2.79.0:
tough-cookie "~2.3.0"
tunnel-agent "~0.4.1"

request@^2.49.0:
request@^2.49.0, request@^2.81.0:
version "2.83.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.83.0.tgz#ca0b65da02ed62935887808e6f510381034e3356"
dependencies:
Expand All @@ -2382,6 +2353,33 @@ request@^2.49.0:
tunnel-agent "^0.6.0"
uuid "^3.1.0"

request@^2.79.0:
version "2.81.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0"
dependencies:
aws-sign2 "~0.6.0"
aws4 "^1.2.1"
caseless "~0.12.0"
combined-stream "~1.0.5"
extend "~3.0.0"
forever-agent "~0.6.1"
form-data "~2.1.1"
har-validator "~4.2.1"
hawk "~3.1.3"
http-signature "~1.1.0"
is-typedarray "~1.0.0"
isstream "~0.1.2"
json-stringify-safe "~5.0.1"
mime-types "~2.1.7"
oauth-sign "~0.8.1"
performance-now "^0.2.0"
qs "~6.4.0"
safe-buffer "^5.0.1"
stringstream "~0.0.4"
tough-cookie "~2.3.0"
tunnel-agent "^0.6.0"
uuid "^3.0.0"

require-directory@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
Expand Down Expand Up @@ -2424,10 +2422,6 @@ safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853"

safe-buffer@~5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.0.1.tgz#d263ca54696cd8a306b5ca6551e92de57918fbe7"

"semver@2 || 3 || 4 || 5", semver@^5.3.0:
version "5.4.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"
Expand Down Expand Up @@ -2980,13 +2974,6 @@ write-file-atomic@^1.1.4:
imurmurhash "^0.1.4"
slide "^1.1.5"

[email protected]:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-3.0.0.tgz#98ddb00056c8390cb751e7788788497f99103b6c"
dependencies:
safe-buffer "~5.0.1"
ultron "~1.1.0"

[email protected]:
version "3.3.1"
resolved "https://registry.yarnpkg.com/ws/-/ws-3.3.1.tgz#d97e34dee06a1190c61ac1e95f43cb60b78cf939"
Expand All @@ -2995,6 +2982,13 @@ [email protected]:
safe-buffer "~5.1.0"
ultron "~1.1.0"

ws@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-4.1.0.tgz#a979b5d7d4da68bf54efe0408967c324869a7289"
dependencies:
async-limiter "~1.0.0"
safe-buffer "~5.1.0"

xtend@^4.0.0, xtend@~4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"
Expand Down

0 comments on commit de88809

Please sign in to comment.