v1.0.6: fix() fix type differences for spot vs futures candles. Add example for fetching last 1k futures candles
This commit is contained in:
30
examples/rest-public-futures.ts
Normal file
30
examples/rest-public-futures.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { FuturesClient, SpotClient } from '../src/index';
|
||||
|
||||
// or
|
||||
// import { SpotClient } from 'bitget-api';
|
||||
|
||||
const futuresClient = new FuturesClient();
|
||||
|
||||
const symbol = 'BTCUSDT_UMCBL';
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
// Fetch the last 1000 1min candles for a symbol
|
||||
const timestampNow = Date.now();
|
||||
const msPerCandle = 60 * 1000; // 60 seconds x 1000
|
||||
const candlesToFetch = 1000;
|
||||
const msFor1kCandles = candlesToFetch * msPerCandle;
|
||||
const startTime = timestampNow - msFor1kCandles;
|
||||
|
||||
const response = await futuresClient.getCandles(
|
||||
symbol,
|
||||
'1m',
|
||||
startTime.toString(),
|
||||
timestampNow.toString(),
|
||||
candlesToFetch.toString(),
|
||||
);
|
||||
console.log('getCandles returned ' + response.length + ' candles');
|
||||
} catch (e) {
|
||||
console.error('request failed: ', e);
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user