@medievalrain/binance-ts 0.10.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +203 -1
- package/dist/index.js +83 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -795,4 +795,206 @@ type FuturesChannels = {
|
|
|
795
795
|
//#region src/websocket/futures/client.d.ts
|
|
796
796
|
declare const createFuturesWebsocketClient: (baseUrl?: string) => WebsocketClient<FuturesChannels>;
|
|
797
797
|
//#endregion
|
|
798
|
-
|
|
798
|
+
//#region src/websocket/futures/types/user.d.ts
|
|
799
|
+
type FuturesListenKeyExpiredEvent = {
|
|
800
|
+
e: "listenKeyExpired";
|
|
801
|
+
E: number;
|
|
802
|
+
listenKey: string;
|
|
803
|
+
};
|
|
804
|
+
type FuturesAccountUpdateEventReason = "DEPOSIT" | "WITHDRAW" | "ORDER" | "FUNDING_FEE" | "WITHDRAW_REJECT" | "ADJUSTMENT" | "INSURANCE_CLEAR" | "ADMIN_DEPOSIT" | "ADMIN_WITHDRAW" | "MARGIN_TRANSFER" | "MARGIN_TYPE_CHANGE" | "ASSET_TRANSFER" | "OPTIONS_PREMIUM_FEE" | "OPTIONS_SETTLE_PROFIT" | "AUTO_EXCHANGE" | "COIN_SWAP_DEPOSIT" | "COIN_SWAP_WITHDRAW";
|
|
805
|
+
type FuturesAccountUpdateEventBalance = {
|
|
806
|
+
a: string;
|
|
807
|
+
wb: string;
|
|
808
|
+
cw: string;
|
|
809
|
+
bc: string;
|
|
810
|
+
};
|
|
811
|
+
type FuturesPositionSide$1 = "LONG" | "SHORT";
|
|
812
|
+
type FuturesAccountUpdateEventPosition = {
|
|
813
|
+
s: string;
|
|
814
|
+
pa: string;
|
|
815
|
+
ep: string;
|
|
816
|
+
bep: string;
|
|
817
|
+
cr: string;
|
|
818
|
+
up: string;
|
|
819
|
+
mt: "isolated" & string & {};
|
|
820
|
+
iw: string;
|
|
821
|
+
ps: FuturesPositionSide$1;
|
|
822
|
+
};
|
|
823
|
+
type FuturesAccountUpdateEvent = {
|
|
824
|
+
e: "ACCOUNT_UPDATE";
|
|
825
|
+
E: number;
|
|
826
|
+
T: number;
|
|
827
|
+
a: {
|
|
828
|
+
m: FuturesAccountUpdateEventReason;
|
|
829
|
+
B: FuturesAccountUpdateEventBalance[];
|
|
830
|
+
P: FuturesAccountUpdateEventPosition[];
|
|
831
|
+
};
|
|
832
|
+
};
|
|
833
|
+
type FuturesMarginCallPosition = {
|
|
834
|
+
s: string;
|
|
835
|
+
ps: FuturesPositionSide$1;
|
|
836
|
+
pa: string;
|
|
837
|
+
mt: "CROSSED" | "ISOLATED";
|
|
838
|
+
iw: string;
|
|
839
|
+
mp: string;
|
|
840
|
+
up: string;
|
|
841
|
+
mm: string;
|
|
842
|
+
};
|
|
843
|
+
type FuturesMarginCallEvent = {
|
|
844
|
+
e: "MARGIN_CALL";
|
|
845
|
+
E: number;
|
|
846
|
+
cw: string;
|
|
847
|
+
p: FuturesMarginCallPosition[];
|
|
848
|
+
};
|
|
849
|
+
type FuturesOrderType$1 = "LIMIT" | "MARKET" | "STOP" | "STOP_MARKET" | "TAKE_PROFIT" | "TAKE_PROFIT_MARKET" | "TRAILING_STOP_MARKET" | "LIQUIDATION";
|
|
850
|
+
type FuturesOrderTimeInForce = "GTC" | "IOC" | "FOK" | "GTX";
|
|
851
|
+
type FuturesOrderExecutionType = "NEW" | "CANCELED" | "CALCULATED" | "EXPIRED" | "TRADE" | "AMENDMENT";
|
|
852
|
+
type FuturesOrderStatus = "NEW" | "PARTIALLY_FILLED" | "FILLED" | "CANCELED" | "EXPIRED" | "EXPIRED_IN_MATCH";
|
|
853
|
+
type FuturesOrderSide$1 = "BUY" | "SELL";
|
|
854
|
+
type FuturesOrderWorkingType = "CONTRACT_PRICE" | "MARK_PRICE";
|
|
855
|
+
type FuturesOrderUpdateEvent = {
|
|
856
|
+
e: "ORDER_TRADE_UPDATE";
|
|
857
|
+
E: number;
|
|
858
|
+
T: number;
|
|
859
|
+
o: {
|
|
860
|
+
s: string;
|
|
861
|
+
c: string;
|
|
862
|
+
S: FuturesOrderSide$1;
|
|
863
|
+
o: FuturesOrderType$1;
|
|
864
|
+
f: FuturesOrderTimeInForce;
|
|
865
|
+
q: string;
|
|
866
|
+
p: string;
|
|
867
|
+
ap: string;
|
|
868
|
+
sp: string;
|
|
869
|
+
x: FuturesOrderExecutionType;
|
|
870
|
+
X: FuturesOrderStatus;
|
|
871
|
+
i: number;
|
|
872
|
+
l: string;
|
|
873
|
+
z: string;
|
|
874
|
+
L: string;
|
|
875
|
+
N: string;
|
|
876
|
+
n: string;
|
|
877
|
+
T: number;
|
|
878
|
+
t: number;
|
|
879
|
+
b: string;
|
|
880
|
+
a: string;
|
|
881
|
+
m: boolean;
|
|
882
|
+
R: boolean;
|
|
883
|
+
wt: FuturesOrderWorkingType;
|
|
884
|
+
ot: "TRAILING_STOP_MARKET";
|
|
885
|
+
ps: FuturesPositionSide$1;
|
|
886
|
+
cp: boolean;
|
|
887
|
+
AP: string;
|
|
888
|
+
cr: string;
|
|
889
|
+
pP: boolean;
|
|
890
|
+
si: number;
|
|
891
|
+
ss: number;
|
|
892
|
+
rp: string;
|
|
893
|
+
V: "EXPIRE_TAKER";
|
|
894
|
+
pm: "OPPONENT";
|
|
895
|
+
gtd: number;
|
|
896
|
+
er: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
897
|
+
};
|
|
898
|
+
};
|
|
899
|
+
type FuturesTradeLiteEvent = {
|
|
900
|
+
e: "TRADE_LITE";
|
|
901
|
+
E: number;
|
|
902
|
+
T: number;
|
|
903
|
+
s: string;
|
|
904
|
+
q: string;
|
|
905
|
+
p: string;
|
|
906
|
+
m: boolean;
|
|
907
|
+
c: string;
|
|
908
|
+
S: FuturesPositionSide$1;
|
|
909
|
+
L: string;
|
|
910
|
+
l: string;
|
|
911
|
+
t: number;
|
|
912
|
+
i: number;
|
|
913
|
+
};
|
|
914
|
+
type AccountConfigUpdateEvent = {
|
|
915
|
+
e: "ACCOUNT_CONFIG_UPDATE";
|
|
916
|
+
E: number;
|
|
917
|
+
T: number;
|
|
918
|
+
} & ({
|
|
919
|
+
ac: {
|
|
920
|
+
s: string;
|
|
921
|
+
l: number;
|
|
922
|
+
};
|
|
923
|
+
} | {
|
|
924
|
+
ai: {
|
|
925
|
+
j: boolean;
|
|
926
|
+
};
|
|
927
|
+
});
|
|
928
|
+
type FuturesStrategyStatus = "NEW" | "WORKING" | "CANCELLED" | "EXPIRED";
|
|
929
|
+
type FuturesStrategyUpdateEvent = {
|
|
930
|
+
e: "STRATEGY_UPDATE";
|
|
931
|
+
T: number;
|
|
932
|
+
E: number;
|
|
933
|
+
su: {
|
|
934
|
+
si: number;
|
|
935
|
+
st: "GRID";
|
|
936
|
+
ss: FuturesStrategyStatus;
|
|
937
|
+
s: string;
|
|
938
|
+
ut: number;
|
|
939
|
+
c: 8001 | 8002 | 8003 | 8004 | 8005 | 8006 | 8007 | 8008 | 8009 | 8010 | 8011 | 8012 | 8013 | 8014 | 8015;
|
|
940
|
+
};
|
|
941
|
+
};
|
|
942
|
+
type FuturesGridUpdateEvent = {
|
|
943
|
+
e: "GRID_UPDATE";
|
|
944
|
+
T: number;
|
|
945
|
+
E: number;
|
|
946
|
+
gu: {
|
|
947
|
+
si: number;
|
|
948
|
+
st: "GRID";
|
|
949
|
+
ss: FuturesStrategyStatus;
|
|
950
|
+
s: string;
|
|
951
|
+
r: string;
|
|
952
|
+
up: string;
|
|
953
|
+
uq: string;
|
|
954
|
+
uf: string;
|
|
955
|
+
mp: string;
|
|
956
|
+
ut: number;
|
|
957
|
+
};
|
|
958
|
+
};
|
|
959
|
+
type FuturesConditionalOrderTriggerRejectEvent = {
|
|
960
|
+
e: "CONDITIONAL_ORDER_TRIGGER_REJECT";
|
|
961
|
+
T: number;
|
|
962
|
+
E: number;
|
|
963
|
+
or: {
|
|
964
|
+
s: string;
|
|
965
|
+
i: number;
|
|
966
|
+
r: string;
|
|
967
|
+
};
|
|
968
|
+
};
|
|
969
|
+
type FuturesUserEvent = FuturesListenKeyExpiredEvent | FuturesAccountUpdateEvent | FuturesMarginCallEvent | FuturesOrderUpdateEvent | FuturesTradeLiteEvent | AccountConfigUpdateEvent | FuturesStrategyUpdateEvent | FuturesGridUpdateEvent | FuturesConditionalOrderTriggerRejectEvent;
|
|
970
|
+
declare const futuresEventRouting: {
|
|
971
|
+
readonly listenKeyExpired: "listenKeyExpired";
|
|
972
|
+
readonly accountUpdate: "ACCOUNT_UPDATE";
|
|
973
|
+
readonly marginCall: "MARGIN_CALL";
|
|
974
|
+
readonly orderTradeUpdate: "ORDER_TRADE_UPDATE";
|
|
975
|
+
readonly tradeLite: "TRADE_LITE";
|
|
976
|
+
readonly accountConfigUpdate: "ACCOUNT_CONFIG_UPDATE";
|
|
977
|
+
readonly strategyUpdate: "STRATEGY_UPDATE";
|
|
978
|
+
readonly gridUpdate: "GRID_UPDATE";
|
|
979
|
+
readonly conditionalOrderTriggerReject: "CONDITIONAL_ORDER_TRIGGER_REJECT";
|
|
980
|
+
};
|
|
981
|
+
type InferFutruresUserEvent<EventName extends FuturesUserEvent["e"]> = Extract<FuturesUserEvent, {
|
|
982
|
+
e: EventName;
|
|
983
|
+
}>;
|
|
984
|
+
type FuturesUserWebsocketClient = { [MethodName in keyof typeof futuresEventRouting]: {
|
|
985
|
+
on: (callback: (data: InferFutruresUserEvent<(typeof futuresEventRouting)[MethodName]>, options?: CallbackOptions) => void) => void;
|
|
986
|
+
off: (callback: (data: InferFutruresUserEvent<(typeof futuresEventRouting)[MethodName]>, options?: CallbackOptions) => void, options?: CallbackOptions) => void;
|
|
987
|
+
} };
|
|
988
|
+
//#endregion
|
|
989
|
+
//#region src/websocket/futures/user.d.ts
|
|
990
|
+
declare const createFuturesUserWebsocketClient: ({
|
|
991
|
+
baseUrl,
|
|
992
|
+
apiKey,
|
|
993
|
+
apiSecret
|
|
994
|
+
}: {
|
|
995
|
+
baseUrl?: string;
|
|
996
|
+
apiKey: string;
|
|
997
|
+
apiSecret: string;
|
|
998
|
+
}) => Promise<FuturesUserWebsocketClient>;
|
|
999
|
+
//#endregion
|
|
1000
|
+
export { ApiError, BinanceRestClient, ErrorMessageParsingError, FuturesAccountAsset, FuturesAccountBalance, FuturesAccountConfig, FuturesAccountInfo, FuturesAccountPosition, FuturesAggTradeEvent, FuturesAggregateTrade, FuturesAssetIndex, FuturesBasis, FuturesBookDepthEvent, FuturesBookTicker, FuturesBookTickerEvent, FuturesCheckServerTime, FuturesCommissionRate, FuturesCompositeIndex, FuturesCompositeIndexAsset, FuturesContractType, FuturesDeliveryPrice, FuturesExchangeInfo, FuturesExchangeInfoAsset, FuturesExchangeInfoFilter, FuturesExchangeInfoRateLimit, FuturesExchangeInfoSymbol, FuturesFundingInfo, FuturesFundingRate, FuturesGetListenKey, FuturesIncomeHistory, FuturesIncomeType, FuturesIndexPriceConstituentItem, FuturesIndexPriceConstituents, FuturesInsuranceBalance, FuturesInsuranceBalanceAsset, FuturesKline, FuturesKlineInterval, FuturesLeverageBracket, FuturesLeverageBracketEntry, FuturesLongShortRatio, FuturesMarkPrice, FuturesNewOrder, FuturesNewOrderRespType, FuturesOpenInterest, FuturesOpenInterestPeriod, FuturesOpenInterestStats, FuturesOrderBook, FuturesOrderSide, FuturesOrderType, FuturesPositionMode, FuturesPositionSide, FuturesPriceMatch, FuturesSelfTradePrevention, FuturesSymbolConfig, FuturesSymbolPrice, FuturesTakerBuySellRatio, FuturesTestConnectivity, FuturesTicker24h, FuturesTimeInForce, FuturesTrade, FuturesUnderlyingType, FuturesUserRateLimit, FuturesWorkingType, MalformedParamError, PermissionSet, ResponseError, WeightError, createFuturesUserWebsocketClient, createFuturesWebsocketClient };
|
package/dist/index.js
CHANGED
|
@@ -604,4 +604,86 @@ const createFuturesWebsocketClient = (baseUrl = "wss://stream.binance.com:9443/w
|
|
|
604
604
|
};
|
|
605
605
|
|
|
606
606
|
//#endregion
|
|
607
|
-
|
|
607
|
+
//#region src/websocket/futures/types/user.ts
|
|
608
|
+
const futuresEventRouting = {
|
|
609
|
+
listenKeyExpired: "listenKeyExpired",
|
|
610
|
+
accountUpdate: "ACCOUNT_UPDATE",
|
|
611
|
+
marginCall: "MARGIN_CALL",
|
|
612
|
+
orderTradeUpdate: "ORDER_TRADE_UPDATE",
|
|
613
|
+
tradeLite: "TRADE_LITE",
|
|
614
|
+
accountConfigUpdate: "ACCOUNT_CONFIG_UPDATE",
|
|
615
|
+
strategyUpdate: "STRATEGY_UPDATE",
|
|
616
|
+
gridUpdate: "GRID_UPDATE",
|
|
617
|
+
conditionalOrderTriggerReject: "CONDITIONAL_ORDER_TRIGGER_REJECT"
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
//#endregion
|
|
621
|
+
//#region src/websocket/futures/user.ts
|
|
622
|
+
const createFuturesUserWebsocketClient = async ({ baseUrl = "wss://fstream.binance.com/ws", apiKey, apiSecret }) => {
|
|
623
|
+
let socket;
|
|
624
|
+
const futuresRestClient = new FuturesRestClient({
|
|
625
|
+
apiKey,
|
|
626
|
+
apiSecret
|
|
627
|
+
});
|
|
628
|
+
let connectionController = new AbortController();
|
|
629
|
+
let listenKeyUpdateInterval;
|
|
630
|
+
const emitter = createEmitter();
|
|
631
|
+
const invertedRouting = Object.fromEntries(Object.entries(futuresEventRouting).map(([key, value]) => [value, key]));
|
|
632
|
+
const parseMessageEvent = (e) => {
|
|
633
|
+
if (typeof e.data !== "string") return;
|
|
634
|
+
const data = JSON.parse(e.data);
|
|
635
|
+
const routedEvent = invertedRouting[data.e];
|
|
636
|
+
emitter.emit(routedEvent, data);
|
|
637
|
+
};
|
|
638
|
+
const on = (method, callback, options) => {
|
|
639
|
+
emitter.on(method, callback, options);
|
|
640
|
+
};
|
|
641
|
+
const off = (method, callback) => {
|
|
642
|
+
emitter.off(method, callback);
|
|
643
|
+
};
|
|
644
|
+
const connect = async () => {
|
|
645
|
+
return new Promise((resolve) => {
|
|
646
|
+
if (!socket || socket.readyState === WebSocket.CLOSED) {
|
|
647
|
+
clearInterval(listenKeyUpdateInterval);
|
|
648
|
+
futuresRestClient.getListenKey().then(({ listenKey: newListenKey }) => {
|
|
649
|
+
let listenKey = newListenKey;
|
|
650
|
+
let url = `${baseUrl}/${listenKey}`;
|
|
651
|
+
listenKeyUpdateInterval = setInterval(async () => {
|
|
652
|
+
listenKey = (await futuresRestClient.getListenKey()).listenKey;
|
|
653
|
+
}, 30 * 1e3 * 60);
|
|
654
|
+
connectionController.abort();
|
|
655
|
+
socket = new WebSocket(url);
|
|
656
|
+
connectionController = new AbortController();
|
|
657
|
+
socket.addEventListener("open", () => {
|
|
658
|
+
socket.addEventListener("message", parseMessageEvent, { signal: connectionController.signal });
|
|
659
|
+
resolve();
|
|
660
|
+
}, { once: true });
|
|
661
|
+
});
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
if (socket.readyState === WebSocket.OPEN) return resolve();
|
|
665
|
+
if (socket.readyState === WebSocket.CONNECTING) socket.addEventListener("open", () => {
|
|
666
|
+
socket.addEventListener("message", parseMessageEvent, { signal: connectionController.signal });
|
|
667
|
+
resolve();
|
|
668
|
+
}, { once: true });
|
|
669
|
+
if (socket.readyState === WebSocket.CLOSING) socket.addEventListener("close", async () => {
|
|
670
|
+
await connect();
|
|
671
|
+
resolve();
|
|
672
|
+
}, { once: true });
|
|
673
|
+
});
|
|
674
|
+
};
|
|
675
|
+
await connect();
|
|
676
|
+
return new Proxy({}, { get(_target, method) {
|
|
677
|
+
return Object.freeze({
|
|
678
|
+
on: (callback, options) => {
|
|
679
|
+
on(method, callback, options);
|
|
680
|
+
},
|
|
681
|
+
off: (callback) => {
|
|
682
|
+
off(method, callback);
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
} });
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
//#endregion
|
|
689
|
+
export { ApiError, BinanceRestClient, ErrorMessageParsingError, MalformedParamError, ResponseError, WeightError, createFuturesUserWebsocketClient, createFuturesWebsocketClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medievalrain/binance-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Binance API SDK",
|
|
5
5
|
"access": "public",
|
|
6
6
|
"type": "module",
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
"oxlint": "1.24.0",
|
|
32
32
|
"prettier": "3.6.2",
|
|
33
33
|
"ts-to-zod": "5.0.1",
|
|
34
|
-
"tsdown": "0.15.
|
|
34
|
+
"tsdown": "0.15.11",
|
|
35
35
|
"typescript": "5.9.3",
|
|
36
|
-
"vitest": "4.0.
|
|
36
|
+
"vitest": "4.0.4",
|
|
37
37
|
"zod": "4.1.12"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@medievalrain/emitter": "0.
|
|
40
|
+
"@medievalrain/emitter": "0.8.0"
|
|
41
41
|
},
|
|
42
42
|
"repository": {
|
|
43
43
|
"type": "git",
|