Skip to content

Commit f485407

Browse files
committed
feat(v2.2.0): support demo trading
1 parent 3f992cd commit f485407

16 files changed

+665
-111
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ const futuresClient = new FuturesClientV2({
178178
apiMemo: API_MEMO,
179179
});
180180

181+
// Enable demo/simulated trading environment (optional)
182+
const demoFuturesClient = new FuturesClientV2({
183+
apiKey: API_KEY,
184+
apiSecret: API_SECRET,
185+
apiMemo: API_MEMO,
186+
useDemo: true, // Connect to simulated trading environment
187+
});
188+
181189
// Get futures account assets
182190
try {
183191
const balances = await futuresClient.getFuturesAccountAssets();
@@ -289,6 +297,14 @@ const wsClient = new WebsocketClient({
289297
apiMemo: 'yourAPIMemoHere',
290298
});
291299

300+
// Enable demo/simulated trading environment for V2 Futures WebSocket (optional)
301+
const demoWsClient = new WebsocketClient({
302+
apiKey: 'yourAPIKeyHere',
303+
apiSecret: 'yourAPISecretHere',
304+
apiMemo: 'yourAPIMemoHere',
305+
useDemo: true, // Connect to simulated trading environment (V2 Futures only)
306+
});
307+
292308
// Set up event handlers
293309
wsClient.on('open', (data) => {
294310
console.log('Private WebSocket connected: ', data?.wsKey);
@@ -329,6 +345,34 @@ For more comprehensive examples, including custom logging and error handling, ch
329345

330346
## Configuration Options
331347

348+
### Demo Trading
349+
350+
BitMart provides a simulated trading environment for testing futures trading strategies. Enable demo mode by adding `useDemo: true` to your client configuration:
351+
352+
**REST API (Futures V2 only):**
353+
354+
```typescript
355+
const demoClient = new FuturesClientV2({
356+
apiKey: API_KEY,
357+
apiSecret: API_SECRET,
358+
apiMemo: API_MEMO,
359+
useDemo: true, // Uses https://demo-api-cloud-v2.bitmart.com
360+
});
361+
```
362+
363+
**WebSocket (V2 Futures only):**
364+
365+
```typescript
366+
const demoWsClient = new WebsocketClient({
367+
apiKey: API_KEY,
368+
apiSecret: API_SECRET,
369+
apiMemo: API_MEMO,
370+
useDemo: true, // Uses wss://openapi-wsdemo-v2.bitmart.com
371+
});
372+
```
373+
374+
**Note:** Demo environment is only available for V2 Futures. Spot trading and V1 Futures will continue using production endpoints. The same API keys work for both production and demo environments.
375+
332376
### Recv Window
333377

334378
The receive window parameter determines how long an API request is valid. This can be configured at two levels:

docs/endpointFunctionList.md

Lines changed: 102 additions & 99 deletions
Large diffs are not rendered by default.

examples/apidoc/FuturesClientV2/getFuturesAccountPositionsV2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { FuturesClientV2 } = require('bitmart-api');
22

33
// This example shows how to call this bitmart API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitmart-api" for bitmart exchange
44
// This bitmart API SDK is available on npm via "npm install bitmart-api"
5-
// ENDPOINT: contract/private/position
5+
// ENDPOINT: contract/private/position-v2
66
// METHOD: GET
77
// PUBLIC: NO
88

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { FuturesClientV2 } = require('bitmart-api');
2+
3+
// This example shows how to call this bitmart API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitmart-api" for bitmart exchange
4+
// This bitmart API SDK is available on npm via "npm install bitmart-api"
5+
// ENDPOINT: contract/private/affiliate/rebate-api
6+
// METHOD: GET
7+
// PUBLIC: NO
8+
9+
const client = new FuturesClientV2({
10+
apiKey: 'yourAPIKeyHere',
11+
apiSecret: 'yourAPISecretHere',
12+
apiMemo: 'yourAPIMemoHere',
13+
});
14+
15+
client.getFuturesAffiliateRebateApi(params)
16+
.then((response) => {
17+
console.log(response);
18+
})
19+
.catch((error) => {
20+
console.error(error);
21+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { FuturesClientV2 } = require('bitmart-api');
2+
3+
// This example shows how to call this bitmart API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitmart-api" for bitmart exchange
4+
// This bitmart API SDK is available on npm via "npm install bitmart-api"
5+
// ENDPOINT: contract/private/affiliate/rebate-user
6+
// METHOD: GET
7+
// PUBLIC: NO
8+
9+
const client = new FuturesClientV2({
10+
apiKey: 'yourAPIKeyHere',
11+
apiSecret: 'yourAPISecretHere',
12+
apiMemo: 'yourAPIMemoHere',
13+
});
14+
15+
client.getFuturesAffiliateRebateUser(params)
16+
.then((response) => {
17+
console.log(response);
18+
})
19+
.catch((error) => {
20+
console.error(error);
21+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { FuturesClientV2 } = require('bitmart-api');
2+
3+
// This example shows how to call this bitmart API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitmart-api" for bitmart exchange
4+
// This bitmart API SDK is available on npm via "npm install bitmart-api"
5+
// ENDPOINT: contract/private/claim
6+
// METHOD: POST
7+
// PUBLIC: NO
8+
9+
const client = new FuturesClientV2({
10+
apiKey: 'yourAPIKeyHere',
11+
apiSecret: 'yourAPISecretHere',
12+
apiMemo: 'yourAPIMemoHere',
13+
});
14+
15+
client.submitFuturesSimulatedClaim(params)
16+
.then((response) => {
17+
console.log(response);
18+
})
19+
.catch((error) => {
20+
console.error(error);
21+
});

0 commit comments

Comments
 (0)