Skip to content

Could we add more comprehensive type hint to the derivatives-trading-usds-futures examples? #550

@Need-an-AwP

Description

@Need-an-AwP

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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions