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

Commit

Permalink
feat: Get current fees (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Apr 3, 2020
1 parent 4a80aa2 commit 9920c2f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/client/RESTClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {OrderAPI} from '../order/OrderAPI';
import {ProductAPI} from '../product/ProductAPI';
import {TimeAPI} from '../time/TimeAPI';
import {UserAPI} from '../user/UserAPI';
import {FeeAPI} from '../fee/FeeAPI';
import {FillAPI} from '../fill/FillAPI';
import querystring from 'querystring';
import {ProfileAPI} from '../profile/ProfileAPI';
Expand All @@ -25,6 +26,7 @@ export class RESTClient {
}

readonly account: AccountAPI;
readonly fee: FeeAPI;
readonly fill: FillAPI;
readonly order: OrderAPI;
readonly product: ProductAPI;
Expand Down Expand Up @@ -92,6 +94,7 @@ export class RESTClient {
});

this.account = new AccountAPI(this.httpClient);
this.fee = new FeeAPI(this.httpClient);
this.fill = new FillAPI(this.httpClient);
this.order = new OrderAPI(this.httpClient);
this.product = new ProductAPI(this.httpClient);
Expand Down
16 changes: 16 additions & 0 deletions src/fee/FeeAPI.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import nock from 'nock';

describe('FeeAPI', () => {
describe('getCurrentFees', () => {
it('returns maker & taker fee rates', async () => {
const response = {
maker_fee_rate: '0.0050',
taker_fee_rate: '0.0050',
usd_volume: null,
};
nock(global.REST_URL).get('/fees').reply(200, response);
const canceledOrderIds = await global.client.rest.fee.getCurrentFees();
expect(canceledOrderIds).toEqual(response);
});
});
});
31 changes: 31 additions & 0 deletions src/fee/FeeAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {AxiosInstance} from 'axios';

export interface Fee {
/** 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. */
maker_fee_rate: string;
/** 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). */
taker_fee_rate: string;
/** Your 30-day trailing volume which impacts your fee rates. */
usd_volume: string | null;
}

export class FeeAPI {
static readonly URL = {
FEES: `/fees`,
};

constructor(private readonly apiClient: AxiosInstance) {}

/**
* Get your current maker & taker fee rates, as well as your 30-day trailing volume. Quoted rates are subject to
* change.
*
* @see https://docs.pro.coinbase.com/#fees
* @see https://help.coinbase.com/en/pro/trading-and-funding/trading-rules-and-fees/fees.html
*/
async getCurrentFees(): Promise<Fee> {
const resource = FeeAPI.URL.FEES;
const response = await this.apiClient.get(resource);
return response.data;
}
}

0 comments on commit 9920c2f

Please sign in to comment.