Skip to content

Commit 0864d1c

Browse files
authored
Merge pull request tiagosiebler#76 from JJ-Cro/updateExamples3101
feat: add example scripts for Spot and Futures API interactions via REST and WebSocket clients
2 parents e3cd5ac + 8f910e0 commit 0864d1c

14 files changed

Lines changed: 29 additions & 31 deletions
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createHmac } from 'crypto';
22

3-
import { RestClient } from '../src';
3+
import { RestClient } from '../../src/index.js';
44
// import from npm, after installing via npm `npm install bitmart-api`
55
// import { RestClient } from 'bitmart-api';
66

@@ -29,7 +29,7 @@ async function getSpotBalances() {
2929

3030
console.log('Balances: ', JSON.stringify(balances, null, 2));
3131
} catch (e) {
32-
console.error(`Req error: `, e);
32+
console.error('Req error: ', e);
3333
}
3434
}
3535

examples/futures-get-balances.ts renamed to examples/Rest/Futures/futures-get-balances.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FuturesClientV2 } from '../src/index.js';
1+
import { FuturesClientV2 } from '../../../src/index.js';
22
// // import from npm, after installing via npm `npm install bitmart-api`
33
// import { FuturesClientV2 } from 'bitmart-api';
44

@@ -20,7 +20,7 @@ async function getFuturesAssets() {
2020

2121
console.log('Balances: ', JSON.stringify(balances, null, 2));
2222
} catch (e) {
23-
console.error(`Req error: `, e);
23+
console.error('Req error: ', e);
2424
}
2525
}
2626

examples/futures-get-klines.ts renamed to examples/Rest/Futures/futures-get-klines.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FuturesClientV2 } from '../src/index.js';
1+
import { FuturesClientV2 } from '../../../src/index.js';
22
// // import from npm, after installing via npm `npm install bitmart-api`
33
// import { FuturesClientV2 } from 'bitmart-api';
44

@@ -14,7 +14,7 @@ async function getFuturesKlines() {
1414

1515
console.log('Tickers: ', JSON.stringify(klines, null, 2));
1616
} catch (e) {
17-
console.error(`Req error: `, e);
17+
console.error('Req error: ', e);
1818
}
1919
}
2020

examples/futures-get-tickers.ts renamed to examples/Rest/Futures/futures-get-tickers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FuturesClientV2 } from '../src/index.js';
1+
import { FuturesClientV2 } from '../../../src/index.js';
22
// // import from npm, after installing via npm `npm install bitmart-api`
33
// import { FuturesClientV2 } from 'bitmart-api';
44

@@ -10,7 +10,7 @@ async function getFuturesTickers() {
1010

1111
console.log('Tickers: ', JSON.stringify(tickers, null, 2));
1212
} catch (e) {
13-
console.error(`Req error: `, e);
13+
console.error('Req error: ', e);
1414
}
1515
}
1616

examples/futures-submit-order.ts renamed to examples/Rest/Futures/futures-submit-order.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FuturesClientV2 } from '../src/index.js';
1+
import { FuturesClientV2 } from '../../../src/index.js';
22
// // import from npm, after installing via npm `npm install bitmart-api`
33
// import { FuturesClientV2 } from 'bitmart-api';
44

@@ -21,12 +21,13 @@ async function SumbitFuturesOrder() {
2121
type: 'market',
2222
side: 1, // Order side - 1=buy_open_long -2=buy_close_short -3=sell_close_long -4=sell_open_short
2323
size: 1,
24+
leverage: '1',
2425
open_type: 'cross',
2526
});
2627

2728
console.log('Order: ', JSON.stringify(order, null, 2));
2829
} catch (e) {
29-
console.error(`Req error: `, e);
30+
console.error('Req error: ', e);
3031
}
3132
}
3233

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RestClient } from '../src';
1+
import { RestClient } from '../../../src/index.js';
22
// import from npm, after installing via npm `npm install bitmart-api`
33
// import { RestClient } from 'bitmart-api';
44

@@ -20,7 +20,7 @@ async function getSpotBalances() {
2020

2121
console.log('Balances: ', JSON.stringify(balances, null, 2));
2222
} catch (e) {
23-
console.error(`Req error: `, e);
23+
console.error('Req error: ', e);
2424
}
2525
}
2626

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RestClient } from '../src';
1+
import { RestClient } from '../../../src/index.js';
22
// import from npm, after installing via npm `npm install bitmart-api`
33
// import { RestClient } from 'bitmart-api';
44

@@ -10,7 +10,7 @@ async function getKlines() {
1010

1111
console.log('Tickers: ', JSON.stringify(klines, null, 2));
1212
} catch (e) {
13-
console.error(`Req error: `, e);
13+
console.error('Req error: ', e);
1414
}
1515
}
1616

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RestClient } from '../src';
1+
import { RestClient } from '../../../src/index.js';
22
// import from npm, after installing via npm `npm install bitmart-api`
33
// import { RestClient } from 'bitmart-api';
44

@@ -10,7 +10,7 @@ async function getTickers() {
1010

1111
console.log('Tickers: ', JSON.stringify(tickers, null, 2));
1212
} catch (e) {
13-
console.error(`Req error: `, e);
13+
console.error('Req error: ', e);
1414
}
1515
}
1616

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RestClient } from '../src';
1+
import { RestClient } from '../../../src/index.js';
22
// import from npm, after installing via npm `npm install bitmart-api`
33
// import { RestClient } from 'bitmart-api';
44

@@ -43,7 +43,7 @@ async function start() {
4343
});
4444
console.log('res ', JSON.stringify(res, null, 2));
4545
} catch (e) {
46-
console.error(`Req error: `, e);
46+
console.error('Req error: ', e);
4747
}
4848
}
4949

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DefaultLogger, LogParams, WebsocketClient } from '../src';
1+
import { DefaultLogger, LogParams, WebsocketClient } from '../../src/index.js';
22
// import from npm, after installing via npm `npm install bitmart-api`
33
// import { DefaultLogger, LogParams, WebsocketClient } from 'bitmart-api';
44

@@ -59,7 +59,7 @@ async function start() {
5959
client.subscribe('spot/ticker:BTC_USDT', 'spot');
6060
//
6161
} catch (e) {
62-
console.error(`Req error: `, e);
62+
console.error('Req error: ', e);
6363
}
6464
}
6565

0 commit comments

Comments
 (0)