From 63386c682f2f0897a47106fc12351aef6177af04 Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Wed, 12 Jun 2024 16:56:07 +0100 Subject: [PATCH] chore(): cleaning on examples --- examples/README.md | 11 +++++-- examples/futures/getBalances.ts | 3 +- examples/futures/getOrders.ts | 3 +- examples/futures/getTickers.ts | 3 +- examples/futures/submitLimitOrder.ts | 3 +- examples/futures/submitMarketOrder.ts | 3 +- examples/rest-private.ts | 36 ----------------------- examples/spot/getBalances.ts | 3 +- examples/spot/getOrders.ts | 3 +- examples/spot/getTickers.ts | 3 +- examples/spot/submitLimitOrder.ts | 3 +- examples/spot/submitMarketOrder.ts | 3 +- examples/ws-private-perp-futures-wsapi.ts | 5 +--- examples/ws-private-perp-futures.ts | 4 +-- examples/ws-private-spot-wsapi.ts | 5 +--- examples/ws-private-spot.ts | 4 +-- examples/ws-public.ts | 4 +-- src/index.ts | 1 + tsconfig.linting.json | 3 +- 19 files changed, 40 insertions(+), 63 deletions(-) delete mode 100644 examples/rest-private.ts diff --git a/examples/README.md b/examples/README.md index 6860449..4a73bc4 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,6 +1,13 @@ # Examples -These samples can be executed using `ts-node`: +These samples can be executed using `ts-node` or `tsx`: + +``` +ts-node ./examples/ws-public.ts +``` + +Most examples also have minimal typescript, so if you rename them to "js" they should execute fine with just node. TypeScript is recommended but completely optional: + ``` -ts-node ./examples/rest-spot-public.ts +node ./examples/spot/getTickers.js ``` diff --git a/examples/futures/getBalances.ts b/examples/futures/getBalances.ts index 1f93af9..19e7384 100644 --- a/examples/futures/getBalances.ts +++ b/examples/futures/getBalances.ts @@ -1,4 +1,5 @@ -import { RestClient } from '../../src'; +import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead. +// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api) // Define the account object with API key and secret const account = { diff --git a/examples/futures/getOrders.ts b/examples/futures/getOrders.ts index a56264f..6f1a41c 100644 --- a/examples/futures/getOrders.ts +++ b/examples/futures/getOrders.ts @@ -1,4 +1,5 @@ -import { RestClient } from '../../src'; +import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead. +// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api) // Define the account object with API key and secret const account = { diff --git a/examples/futures/getTickers.ts b/examples/futures/getTickers.ts index 96097da..5a19e1d 100644 --- a/examples/futures/getTickers.ts +++ b/examples/futures/getTickers.ts @@ -1,4 +1,5 @@ -import { RestClient } from '../../src'; // Import the RestClient from the src directory +import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead. +// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api) // Define the account object with API key and secret const account = { diff --git a/examples/futures/submitLimitOrder.ts b/examples/futures/submitLimitOrder.ts index 39576de..d934457 100644 --- a/examples/futures/submitLimitOrder.ts +++ b/examples/futures/submitLimitOrder.ts @@ -1,4 +1,5 @@ -import { RestClient } from '../../src'; // Import the RestClient from the src directory +import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead. +// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api) // Define the account object with API key and secret const account = { diff --git a/examples/futures/submitMarketOrder.ts b/examples/futures/submitMarketOrder.ts index 1ed992c..b4d8349 100644 --- a/examples/futures/submitMarketOrder.ts +++ b/examples/futures/submitMarketOrder.ts @@ -1,4 +1,5 @@ -import { RestClient } from '../../src'; // Import the RestClient from the src directory +import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead. +// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api) // Define the account object with API key and secret const account = { diff --git a/examples/rest-private.ts b/examples/rest-private.ts deleted file mode 100644 index 052b09a..0000000 --- a/examples/rest-private.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { RestClient } from '../src'; // Import the RestClient from the src directory - -// Define the account object with API key and secret -const account = { - key: process.env.API_KEY || 'yourApiHere', // Replace 'yourApiHere' with your actual API key - secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' with your actual API secret -}; - -// Initialize the RestClient with the API credentials -const gateRestClient = new RestClient({ - apiKey: account.key, - apiSecret: account.secret, -}); - -async function restPrivateExample() { - try { - console.log('Using credentials: ', account); - - // Submit a limit order for spot trading - const result = await gateRestClient.submitSpotOrder({ - currency_pair: 'BTC_USDT', // Specify the currency pair - side: 'buy', // Specify the order side: 'buy' or 'sell' - type: 'limit', // Specify the order type: 'limit' - amount: '0.001', // Specify the amount to buy - price: '45000', // Specify the limit price - time_in_force: 'gtc', // Time in force: 'gtc' (Good Till Cancelled) - }); - - console.log('Result: ', JSON.stringify(result, null, 2)); // Log the result to the console - } catch (e) { - console.error(`Error in execution: `, e); // Log any errors that occur - } -} - -// Execute the function to demonstrate the RestClient usage -restPrivateExample(); diff --git a/examples/spot/getBalances.ts b/examples/spot/getBalances.ts index fa02524..1189f14 100644 --- a/examples/spot/getBalances.ts +++ b/examples/spot/getBalances.ts @@ -1,4 +1,5 @@ -import { RestClient } from '../../src'; // Import the RestClient from the src directory +import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead. +// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api) // Define the account object with API key and secret const account = { diff --git a/examples/spot/getOrders.ts b/examples/spot/getOrders.ts index c49195c..229ea88 100644 --- a/examples/spot/getOrders.ts +++ b/examples/spot/getOrders.ts @@ -1,4 +1,5 @@ -import { RestClient } from '../../src'; // Import the RestClient from the src directory +import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead. +// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api) // Define the account object with API key and secret const account = { diff --git a/examples/spot/getTickers.ts b/examples/spot/getTickers.ts index a966820..565fdf2 100644 --- a/examples/spot/getTickers.ts +++ b/examples/spot/getTickers.ts @@ -1,4 +1,5 @@ -import { RestClient } from '../../src'; // Import the RestClient from the src directory +import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead. +// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api) // Define the account object with API key and secret const account = { diff --git a/examples/spot/submitLimitOrder.ts b/examples/spot/submitLimitOrder.ts index 0e71d26..7f65151 100644 --- a/examples/spot/submitLimitOrder.ts +++ b/examples/spot/submitLimitOrder.ts @@ -1,4 +1,5 @@ -import { RestClient } from '../../src'; // Import the RestClient from the src directory +import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead. +// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api) // Define the account object with API key and secret const account = { diff --git a/examples/spot/submitMarketOrder.ts b/examples/spot/submitMarketOrder.ts index dda06c4..2c2f6a7 100644 --- a/examples/spot/submitMarketOrder.ts +++ b/examples/spot/submitMarketOrder.ts @@ -1,4 +1,5 @@ -import { RestClient } from '../../src'; // Import the RestClient from the src directory +import { RestClient } from '../../src'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead. +// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api) // Define the account object with API key and secret const account = { diff --git a/examples/ws-private-perp-futures-wsapi.ts b/examples/ws-private-perp-futures-wsapi.ts index 1b71556..0ee81a5 100644 --- a/examples/ws-private-perp-futures-wsapi.ts +++ b/examples/ws-private-perp-futures-wsapi.ts @@ -1,10 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import { LogParams, WebsocketClient } from '../src'; -import { - WSAPILoginResponse, - WSAPIResponse, -} from '../src/types/websockets/wsAPI'; +// import { LogParams, WebsocketClient } from 'gateio-api'; // normally you should install this module via npm: `npm install gateio-api` const account = { key: process.env.API_KEY || 'apiKeyHere', diff --git a/examples/ws-private-perp-futures.ts b/examples/ws-private-perp-futures.ts index 1c9701c..9430acc 100644 --- a/examples/ws-private-perp-futures.ts +++ b/examples/ws-private-perp-futures.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -import { LogParams, WebsocketClient } from '../src'; -import { WsTopicRequest } from '../src/lib/websocket/websocket-util'; +import { LogParams, WebsocketClient, WsTopicRequest } from '../src'; +// import { LogParams, WebsocketClient, WsTopicRequest } from 'gateio-api'; // normally you should install this module via npm: `npm install gateio-api` const account = { key: process.env.API_KEY || 'apiKeyHere', diff --git a/examples/ws-private-spot-wsapi.ts b/examples/ws-private-spot-wsapi.ts index cb8030b..b9632cb 100644 --- a/examples/ws-private-spot-wsapi.ts +++ b/examples/ws-private-spot-wsapi.ts @@ -1,10 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import { LogParams, WebsocketClient } from '../src'; -import { - WSAPILoginResponse, - WSAPIResponse, -} from '../src/types/websockets/wsAPI'; +// import { LogParams, WebsocketClient } from 'gateio-api'; // normally you should install this module via npm: `npm install gateio-api` // eslint-disable-next-line @typescript-eslint/no-unused-vars const account = { diff --git a/examples/ws-private-spot.ts b/examples/ws-private-spot.ts index de89234..4607bcf 100644 --- a/examples/ws-private-spot.ts +++ b/examples/ws-private-spot.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -import { LogParams, WebsocketClient } from '../src'; -import { WsTopicRequest } from '../src/lib/websocket/websocket-util'; +import { LogParams, WebsocketClient, WsTopicRequest } from '../src'; +// import { LogParams, WebsocketClient, WsTopicRequest } from 'gateio-api'; // normally you should install this module via npm: `npm install gateio-api` // eslint-disable-next-line @typescript-eslint/no-unused-vars const account = { diff --git a/examples/ws-public.ts b/examples/ws-public.ts index e52ba84..721322a 100644 --- a/examples/ws-public.ts +++ b/examples/ws-public.ts @@ -1,6 +1,6 @@ // eslint-disable-next-line @typescript-eslint/no-unused-vars -import { LogParams, WebsocketClient } from '../src'; -import { WsTopicRequest } from '../src/lib/websocket/websocket-util'; +import { LogParams, WebsocketClient, WsTopicRequest } from '../src'; +// import { LogParams, WebsocketClient, WsTopicRequest } from 'gateio-api'; // normally you should install this module via npm: `npm install gateio-api` // const customLogger = { // // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/src/index.ts b/src/index.ts index 32f7590..a1ed4b9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ export * from './lib/logger.js'; +export * from './lib/websocket/websocket-util.js'; export * from './RestClient.js'; export * from './WebsocketClient.js'; diff --git a/tsconfig.linting.json b/tsconfig.linting.json index c55e821..e925971 100644 --- a/tsconfig.linting.json +++ b/tsconfig.linting.json @@ -4,7 +4,8 @@ "module": "commonjs", "outDir": "dist/cjs", "target": "esnext", - "rootDir": "../" + "rootDir": "../", + "allowJs": true }, "include": [ "src/**/*.*",