From 9920c2f4343985c349b68e2a47d7fe2c42e23e34 Mon Sep 17 00:00:00 2001 From: Benny Neugebauer Date: Sat, 4 Apr 2020 00:57:55 +0200 Subject: [PATCH] feat: Get current fees (#109) --- src/client/RESTClient.ts | 3 +++ src/fee/FeeAPI.test.ts | 16 ++++++++++++++++ src/fee/FeeAPI.ts | 31 +++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 src/fee/FeeAPI.test.ts create mode 100644 src/fee/FeeAPI.ts diff --git a/src/client/RESTClient.ts b/src/client/RESTClient.ts index 0199d04c..2d6397eb 100644 --- a/src/client/RESTClient.ts +++ b/src/client/RESTClient.ts @@ -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'; @@ -25,6 +26,7 @@ export class RESTClient { } readonly account: AccountAPI; + readonly fee: FeeAPI; readonly fill: FillAPI; readonly order: OrderAPI; readonly product: ProductAPI; @@ -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); diff --git a/src/fee/FeeAPI.test.ts b/src/fee/FeeAPI.test.ts new file mode 100644 index 00000000..c770494e --- /dev/null +++ b/src/fee/FeeAPI.test.ts @@ -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); + }); + }); +}); diff --git a/src/fee/FeeAPI.ts b/src/fee/FeeAPI.ts new file mode 100644 index 00000000..10d024f9 --- /dev/null +++ b/src/fee/FeeAPI.ts @@ -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 { + const resource = FeeAPI.URL.FEES; + const response = await this.apiClient.get(resource); + return response.data; + } +}