Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit 9920c2f

Browse files
authored
feat: Get current fees (#109)
1 parent 4a80aa2 commit 9920c2f

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/client/RESTClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {OrderAPI} from '../order/OrderAPI';
66
import {ProductAPI} from '../product/ProductAPI';
77
import {TimeAPI} from '../time/TimeAPI';
88
import {UserAPI} from '../user/UserAPI';
9+
import {FeeAPI} from '../fee/FeeAPI';
910
import {FillAPI} from '../fill/FillAPI';
1011
import querystring from 'querystring';
1112
import {ProfileAPI} from '../profile/ProfileAPI';
@@ -25,6 +26,7 @@ export class RESTClient {
2526
}
2627

2728
readonly account: AccountAPI;
29+
readonly fee: FeeAPI;
2830
readonly fill: FillAPI;
2931
readonly order: OrderAPI;
3032
readonly product: ProductAPI;
@@ -92,6 +94,7 @@ export class RESTClient {
9294
});
9395

9496
this.account = new AccountAPI(this.httpClient);
97+
this.fee = new FeeAPI(this.httpClient);
9598
this.fill = new FillAPI(this.httpClient);
9699
this.order = new OrderAPI(this.httpClient);
97100
this.product = new ProductAPI(this.httpClient);

src/fee/FeeAPI.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import nock from 'nock';
2+
3+
describe('FeeAPI', () => {
4+
describe('getCurrentFees', () => {
5+
it('returns maker & taker fee rates', async () => {
6+
const response = {
7+
maker_fee_rate: '0.0050',
8+
taker_fee_rate: '0.0050',
9+
usd_volume: null,
10+
};
11+
nock(global.REST_URL).get('/fees').reply(200, response);
12+
const canceledOrderIds = await global.client.rest.fee.getCurrentFees();
13+
expect(canceledOrderIds).toEqual(response);
14+
});
15+
});
16+
});

src/fee/FeeAPI.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {AxiosInstance} from 'axios';
2+
3+
export interface Fee {
4+
/** A maker fee is paid when you create ("make") liquidity on the order book, i.e. you create an order which is not matched immediately. */
5+
maker_fee_rate: string;
6+
/** A taker fee is paid when you remove ("take") liquidity from the order book, i.e. you create an order which matches an existing order (this includes all market orders). */
7+
taker_fee_rate: string;
8+
/** Your 30-day trailing volume which impacts your fee rates. */
9+
usd_volume: string | null;
10+
}
11+
12+
export class FeeAPI {
13+
static readonly URL = {
14+
FEES: `/fees`,
15+
};
16+
17+
constructor(private readonly apiClient: AxiosInstance) {}
18+
19+
/**
20+
* Get your current maker & taker fee rates, as well as your 30-day trailing volume. Quoted rates are subject to
21+
* change.
22+
*
23+
* @see https://docs.pro.coinbase.com/#fees
24+
* @see https://help.coinbase.com/en/pro/trading-and-funding/trading-rules-and-fees/fees.html
25+
*/
26+
async getCurrentFees(): Promise<Fee> {
27+
const resource = FeeAPI.URL.FEES;
28+
const response = await this.apiClient.get(resource);
29+
return response.data;
30+
}
31+
}

0 commit comments

Comments
 (0)