binance-connector-node icon indicating copy to clipboard operation
binance-connector-node copied to clipboard

Add type declarations

Open luukvhoudt opened this issue 3 years ago • 19 comments

Issue subject

Add type declarations for typescript (*.d.ts).

Expected behaviour

When importing this package I would expect it to allocate type declarations for it.

Actual behaviour

No type declarations are available and thus switching back and forth to the online examples and/or source is the only way to figure out what types/signature this package includes

Steps to reproduce

Download the package in a typescript project and try to type hint response from certain functions for example.

Environment

Provide any relevant information about your setup, such as:

  • Version of binance-connector-node: 1.1.0
  • Node version: 14.17.5
  • Operating system: Ubuntu 21.04

luukvhoudt avatar Aug 18 '21 11:08 luukvhoudt

Yep, this would definitely be helpful. The docs aren't very rich either.

Senseye avatar Aug 20 '21 12:08 Senseye

Thanks for the feedbacks. In addition to the type definition file, could you also list out which part is not clear enough in the current document? It will be helpful for us to improve the package.

ishuen avatar Aug 20 '21 13:08 ishuen

The documentation looks pretty well written as well as the examples are to good use. I didn't utilize this API to it's fullest potential yet thus as of now I'm unable to give extensive feedback about that.

This issue was created to only tackle the lack of type declaration what usually improves the "in editor" documentation.

luukvhoudt avatar Aug 24 '21 07:08 luukvhoudt

Thanks for the reply. Since the current implementation involves mix-in, which allows the classes to dynamically extend multiple classes during run time, it might have some difficulties to provide typescript definition. We will try to figure out how to achieve it without impacting the current behaviour and code maintainability.

ishuen avatar Aug 25 '21 06:08 ishuen

I will try to share interfaces I write along the way while working on my project that uses this library. I will try to base these interfaces as much as possible on the documentation available from this library as well as the Binance API.

The first batch of interfaces I would like to share are the once for userData(listenKey, callbacks).

NOTE: the event parameter in the message callback is currently a JSON string. Please add JSON.parse(str) here before passing it to the callback.

export interface StreamBaseEvent {
	e: string;
	E: number;
}

export interface StreamCallbacks<E extends StreamBaseEvent> = {
	open: () => void;
	close: () => void;
	message: (event: E) => void;
};

export type UserDataStreamFn =
	(listenKey: string, callbacks: StreamCallbacks<UserDataStreamEvent>) => WebSocketClient;

export type UserDataStreamEvent =
	UserDataStreamOutboundAccountPositionEvent
	| UserDataStreamBalanceUpdateEvent
	| UserDataStreamExecutionReportEvent
	| UserDataStreamListStatusEvent;

export interface UserDataStreamOutboundAccountPositionEvent extends StreamBaseEvent {
	e: 'outboundAccountPosition';
	u: number;
	B: Array<{
		a: string;
		f: string; // decimal
		l: string; // decimal
	}>;
}

export interface UserDataStreamBalanceUpdateEvent extends StreamBaseEvent {
	e: 'balanceUpdate';
	a: string;
	d: string; // decimal
	T: number;
}

export interface UserDataStreamExecutionReportEvent extends StreamBaseEvent {
	e: 'executionReport';
	s: string;
	c: string;
	S: 'BUY' | 'SELL';
	o: 'LIMIT' | 'MARKET' | 'STOP_LOSS' | 'STOP_LOSS_LIMIT' | 'TAKE_PROFIT' | 'TAKE_PROFIT_LIMIT' | 'LIMIT_MAKER';
	f: 'GTC' | 'FOK' | 'IOC';
	q: string; // decimal
	p: string; // decimal
	P: string; // decimal
	F: string; // decimal
	g: number;
	C: string;
	x: 'NEW' | 'CANCELED' | 'REPLACED' | 'REJECTED' | 'TRADE' | 'EXPIRED';
	X: 'NEW' | 'PARTIALLY_FILLED' | 'FILLED' | 'CANCELED' | 'PENDING_CANCEL' | 'REJECTED' | 'EXPIRED';
	r: 'NONE' | number;
	i: number;
	l: string; // decimal
	z: string; // decimal
	L: string; // decimal
	n: string; // decimal
	N: null | string;
	T: number;
	t: number;
	I: number;
	w: boolean;
	m: boolean;
	M: boolean;
	O: number;
	Z: string; // decimal
	Y: string; // decimal
	Q: string; // decimal
}

export interface UserDataStreamListStatusEvent extends StreamBaseEvent {
	e: 'listStatus';
	s: string;
	g: number;
	c: 'OCO';
	l: 'RESPONSE' | 'EXEC_STARTED' | 'ALL_DONE';
	L: 'EXECUTING' | 'ALL_DONE' | 'REJECT';
	r: 'NONE' | number;
	C: string;
	T: number;
	O: Array<{
		s: string;
		i: number;
		c: string;
	}>;
}

luukvhoudt avatar Aug 31 '21 14:08 luukvhoudt

export interface StreamCallbacks<E extends StreamBaseEvent> = {
	open: () => void;
	close: () => void;
	message: (event: E) => void;
};

Extra "=" in this interface, should be:

export interface StreamCallbacks<E extends StreamBaseEvent> {
	open: () => void;
	close: () => void;
	message: (event: E) => void;
};

@luukvhoudt

elquimeras avatar Sep 05 '21 14:09 elquimeras

this would be nice to have

Cintrust avatar Oct 11 '21 15:10 Cintrust

Any progress on this? @ishuen

luukvhoudt avatar Nov 02 '21 13:11 luukvhoudt

Looking forward to use this package as soon as types will be implemented.

DontEatRice avatar Nov 04 '21 21:11 DontEatRice

Any progress on this? @ishuen

@2pd @aisling11 Please take a look at this, thanks.

ishuen avatar Nov 12 '21 10:11 ishuen

+1 for adding typescript types on this library!

gateian avatar Dec 10 '21 10:12 gateian

+1 for this feature request.

mittalshubham avatar Jan 09 '22 15:01 mittalshubham

+1

adrael avatar Jan 11 '22 16:01 adrael

+1

vivi32767 avatar Jan 14 '22 17:01 vivi32767

+1

JLTG2018 avatar Jan 15 '22 05:01 JLTG2018

+1

AndrianinaH avatar Jan 24 '22 07:01 AndrianinaH

any update ?

zhanzekun avatar Jan 27 '22 07:01 zhanzekun

Very much needed... can't work without TS, it became part of me. If any help with types is needed, I'm here.

dvlden avatar Feb 24 '22 19:02 dvlden

@ishuen thank you for your hard work on this library, but honestly working with this library hurts the soul type definitions are one thing but an example for each function in the documentation would make things much easier

like this methode : https://binance.github.io/binance-connector-node/module-Trade.html#newOrder should look like this let response = await client.newOrder("BTCUSDT", "BUY", "MARKET", { quantity: 0.001, });

armin-malek avatar Feb 27 '22 14:02 armin-malek

Any updates on this? Are they even working on this feature?

Ashu2k avatar Nov 14 '22 09:11 Ashu2k