From b90d6c08d43e099405d94247acf31a24c9e2360c Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Tue, 18 Jun 2024 22:52:19 +0100 Subject: [PATCH 1/2] chore(): minor readme updates --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cb5779b..29bb835 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Node.js & JavaScript SDK for Gate.io REST APIs, WebSockets & WebSocket API

- - - - SDK Logo - - + + + + SDK Logo + +

[![npm version](https://img.shields.io/npm/v/gateio-api)][1] @@ -373,6 +373,12 @@ Have my projects helped you? Share the love, there are many ways you can show yo - Or buy me all the coffee: - ETH(ERC20): `0xA3Bda8BecaB4DCdA539Dc16F9C54a592553Be06C` +For more ways to give thanks & support my efforts, visit [Contributions & Thanks](https://github.com/tiagosiebler/awesome-crypto-examples/wiki/Contributions-&-Thanks)! + ### Contributions & Pull Requests Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items. + +## Star History + +[![Star History Chart](https://api.star-history.com/svg?repos=tiagosiebler/bybit-api,tiagosiebler/binance,tiagosiebler/orderbooks,tiagosiebler/okx-api,tiagosiebler/bitget-api,tiagosiebler/awesome-crypto-examples,tiagosiebler/bitmart-api,tiagosiebler/gateio-api&type=Date)](https://star-history.com/#tiagosiebler/bybit-api&tiagosiebler/binance&tiagosiebler/orderbooks&tiagosiebler/okx-api&tiagosiebler/bitget-api&tiagosiebler/awesome-crypto-examples&tiagosiebler/bitmart-api&tiagosiebler/gateio-api&Date) From 03eb7d7923c64c1389e4a31b677d6a090b32202f Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Tue, 18 Jun 2024 23:12:23 +0100 Subject: [PATCH 2/2] v1.0.6: fix() response type on remaining endpoints, minor readme update --- package-lock.json | 10 +- package.json | 2 +- src/RestClient.ts | 227 +++++++++++++---------------------- src/index.ts | 1 - src/types/response/shared.ts | 5 - test/REST/public.test.ts | 24 ++++ 6 files changed, 116 insertions(+), 153 deletions(-) delete mode 100644 src/types/response/shared.ts create mode 100644 test/REST/public.test.ts diff --git a/package-lock.json b/package-lock.json index 39d795d..918412a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gateio-api", - "version": "1.0.4", + "version": "1.0.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gateio-api", - "version": "1.0.4", + "version": "1.0.6", "license": "MIT", "dependencies": { "axios": "^1.6.6", @@ -5122,9 +5122,9 @@ } }, "node_modules/ws": { - "version": "8.17.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.0.tgz", - "integrity": "sha512-uJq6108EgZMAl20KagGkzCKfMEjxmKvZHG7Tlq0Z6nOky7YF7aq4mOx6xK8TJ/i1LeK4Qus7INktacctDgY8Ow==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", "engines": { "node": ">=10.0.0" }, diff --git a/package.json b/package.json index ddd629a..44dd280 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gateio-api", - "version": "1.0.5", + "version": "1.0.6", "description": "Complete & robust Node.js SDK for Gate.io's REST APIs, WebSockets & WebSocket APIs, with TypeScript declarations.", "scripts": { "clean": "rm -rf dist/*", diff --git a/src/RestClient.ts b/src/RestClient.ts index 919f367..7767888 100644 --- a/src/RestClient.ts +++ b/src/RestClient.ts @@ -254,7 +254,6 @@ import { BrokerCommissionHistoryRecord, BrokerTransactionHistoryRecord, } from './types/response/rebate.js'; -import { APIResponse } from './types/response/shared.js'; import { DeleteSpotBatchOrdersResp, GetSpotOpenOrdersResp, @@ -487,12 +486,10 @@ export class RestClient extends BaseRestClient { }[]> */ getSubBalance(params?: { sub_uid?: string }): Promise< - APIResponse< - { - uid: string; - available: { [key: string]: string }; - }[] - > + { + uid: string; + available: { [key: string]: string }; + }[] > { return this.getPrivate('/wallet/sub_account_balances', params); } @@ -505,9 +502,7 @@ export class RestClient extends BaseRestClient { */ getSubMarginBalances(params?: { sub_uid?: string; - }): Promise< - APIResponse<{ uid: string; available: SubAccountMarginBalance[] }> - > { + }): Promise<{ uid: string; available: SubAccountMarginBalance[] }> { return this.getPrivate('/wallet/sub_account_margin_balances', params); } @@ -756,12 +751,10 @@ export class RestClient extends BaseRestClient { * amount: string; * }> */ - getUnifiedMaxBorrow(params: { currency: string }): Promise< - APIResponse<{ - currency: string; - amount: string; - }> - > { + getUnifiedMaxBorrow(params: { currency: string }): Promise<{ + currency: string; + amount: string; + }> { return this.getPrivate('/unified/borrowable', params); } @@ -774,12 +767,10 @@ export class RestClient extends BaseRestClient { * amount: string; * }> */ - getUnifiedMaxTransferable(params: { currency: string }): Promise< - APIResponse<{ - currency: string; - amount: string; - }> - > { + getUnifiedMaxTransferable(params: { currency: string }): Promise<{ + currency: string; + amount: string; + }> { return this.getPrivate('/unified/transferable', params); } @@ -890,9 +881,7 @@ export class RestClient extends BaseRestClient { * * @returns Promise */ - getUnifiedCurrencyDiscountTiers(): Promise< - APIResponse - > { + getUnifiedCurrencyDiscountTiers(): Promise { return this.get('/unified/currency_discount_tiers'); } @@ -1240,11 +1229,9 @@ export class RestClient extends BaseRestClient { * server_time: number; * }> */ - getServerTime(): Promise< - APIResponse<{ - server_time: number; - }> - > { + getServerTime(): Promise<{ + server_time: number; + }> { return this.get('/spot/time'); } @@ -1261,11 +1248,9 @@ export class RestClient extends BaseRestClient { submitSpotCountdownOrders(params: { timeout: number; currency_pair?: string; - }): Promise< - APIResponse<{ - triggerTime: number; - }> - > { + }): Promise<{ + triggerTime: number; + }> { return this.postPrivate('/spot/countdown_cancel_all', { body: params }); } @@ -1291,11 +1276,9 @@ export class RestClient extends BaseRestClient { * id: number; * }> */ - submitSpotPriceTriggerOrder(params: SpotPriceTriggeredOrder): Promise< - APIResponse<{ - id: number; - }> - > { + submitSpotPriceTriggerOrder(params: SpotPriceTriggeredOrder): Promise<{ + id: number; + }> { return this.postPrivate('/spot/price_orders', { body: params }); } @@ -1392,15 +1375,13 @@ export class RestClient extends BaseRestClient { * }[]> */ getFundingAccounts(params?: { currency?: string }): Promise< - APIResponse< - { - currency: string; - available: string; - locked: string; - lent: string; - total_lent: string; - }[] - > + { + currency: string; + available: string; + locked: string; + lent: string; + total_lent: string; + }[] > { return this.getPrivate('/margin/funding_accounts', params); } @@ -1439,13 +1420,11 @@ export class RestClient extends BaseRestClient { getMarginTransferableAmount(params: { currency: string; currency_pair?: string; - }): Promise< - APIResponse<{ - currency: string; - currency_pair?: string; - amount: string; - }> - > { + }): Promise<{ + currency: string; + currency_pair?: string; + amount: string; + }> { return this.getPrivate('/margin/transferable', params); } @@ -1582,12 +1561,10 @@ export class RestClient extends BaseRestClient { * amount: string; * }> */ - getCrossMarginTransferableAmount(params: { currency: string }): Promise< - APIResponse<{ - currency: string; - amount: string; - }> - > { + getCrossMarginTransferableAmount(params: { currency: string }): Promise<{ + currency: string; + amount: string; + }> { return this.getPrivate('/margin/cross/transferable', params); } @@ -1612,12 +1589,10 @@ export class RestClient extends BaseRestClient { * amount: string; * }> */ - getCrossMarginBorrowableAmount(params: { currency: string }): Promise< - APIResponse<{ - currency: string; - amount: string; - }> - > { + getCrossMarginBorrowableAmount(params: { currency: string }): Promise<{ + currency: string; + amount: string; + }> { return this.getPrivate('/margin/cross/borrowable', params); } @@ -1904,12 +1879,10 @@ export class RestClient extends BaseRestClient { contract: string; limit?: number; }): Promise< - APIResponse< - { - t: number; - r: string; - }[] - > + { + t: number; + r: string; + }[] > { const { settle, ...query } = params; return this.get(`/futures/${settle}/funding_rate`, query); @@ -1928,12 +1901,10 @@ export class RestClient extends BaseRestClient { settle: 'btc' | 'usdt' | 'usd'; limit?: number; }): Promise< - APIResponse< - { - t: number; - b: string; - }[] - > + { + t: number; + b: string; + }[] > { const { settle, ...query } = params; return this.get(`/futures/${settle}/insurance`, query); @@ -2594,12 +2565,10 @@ export class RestClient extends BaseRestClient { settle: 'usdt'; limit?: number; }): Promise< - APIResponse< - { - t: number; - b: string; - }[] - > + { + t: number; + b: string; + }[] > { const { settle, ...query } = params; return this.get(`/delivery/${settle}/insurance`, query); @@ -2920,9 +2889,7 @@ export class RestClient extends BaseRestClient { * * @returns Promise<{ name: string; index_price: string }[]> */ - getOptionsUnderlyings(): Promise< - APIResponse<{ name: string; index_price: string }[]> - > { + getOptionsUnderlyings(): Promise<{ name: string; index_price: string }[]> { return this.get(`/options/underlyings`); } @@ -3032,13 +2999,11 @@ export class RestClient extends BaseRestClient { * index_price: string; * }> */ - getOptionsUnderlyingTicker(params: { underlying: string }): Promise< - APIResponse<{ - trade_put: number; - trade_call: number; - index_price: string; - }> - > { + getOptionsUnderlyingTicker(params: { underlying: string }): Promise<{ + trade_put: number; + trade_call: number; + index_price: string; + }> { return this.get(`/options/underlying/tickers/${params.underlying}`); } @@ -3284,12 +3249,10 @@ export class RestClient extends BaseRestClient { * interest: string; * }> */ - getLendingTotalInterest(params: { currency: string }): Promise< - APIResponse<{ - currency: string; - interest: string; - }> - > { + getLendingTotalInterest(params: { currency: string }): Promise<{ + currency: string; + interest: string; + }> { return this.getPrivate(`/earn/uni/interests/${params.currency}`); } @@ -3327,12 +3290,10 @@ export class RestClient extends BaseRestClient { * interest_status: string; * }> */ - getLendingInterestStatus(params: { currency: string }): Promise< - APIResponse<{ - currency: string; - interest_status: string; - }> - > { + getLendingInterestStatus(params: { currency: string }): Promise<{ + currency: string; + interest_status: string; + }> { return this.getPrivate(`/earn/uni/interest_status/${params.currency}`); } @@ -3383,12 +3344,10 @@ export class RestClient extends BaseRestClient { order_id: number; repay_amount: string; repaid_all: boolean; - }): Promise< - APIResponse<{ - repaid_principal: string; - repaid_interest: string; - }> - > { + }): Promise<{ + repaid_principal: string; + repaid_interest: string; + }> { return this.postPrivate(`/loan/collateral/repay`, { body: params }); } @@ -3434,12 +3393,10 @@ export class RestClient extends BaseRestClient { * collateral_amount: string; * }> */ - getLoanTotalAmount(): Promise< - APIResponse<{ - borrow_amount: string; - collateral_amount: string; - }> - > { + getLoanTotalAmount(): Promise<{ + borrow_amount: string; + collateral_amount: string; + }> { return this.getPrivate(`/loan/collateral/total_amount`); } @@ -3466,12 +3423,10 @@ export class RestClient extends BaseRestClient { * }[]> */ getLoanSupportedCurrencies(params?: { loan_currency?: string }): Promise< - APIResponse< - { - loan_currency: string; - collateral_currency: string[]; - }[] - > + { + loan_currency: string; + collateral_currency: string[]; + }[] > { return this.get(`/loan/collateral/currencies`, params); } @@ -3579,9 +3534,7 @@ export class RestClient extends BaseRestClient { * * @returns Promise */ - getMultiLoanSupportedCurrencies(): Promise< - APIResponse - > { + getMultiLoanSupportedCurrencies(): Promise { return this.get(`/loan/multi_collateral/currencies`); } @@ -3774,9 +3727,7 @@ export class RestClient extends BaseRestClient { */ getAgencyTransactionHistory( params: GetAgencyTransactionHistoryReq, - ): Promise< - APIResponse<{ total: number; list: AgencyTransactionHistoryRecord[] }> - > { + ): Promise<{ total: number; list: AgencyTransactionHistoryRecord[] }> { return this.getPrivate('/rebate/agency/transaction_history', params); } @@ -3789,9 +3740,7 @@ export class RestClient extends BaseRestClient { */ getAgencyCommissionHistory( params: GetAgencyCommissionHistoryReq, - ): Promise< - APIResponse<{ total: number; list: AgencyCommissionHistoryRecord[] }> - > { + ): Promise<{ total: number; list: AgencyCommissionHistoryRecord[] }> { return this.getPrivate('/rebate/agency/commission_history', params); } @@ -3804,9 +3753,7 @@ export class RestClient extends BaseRestClient { */ getBrokerCommissionHistory( params: GetBrokerCommissionHistoryReq, - ): Promise< - APIResponse<{ total: number; list: BrokerCommissionHistoryRecord[] }> - > { + ): Promise<{ total: number; list: BrokerCommissionHistoryRecord[] }> { return this.getPrivate('/rebate/broker/commission_history', params); } @@ -3819,9 +3766,7 @@ export class RestClient extends BaseRestClient { */ getBrokerTransactionHistory( params: GetBrokerTransactionHistoryReq, - ): Promise< - APIResponse<{ total: number; list: BrokerTransactionHistoryRecord[] }> - > { + ): Promise<{ total: number; list: BrokerTransactionHistoryRecord[] }> { return this.getPrivate('/rebate/broker/transaction_history', params); } diff --git a/src/index.ts b/src/index.ts index 6ca855b..a1ed4b9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,7 +35,6 @@ export * from './types/response/marginuni.js'; export * from './types/response/multicollateralLoan.js'; export * from './types/response/options.js'; export * from './types/response/rebate.js'; -export * from './types/response/shared.js'; export * from './types/response/spot.js'; export * from './types/response/subaccount.js'; export * from './types/response/unified.js'; diff --git a/src/types/response/shared.ts b/src/types/response/shared.ts deleted file mode 100644 index a1e0287..0000000 --- a/src/types/response/shared.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface APIResponse { - success: boolean; - data: TData; - timestamp: number; -} diff --git a/test/REST/public.test.ts b/test/REST/public.test.ts new file mode 100644 index 0000000..069c7ab --- /dev/null +++ b/test/REST/public.test.ts @@ -0,0 +1,24 @@ +import { RestClient } from '../../src'; + +describe('REST PUBLIC', () => { + const rest = new RestClient(); + + describe('public endpoints', () => { + it('should succeed making a GET request', async () => { + const res = await rest.getSpotTicker(); + expect(res).toMatchObject(expect.any(Array)); + }); + + it('should return orderbook data', async () => { + const res = await rest.getSpotOrderBook({ + currency_pair: 'BTC_USDT', + }); + + // console.log(JSON.stringify(res, null, 2)); + expect(res.asks).toMatchObject(expect.any(Array)); + expect(res.bids).toMatchObject(expect.any(Array)); + expect(res.current).toEqual(expect.any(Number)); + expect(res.update).toEqual(expect.any(Number)); + }); + }); +});