Skip to content

Commit c1a7c8c

Browse files
authored
Merge pull request #102 from JJ-Cro/updateExamples3101
feat: add new examples for futures and spot trading using REST and WebSocket clients
2 parents b55fb1f + 59fa8ae commit c1a7c8c

19 files changed

+38
-38
lines changed

examples/futures-balance-trade.ts renamed to examples/Rest/futures/futures-balance-trade.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
**/
99

1010
// Import the RestClient and WebsocketClient from the published version of this SDK, installed via NPM (npm install gateio-api)
11-
import { RestClient, WebsocketClient } from 'gateio-api';
11+
import { RestClient, WebsocketClient } from '../../../src/index.js';
1212

1313
// Define the account object with API key and secret
1414
const account = {
@@ -68,7 +68,7 @@ async function subscribePrivateWs() {
6868

6969
return true;
7070
} catch (e) {
71-
console.error(`Req error: `, e);
71+
console.error('Req error: ', e);
7272
throw e;
7373
}
7474
}
@@ -82,7 +82,7 @@ async function main() {
8282
const balances = await gateRestClient.getFuturesAccount({ settle: 'usdt' });
8383

8484
// total usdt balance
85-
const usdtBalance = Number(balances.total);
85+
// const usdtBalance = Number(balances.total);
8686

8787
// available usdt balance
8888
const availableBalance = Number(balances.available);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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.
1+
import { RestClient } from '../../../src/index.js'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
22
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
33

44
// Define the account object with API key and secret
@@ -22,7 +22,7 @@ async function getFuturesBalances() {
2222

2323
console.log('Response: ', result); // Log the response to the console
2424
} catch (e) {
25-
console.error(`Error in execution: `, e); // Log any errors that occur
25+
console.error('Error in execution: ', e); // Log any errors that occur
2626
}
2727
}
2828

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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.
1+
import { RestClient } from '../../../src/index.js'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
22
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
33

44
// Define the account object with API key and secret
@@ -31,7 +31,7 @@ async function getFuturesOrders() {
3131
});
3232
console.log('finishedOrders: ', finishedOrders); // Log the response to the console
3333
} catch (e) {
34-
console.error(`Error in execution: `, e); // Log any errors that occur
34+
console.error('Error in execution: ', e); // Log any errors that occur
3535
}
3636
}
3737

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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.
1+
import { RestClient } from '../../../src/index.js'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
22
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
33

44
// Define the account object with API key and secret
@@ -30,7 +30,7 @@ async function getFuturesTicker() {
3030
});
3131
console.log('ticker: ', ticker); // Log the response to the console
3232
} catch (e) {
33-
console.error(`Error in execution: `, e); // Log any errors that occur
33+
console.error('Error in execution: ', e); // Log any errors that occur
3434
}
3535
}
3636

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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.
1+
import { RestClient } from '../../../src/index.js'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
22
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
33

44
// Define the account object with API key and secret
@@ -28,7 +28,7 @@ async function submitFuturesOrder() {
2828

2929
console.log('Response: ', result); // Log the response to the console
3030
} catch (e) {
31-
console.error(`Error in execution: `, e); // Log any errors that occur
31+
console.error('Error in execution: ', e); // Log any errors that occur
3232
}
3333
}
3434

examples/futures/submitMarketOrder.ts renamed to examples/Rest/futures/submitMarketOrder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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.
1+
import { RestClient } from '../../../src/index.js'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
22
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
33

44
// Define the account object with API key and secret
@@ -28,7 +28,7 @@ async function submitFuturesOrder() {
2828

2929
console.log('Response: ', result); // Log the response to the console
3030
} catch (e) {
31-
console.error(`Error in execution: `, e); // Log any errors that occur
31+
console.error('Error in execution: ', e); // Log any errors that occur
3232
}
3333
}
3434

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RestClient } from '../../src/index.js'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
1+
import { RestClient } from '../../../src/index.js'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
22
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
33

44
// Define the account object with API key and secret
@@ -46,7 +46,7 @@ async function submitFuturesOrder() {
4646

4747
console.log('Response: ', result); // Log the response to the console
4848
} catch (e) {
49-
console.error(`Error in execution: `, e); // Log any errors that occur
49+
console.error('Error in execution: ', e); // Log any errors that occur
5050
}
5151
}
5252

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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.
1+
import { RestClient } from '../../../src/index.js'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
22
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
33

44
// Define the account object with API key and secret
@@ -21,7 +21,7 @@ async function getSpotBalances() {
2121
const balances = await gateRestClient.getSpotAccounts();
2222
console.log('Response: ', balances); // Log the response to the console
2323
} catch (e) {
24-
console.error(`Error in execution: `, e); // Log any errors that occur
24+
console.error('Error in execution: ', e); // Log any errors that occur
2525
}
2626
}
2727

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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.
1+
import { RestClient } from '../../../src/index.js'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
22
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
33

44
// Define the account object with API key and secret
@@ -24,7 +24,7 @@ async function getSpotCandles() {
2424
});
2525
console.log('Response: ', balances); // Log the response to the console
2626
} catch (e) {
27-
console.error(`Error in execution: `, e); // Log any errors that occur
27+
console.error('Error in execution: ', e); // Log any errors that occur
2828
}
2929
}
3030

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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.
1+
import { RestClient } from '../../../src/index.js'; // For an easy demonstration, import from the src dir. Normally though, see below to import from the npm installed version instead.
22
// import { RestClient } from 'gateio-api'; // Import the RestClient from the published version of this SDK, installed via NPM (npm install gateio-api)
33

44
// Define the account object with API key and secret
@@ -31,7 +31,7 @@ async function getSpotOrders() {
3131
});
3232
console.log('finishedOrders: ', finishedOrders); // Log the response to the console
3333
} catch (e) {
34-
console.error(`Error in execution: `, e); // Log any errors that occur
34+
console.error('Error in execution: ', e); // Log any errors that occur
3535
}
3636
}
3737

0 commit comments

Comments
 (0)