Skip to content

Commit

Permalink
feat: Request trailing volume (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode authored Jan 27, 2020
1 parent 58c5817 commit 8a150fe
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"exchange_volume": "4850.87208838",
"product_id": "BTC-EUR",
"recorded_at": "2020-01-27T00:05:55.356639Z",
"volume": "2.02148248"
}
]
14 changes: 14 additions & 0 deletions src/user/UserAPI.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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');
});
});
});
20 changes: 20 additions & 0 deletions src/user/UserAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -17,4 +24,17 @@ export class UserAPI {
const response = await this.apiClient.get<VerifiedUser>(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<TrailingVolume>} 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<TrailingVolume[]> {
const resource = `${UserAPI.URL.USERS}/self/trailing-volume`;
const response = await this.apiClient.get<TrailingVolume[]>(resource);
return response.data;
}
}

0 comments on commit 8a150fe

Please sign in to comment.