diff --git a/package.json b/package.json index 1f999da5..919f8312 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/exchanges/gdax/GDAXExchangeAPI.ts b/src/exchanges/gdax/GDAXExchangeAPI.ts index a94f21e8..f3339d62 100644 --- a/src/exchanges/gdax/GDAXExchangeAPI.ts +++ b/src/exchanges/gdax/GDAXExchangeAPI.ts @@ -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; @@ -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 { @@ -77,7 +70,7 @@ export class GDAXExchangeAPI implements PublicExchangeAPI, AuthenticatedExchange } loadProducts(): Promise { - return this.getPublicClient().getProducts() + return this.publicClient.getProducts() .then((products: ProductInfo[]) => { return products.map((prod: ProductInfo) => { return { @@ -117,7 +110,7 @@ export class GDAXExchangeAPI implements PublicExchangeAPI, AuthenticatedExchange loadGDAXOrderbook(options: OrderbookEndpointParams): Promise { 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})); @@ -129,7 +122,7 @@ export class GDAXExchangeAPI implements PublicExchangeAPI, AuthenticatedExchange } loadTicker(product: string): Promise { - return this.getPublicClient(product).getProductTicker() + return this.publicClient.getProductTicker(product) .then((ticker: ProductTicker) => { return { productId: product, @@ -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) => { @@ -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[][]) => { @@ -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 { diff --git a/yarn.lock b/yarn.lock index 63c43ae3..84c9ee0d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -352,6 +352,10 @@ bignumber.js@4.0.2: 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" @@ -360,6 +364,10 @@ bintrees@1.0.1: 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" @@ -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" @@ -1228,10 +1236,6 @@ ini@^1.3.4: version "1.3.4" resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.4.tgz#0537cb79daf59b59a1a517dff706c86ec039162e" -int@0.2.0: - 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" @@ -1921,12 +1925,6 @@ npm-run-path@^2.0.0: dependencies: path-key "^2.0.0" -num@0.3.0: - 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" @@ -2302,33 +2300,6 @@ repeating@^2.0.0: dependencies: is-finite "^1.0.0" -request@2.81.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" - "request@>= 2.35.0": version "2.74.0" resolved "https://registry.yarnpkg.com/request/-/request-2.74.0.tgz#7693ca768bbb0ea5c8ce08c084a45efa05b892ab" @@ -2355,7 +2326,7 @@ request@2.81.0, 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: @@ -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" @@ -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" @@ -2980,13 +2974,6 @@ write-file-atomic@^1.1.4: imurmurhash "^0.1.4" slide "^1.1.5" -ws@3.0.0: - 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" - ws@3.3.1: version "3.3.1" resolved "https://registry.yarnpkg.com/ws/-/ws-3.3.1.tgz#d97e34dee06a1190c61ac1e95f43cb60b78cf939" @@ -2995,6 +2982,13 @@ ws@3.3.1: 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"