The examples in clients/derivatives-trading-usds-futures/examples don't seem to have type hints to connection returned by connect() method.
and i spent a lots time to figure out how to import correct types from @binance/derivatives-trading-usds-futures, like import type { WebsocketAPIConnection } from "@binance/derivatives-trading-usds-futures"; is incorrect
until i found similar examples in spot connector:
client.websocketAPI
.connect()
.then((connection: SpotWebsocketAPI.WebsocketAPIConnection) =>
connection.exchangeInfo({ symbol: 'BNBUSDT' })
)
Therefore, this type definition should be the correct way to obtain the corresponding data in derivatives-trading-usds-futures:
type WebsocketAPIConnection = DerivativesTradingUsdsFuturesWebsocketAPI.WebsocketAPIConnection;
type WebsocketStreamsConnection = DerivativesTradingUsdsFuturesWebsocketStreams.WebsocketStreamsConnection;
i would like to add robust type hints to the examples in derivatives-trading-usds-futures as well. this might save quite amount of time of reading examples
import {
DerivativesTradingUsdsFutures,
DERIVATIVES_TRADING_USDS_FUTURES_WS_API_PROD_URL,
DerivativesTradingUsdsFuturesWebsocketAPI // new import
} from '../../../src';
const configurationWebsocketAPI = {
apiKey: process.env.API_KEY ?? '',
apiSecret: process.env.API_SECRET ?? '',
wsURL: process.env.WS_API_URL ?? DERIVATIVES_TRADING_USDS_FUTURES_WS_API_PROD_URL,
};
const client = new DerivativesTradingUsdsFutures({ configurationWebsocketAPI });
async function keepaliveUserDataStream() {
let connection: DerivativesTradingUsdsFuturesWebsocketAPI.WebsocketAPIConnection | undefined; // new defination
try {
connection = await client.websocketAPI.connect();
const response = await connection.keepaliveUserDataStream();
const rateLimits = response.rateLimits!;
console.log('keepaliveUserDataStream() rate limits:', rateLimits);
const data = response.data;
console.log('keepaliveUserDataStream() response:', data);
} catch (error) {
console.error('keepaliveUserDataStream() error:', error);
} finally {
await connection!.disconnect();
}
}
keepaliveUserDataStream();
The examples in
clients/derivatives-trading-usds-futures/examplesdon't seem to have type hints toconnectionreturned byconnect()method.and i spent a lots time to figure out how to import correct types from
@binance/derivatives-trading-usds-futures, likeimport type { WebsocketAPIConnection } from "@binance/derivatives-trading-usds-futures";is incorrectuntil i found similar examples in spot connector:
Therefore, this type definition should be the correct way to obtain the corresponding data in derivatives-trading-usds-futures:
i would like to add robust type hints to the examples in derivatives-trading-usds-futures as well. this might save quite amount of time of reading examples