binance-connector-node
binance-connector-node copied to clipboard
Add type declarations
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
Yep, this would definitely be helpful. The docs aren't very rich either.
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.
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.
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.
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;
}>;
}
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
this would be nice to have
Any progress on this? @ishuen
Looking forward to use this package as soon as types will be implemented.
Any progress on this? @ishuen
@2pd @aisling11 Please take a look at this, thanks.
+1 for adding typescript types on this library!
+1 for this feature request.
+1
+1
+1
+1
any update ?
Very much needed... can't work without TS, it became part of me. If any help with types is needed, I'm here.
@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, });
Any updates on this? Are they even working on this feature?