diff --git a/src/test/fixtures/rest/users/self/trailing-volume/GET-200.json b/src/test/fixtures/rest/users/self/trailing-volume/GET-200.json new file mode 100644 index 00000000..16227928 --- /dev/null +++ b/src/test/fixtures/rest/users/self/trailing-volume/GET-200.json @@ -0,0 +1,8 @@ +[ + { + "exchange_volume": "4850.87208838", + "product_id": "BTC-EUR", + "recorded_at": "2020-01-27T00:05:55.356639Z", + "volume": "2.02148248" + } +] diff --git a/src/user/UserAPI.test.ts b/src/user/UserAPI.test.ts index 9de18682..a2fce2a5 100644 --- a/src/user/UserAPI.test.ts +++ b/src/user/UserAPI.test.ts @@ -1,5 +1,6 @@ import nock from 'nock'; import verifyPayload from '../test/fixtures/rest/users/self/verify/GET-200.json'; +import trailingVolume from '../test/fixtures/rest/users/self/trailing-volume/GET-200.json'; import {UserAPI} from './UserAPI'; describe('UserAPI', () => { @@ -13,6 +14,12 @@ describe('UserAPI', () => { return [200, JSON.stringify(verifyPayload)]; }) .persist(); + + nock(global.REST_URL) + .get(`${UserAPI.URL.USERS}/self/trailing-volume`) + .query(() => true) + .reply(() => [200, JSON.stringify(trailingVolume)]) + .persist(); }); describe('verifyAuthentication', () => { @@ -21,4 +28,11 @@ describe('UserAPI', () => { expect(verifiedUser.id).toBe('7cbb4d09b95cee4dea90e9a7'); }); }); + + describe('getTrailingVolume', () => { + it('lists your 30-day trailing volume', async () => { + const trailingVolume = await global.client.rest.user.getTrailingVolume(); + expect(trailingVolume[0].product_id).toBe('BTC-EUR'); + }); + }); }); diff --git a/src/user/UserAPI.ts b/src/user/UserAPI.ts index 42409cf7..5a266792 100644 --- a/src/user/UserAPI.ts +++ b/src/user/UserAPI.ts @@ -4,6 +4,13 @@ export interface VerifiedUser { id: string; } +export interface TrailingVolume { + exchange_volume: string; + product_id: string; + recorded_at: string; + volume: string; +} + export class UserAPI { static readonly URL: {USERS: string} = { USERS: `/users`, @@ -17,4 +24,17 @@ export class UserAPI { const response = await this.apiClient.get(resource); return response.data; } + + /** + * This request will return your 30-day trailing volume for all products of the API key’s profile. This is a cached + * value that’s calculated every day at midnight UTC. + * @note This endpoint requires either the “view” or “trade” permission + * @returns {Promise} Your 30-day trailing volume for all products of the API key’s profile + * @see https://docs.pro.coinbase.com/#trailing-volume + */ + async getTrailingVolume(): Promise { + const resource = `${UserAPI.URL.USERS}/self/trailing-volume`; + const response = await this.apiClient.get(resource); + return response.data; + } }