Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
feat: Support custom URLs to use a proxy server (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Jan 1, 2021
1 parent 834b726 commit ebcb8d2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/CoinbasePro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,19 @@ describe('CoinbasePro', () => {

expect(client.url.REST).toBe(CoinbasePro.SETUP.SANDBOX.REST);
});

it('supports custom URLs to use a proxy server', () => {
const proxyUrl = 'http://localhost:3000/rest-proxy';

const client = new CoinbasePro({
apiKey: '',
apiSecret: '',
passphrase: '',
httpUrl: proxyUrl,
wsUrl: 'wss://ws-feed-public.sandbox.pro.coinbase.com',
});

expect(client.url.REST).toBe(proxyUrl);
});
});
});
31 changes: 29 additions & 2 deletions src/CoinbasePro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@ import {RESTClient} from './client/RESTClient';
import {WebSocketClient} from './client/WebSocketClient';
import {RequestSetup, RequestSigner, SignedRequest} from './auth/RequestSigner';

export interface ClientAuthentication {
export interface ClientAuthenticationBase {
apiKey: string;
apiSecret: string;
passphrase: string;
}

export interface ClientAuthenticationBaseUrls extends ClientAuthenticationBase {
apiKey: string;
apiSecret: string;
passphrase: string;
useSandbox: boolean;
}

export interface ClientAuthenticationCustomUrls extends ClientAuthenticationBase {
apiKey: string;
apiSecret: string;
httpUrl: string;
passphrase: string;
wsUrl: string;
}

export type ClientAuthentication = ClientAuthenticationBaseUrls | ClientAuthenticationCustomUrls;

export interface ClientConnection {
REST: string;
WebSocket: string;
Expand Down Expand Up @@ -41,7 +57,18 @@ export class CoinbasePro {
useSandbox: false,
}
) {
this.url = auth.useSandbox === true ? CoinbasePro.SETUP.SANDBOX : CoinbasePro.SETUP.PRODUCTION;
if (typeof (auth as ClientAuthenticationBaseUrls).useSandbox === 'boolean') {
this.url =
(auth as ClientAuthenticationBaseUrls).useSandbox === true
? CoinbasePro.SETUP.SANDBOX
: CoinbasePro.SETUP.PRODUCTION;
} else {
const {httpUrl, wsUrl} = auth as ClientAuthenticationCustomUrls;
this.url = {
REST: httpUrl,
WebSocket: wsUrl,
};
}

const signRequest = async (setup: RequestSetup): Promise<SignedRequest> => {
const clockSkew = await this.rest.time.getClockSkew();
Expand Down

0 comments on commit ebcb8d2

Please sign in to comment.