ccxt 4.5.48 → 4.5.50
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/README.md +7 -5
- package/dist/ccxt.browser.min.js +10 -10
- package/dist/cjs/ccxt.js +6 -1
- package/dist/cjs/src/abstract/weex.js +11 -0
- package/dist/cjs/src/base/Exchange.js +48 -13
- package/dist/cjs/src/bitget.js +1 -0
- package/dist/cjs/src/btcbox.js +1 -1
- package/dist/cjs/src/bullish.js +2 -1
- package/dist/cjs/src/gate.js +0 -1
- package/dist/cjs/src/hibachi.js +1 -1
- package/dist/cjs/src/kraken.js +1 -0
- package/dist/cjs/src/krakenfutures.js +10 -1
- package/dist/cjs/src/kucoin.js +5 -1
- package/dist/cjs/src/lighter.js +312 -144
- package/dist/cjs/src/mexc.js +7 -12
- package/dist/cjs/src/okx.js +46 -1
- package/dist/cjs/src/paradex.js +5 -2
- package/dist/cjs/src/pro/binance.js +1 -1
- package/dist/cjs/src/pro/cex.js +1 -1
- package/dist/cjs/src/pro/coinbase.js +1 -1
- package/dist/cjs/src/pro/hyperliquid.js +361 -1
- package/dist/cjs/src/pro/lighter.js +339 -18
- package/dist/cjs/src/pro/weex.js +1906 -0
- package/dist/cjs/src/weex.js +3823 -0
- package/js/ccxt.d.ts +8 -2
- package/js/ccxt.js +6 -2
- package/js/src/abstract/myokx.d.ts +34 -0
- package/js/src/abstract/okx.d.ts +34 -0
- package/js/src/abstract/okxus.d.ts +34 -0
- package/js/src/abstract/weex.d.ts +83 -0
- package/js/src/abstract/weex.js +11 -0
- package/js/src/base/Exchange.d.ts +5 -1
- package/js/src/base/Exchange.js +48 -13
- package/js/src/bitget.js +1 -0
- package/js/src/btcbox.js +1 -1
- package/js/src/bullish.js +2 -1
- package/js/src/gate.js +0 -1
- package/js/src/hibachi.js +1 -1
- package/js/src/kraken.js +1 -0
- package/js/src/krakenfutures.js +10 -1
- package/js/src/kucoin.d.ts +4 -0
- package/js/src/kucoin.js +5 -1
- package/js/src/lighter.d.ts +12 -2
- package/js/src/lighter.js +313 -145
- package/js/src/mexc.d.ts +2 -0
- package/js/src/mexc.js +7 -12
- package/js/src/okx.js +46 -1
- package/js/src/paradex.js +5 -2
- package/js/src/pro/binance.js +1 -1
- package/js/src/pro/cex.js +1 -1
- package/js/src/pro/coinbase.js +1 -1
- package/js/src/pro/hyperliquid.d.ts +48 -1
- package/js/src/pro/hyperliquid.js +362 -2
- package/js/src/pro/lighter.d.ts +37 -2
- package/js/src/pro/lighter.js +339 -18
- package/js/src/pro/weex.d.ts +330 -0
- package/js/src/pro/weex.js +1905 -0
- package/js/src/weex.d.ts +675 -0
- package/js/src/weex.js +3822 -0
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// ---------------------------------------------------------------------------
|
|
8
8
|
import hyperliquidRest from '../hyperliquid.js';
|
|
9
9
|
import { NotSupported } from '../base/errors.js';
|
|
10
|
-
import { ArrayCache, ArrayCacheByTimestamp, ArrayCacheBySymbolById } from '../base/ws/Cache.js';
|
|
10
|
+
import { ArrayCache, ArrayCacheByTimestamp, ArrayCacheBySymbolById, ArrayCacheBySymbolBySide } from '../base/ws/Cache.js';
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
12
|
export default class hyperliquid extends hyperliquidRest {
|
|
13
13
|
describe() {
|
|
@@ -19,7 +19,7 @@ export default class hyperliquid extends hyperliquidRest {
|
|
|
19
19
|
'createOrderWs': true,
|
|
20
20
|
'createOrdersWs': true,
|
|
21
21
|
'editOrderWs': true,
|
|
22
|
-
'watchBalance':
|
|
22
|
+
'watchBalance': true,
|
|
23
23
|
'watchMyTrades': true,
|
|
24
24
|
'watchOHLCV': true,
|
|
25
25
|
'watchOrderBook': true,
|
|
@@ -29,6 +29,9 @@ export default class hyperliquid extends hyperliquidRest {
|
|
|
29
29
|
'watchTrades': true,
|
|
30
30
|
'watchTradesForSymbols': false,
|
|
31
31
|
'watchPosition': false,
|
|
32
|
+
'unWatchBalance': true,
|
|
33
|
+
'watchPositions': true,
|
|
34
|
+
'unWatchPositions': true,
|
|
32
35
|
'unWatchOrderBook': true,
|
|
33
36
|
'unWatchTickers': true,
|
|
34
37
|
'unWatchTrades': true,
|
|
@@ -912,6 +915,334 @@ export default class hyperliquid extends hyperliquidRest {
|
|
|
912
915
|
const payload = this.safeDict(response, 'payload');
|
|
913
916
|
client.resolve(payload, id);
|
|
914
917
|
}
|
|
918
|
+
/**
|
|
919
|
+
* @method
|
|
920
|
+
* @name hyperliquid#watchBalance
|
|
921
|
+
* @description watch balance and get the amount of funds available for trading or funds locked in orders
|
|
922
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
923
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
924
|
+
* @param {string} [params.dex] for for hip3 tokens subscription, eg: 'xyz' or 'flx'
|
|
925
|
+
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
|
|
926
|
+
*/
|
|
927
|
+
async watchBalance(params = {}) {
|
|
928
|
+
await this.loadMarkets();
|
|
929
|
+
let userAddress = undefined;
|
|
930
|
+
[userAddress, params] = this.handlePublicAddress('watchBalance', params);
|
|
931
|
+
let type = undefined;
|
|
932
|
+
[type, params] = this.handleMarketTypeAndParams('watchBalance', undefined, params);
|
|
933
|
+
let isUnifiedEnabled = undefined;
|
|
934
|
+
[isUnifiedEnabled, params] = await this.isUnifiedEnabled('watchBalance', userAddress, false, params);
|
|
935
|
+
const dex = this.safeString(params, 'dex');
|
|
936
|
+
const isSpot = ((type === 'spot') || isUnifiedEnabled) && (dex === undefined);
|
|
937
|
+
const topic = (isSpot) ? 'spotState' : 'clearinghouseState';
|
|
938
|
+
const messageHash = topic + '::balance';
|
|
939
|
+
const url = this.urls['api']['ws']['public'];
|
|
940
|
+
const subscription = {
|
|
941
|
+
'type': topic,
|
|
942
|
+
'user': userAddress,
|
|
943
|
+
};
|
|
944
|
+
if (isSpot) {
|
|
945
|
+
if (isUnifiedEnabled) {
|
|
946
|
+
subscription['isPortfolioMargin'] = true;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
else {
|
|
950
|
+
if (dex !== undefined) {
|
|
951
|
+
subscription['dex'] = dex;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
const request = {
|
|
955
|
+
'method': 'subscribe',
|
|
956
|
+
'subscription': subscription,
|
|
957
|
+
};
|
|
958
|
+
const message = this.extend(request, params);
|
|
959
|
+
return await this.watch(url, messageHash, message, topic);
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* @method
|
|
963
|
+
* @name hyperliquid#unWatchBalance
|
|
964
|
+
* @description unWatches balance
|
|
965
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
966
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
967
|
+
* @returns {object} status of the unwatch request
|
|
968
|
+
*/
|
|
969
|
+
async unWatchBalance(params = {}) {
|
|
970
|
+
await this.loadMarkets();
|
|
971
|
+
const url = this.urls['api']['ws']['public'];
|
|
972
|
+
let userAddress = undefined;
|
|
973
|
+
[userAddress, params] = this.handlePublicAddress('unWatchBalance', params);
|
|
974
|
+
let type = undefined;
|
|
975
|
+
[type, params] = this.handleMarketTypeAndParams('unWatchBalance', undefined, params);
|
|
976
|
+
let isUnifiedEnabled = undefined;
|
|
977
|
+
[isUnifiedEnabled, params] = await this.isUnifiedEnabled('unWatchBalance', userAddress, false, params);
|
|
978
|
+
const dex = this.safeString(params, 'dex');
|
|
979
|
+
const isSpot = ((type === 'spot') || isUnifiedEnabled) && (dex === undefined);
|
|
980
|
+
const topic = (isSpot) ? 'spotState' : 'clearinghouseState';
|
|
981
|
+
const messageHash = 'unsubscribe' + ':' + topic;
|
|
982
|
+
const request = {
|
|
983
|
+
'method': 'unsubscribe',
|
|
984
|
+
'subscription': {
|
|
985
|
+
'type': topic,
|
|
986
|
+
'user': userAddress,
|
|
987
|
+
},
|
|
988
|
+
};
|
|
989
|
+
const message = this.extend(request, params);
|
|
990
|
+
return await this.watch(url, messageHash, message, messageHash);
|
|
991
|
+
}
|
|
992
|
+
handleBalance(client, message) {
|
|
993
|
+
//
|
|
994
|
+
// spot
|
|
995
|
+
// {
|
|
996
|
+
// "channel": "spotState",
|
|
997
|
+
// "data": {
|
|
998
|
+
// "user": "0xeeeeexxxxeeeee",
|
|
999
|
+
// "spotState": {
|
|
1000
|
+
// "balances": [
|
|
1001
|
+
// {
|
|
1002
|
+
// "coin": "USDH",
|
|
1003
|
+
// "token": 360,
|
|
1004
|
+
// "total": "0.0",
|
|
1005
|
+
// "hold": "0.0",
|
|
1006
|
+
// "entryNtl": "0.0"
|
|
1007
|
+
// }
|
|
1008
|
+
// ],
|
|
1009
|
+
// "tokenToAvailableAfterMaintenance": [
|
|
1010
|
+
// [
|
|
1011
|
+
// 0,
|
|
1012
|
+
// "56.1"
|
|
1013
|
+
// ]
|
|
1014
|
+
// ]
|
|
1015
|
+
// }
|
|
1016
|
+
// }
|
|
1017
|
+
// }
|
|
1018
|
+
// swap
|
|
1019
|
+
// {
|
|
1020
|
+
// "channel": "clearinghouseState",
|
|
1021
|
+
// "data": {
|
|
1022
|
+
// "dex": "",
|
|
1023
|
+
// "user": "0xeeeeexxxxeeeee",
|
|
1024
|
+
// "clearinghouseState": {
|
|
1025
|
+
// "marginSummary": {
|
|
1026
|
+
// "accountValue": "0.0",
|
|
1027
|
+
// "totalNtlPos": "0.0",
|
|
1028
|
+
// "totalRawUsd": "0.0",
|
|
1029
|
+
// "totalMarginUsed": "0.0"
|
|
1030
|
+
// },
|
|
1031
|
+
// "crossMarginSummary": {
|
|
1032
|
+
// "accountValue": "0.0",
|
|
1033
|
+
// "totalNtlPos": "0.0",
|
|
1034
|
+
// "totalRawUsd": "0.0",
|
|
1035
|
+
// "totalMarginUsed": "0.0"
|
|
1036
|
+
// },
|
|
1037
|
+
// "crossMaintenanceMarginUsed": "0.0",
|
|
1038
|
+
// "withdrawable": "0.0",
|
|
1039
|
+
// "assetPositions": [],
|
|
1040
|
+
// "time": 1776000003409
|
|
1041
|
+
// }
|
|
1042
|
+
// }
|
|
1043
|
+
// }
|
|
1044
|
+
//
|
|
1045
|
+
if (this.balance === undefined) {
|
|
1046
|
+
this.balance = {};
|
|
1047
|
+
}
|
|
1048
|
+
const topic = this.safeValue(message, 'channel');
|
|
1049
|
+
const messageHash = topic + '::balance';
|
|
1050
|
+
let info = undefined;
|
|
1051
|
+
let rawBalances = [];
|
|
1052
|
+
let account = undefined;
|
|
1053
|
+
let timestamp = undefined;
|
|
1054
|
+
const data = this.safeValue(message, 'data', []);
|
|
1055
|
+
if (topic === 'spotState') {
|
|
1056
|
+
const spotState = this.safeDict(data, 'spotState');
|
|
1057
|
+
rawBalances = this.safeList(spotState, 'balances');
|
|
1058
|
+
account = 'spot';
|
|
1059
|
+
info = rawBalances;
|
|
1060
|
+
}
|
|
1061
|
+
if (topic === 'clearinghouseState') {
|
|
1062
|
+
account = 'swap';
|
|
1063
|
+
const clearinghouseState = this.safeDict(data, 'clearinghouseState');
|
|
1064
|
+
rawBalances.push(clearinghouseState);
|
|
1065
|
+
info = clearinghouseState;
|
|
1066
|
+
timestamp = this.safeInteger(clearinghouseState, 'time');
|
|
1067
|
+
this.handlePositions(client, message);
|
|
1068
|
+
}
|
|
1069
|
+
for (let i = 0; i < rawBalances.length; i++) {
|
|
1070
|
+
this.parseWsBalance(rawBalances[i], account);
|
|
1071
|
+
}
|
|
1072
|
+
if (this.safeValue(this.balance, account) === undefined) {
|
|
1073
|
+
this.balance[account] = {};
|
|
1074
|
+
}
|
|
1075
|
+
this.balance[account]['info'] = info;
|
|
1076
|
+
this.balance[account]['timestamp'] = timestamp;
|
|
1077
|
+
this.balance[account]['datetime'] = this.iso8601(timestamp);
|
|
1078
|
+
this.balance[account] = this.safeBalance(this.balance[account]);
|
|
1079
|
+
client.resolve(this.balance[account], messageHash);
|
|
1080
|
+
}
|
|
1081
|
+
parseWsBalance(balance, accountType = undefined) {
|
|
1082
|
+
//
|
|
1083
|
+
// spot
|
|
1084
|
+
// {
|
|
1085
|
+
// "coin": "USDH",
|
|
1086
|
+
// "token": 360,
|
|
1087
|
+
// "total": "0.0",
|
|
1088
|
+
// "hold": "0.0",
|
|
1089
|
+
// "entryNtl": "0.0"
|
|
1090
|
+
// }
|
|
1091
|
+
// swap
|
|
1092
|
+
// {
|
|
1093
|
+
// "marginSummary": {
|
|
1094
|
+
// "accountValue": "0.0",
|
|
1095
|
+
// "totalNtlPos": "0.0",
|
|
1096
|
+
// "totalRawUsd": "0.0",
|
|
1097
|
+
// "totalMarginUsed": "0.0"
|
|
1098
|
+
// },
|
|
1099
|
+
// "crossMarginSummary": {
|
|
1100
|
+
// "accountValue": "0.0",
|
|
1101
|
+
// "totalNtlPos": "0.0",
|
|
1102
|
+
// "totalRawUsd": "0.0",
|
|
1103
|
+
// "totalMarginUsed": "0.0"
|
|
1104
|
+
// },
|
|
1105
|
+
// "crossMaintenanceMarginUsed": "0.0",
|
|
1106
|
+
// "withdrawable": "0.0",
|
|
1107
|
+
// "assetPositions": [],
|
|
1108
|
+
// "time": 1776000003409
|
|
1109
|
+
// }
|
|
1110
|
+
//
|
|
1111
|
+
const account = this.account();
|
|
1112
|
+
const currencyId = this.safeString(balance, 'coin');
|
|
1113
|
+
let code = undefined;
|
|
1114
|
+
if (currencyId === undefined) {
|
|
1115
|
+
code = 'USDC';
|
|
1116
|
+
const marginSummary = this.safeDict(balance, 'marginSummary', {});
|
|
1117
|
+
account['free'] = this.safeString(balance, 'withdrawable');
|
|
1118
|
+
account['used'] = this.safeString(marginSummary, 'totalMarginUsed');
|
|
1119
|
+
account['total'] = this.safeString(marginSummary, 'accountValue');
|
|
1120
|
+
}
|
|
1121
|
+
else {
|
|
1122
|
+
code = this.safeCurrencyCode(currencyId);
|
|
1123
|
+
account['used'] = this.safeString(balance, 'hold');
|
|
1124
|
+
account['total'] = this.safeString(balance, 'total');
|
|
1125
|
+
}
|
|
1126
|
+
if (accountType !== undefined) {
|
|
1127
|
+
if (this.safeValue(this.balance, accountType) === undefined) {
|
|
1128
|
+
this.balance[accountType] = {};
|
|
1129
|
+
}
|
|
1130
|
+
this.balance[accountType][code] = account;
|
|
1131
|
+
}
|
|
1132
|
+
else {
|
|
1133
|
+
this.balance[code] = account;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* @method
|
|
1138
|
+
* @name hyperliquid#watchPositions
|
|
1139
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
1140
|
+
* @description watch all open positions
|
|
1141
|
+
* @param {string[]} [symbols] list of unified market symbols
|
|
1142
|
+
* @param {int} [since] the earliest time in ms to fetch positions for
|
|
1143
|
+
* @param {int} [limit] the maximum number of positions to retrieve
|
|
1144
|
+
* @param {object} params extra parameters specific to the exchange API endpoint
|
|
1145
|
+
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
|
|
1146
|
+
*/
|
|
1147
|
+
async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1148
|
+
await this.loadMarkets();
|
|
1149
|
+
let userAddress = undefined;
|
|
1150
|
+
[userAddress, params] = this.handlePublicAddress('watchPositions', params);
|
|
1151
|
+
const topic = 'clearinghouseState';
|
|
1152
|
+
let messageHash = topic + '::positions';
|
|
1153
|
+
if (!this.isEmpty(symbols)) {
|
|
1154
|
+
symbols = this.marketSymbols(symbols);
|
|
1155
|
+
messageHash += '::' + symbols.join(',');
|
|
1156
|
+
}
|
|
1157
|
+
const url = this.urls['api']['ws']['public'];
|
|
1158
|
+
const subscription = {
|
|
1159
|
+
'type': topic,
|
|
1160
|
+
'user': userAddress,
|
|
1161
|
+
};
|
|
1162
|
+
const dexName = this.getDexFromSymbols('watchPositions', symbols);
|
|
1163
|
+
if (dexName !== undefined) {
|
|
1164
|
+
subscription['dex'] = dexName;
|
|
1165
|
+
}
|
|
1166
|
+
const request = {
|
|
1167
|
+
'method': 'subscribe',
|
|
1168
|
+
'subscription': subscription,
|
|
1169
|
+
};
|
|
1170
|
+
const message = this.extend(request, params);
|
|
1171
|
+
const client = this.client(url);
|
|
1172
|
+
this.setPositionsCache(client, symbols);
|
|
1173
|
+
const cache = this.positions;
|
|
1174
|
+
const newPositions = await this.watch(url, messageHash, message, topic);
|
|
1175
|
+
if (this.newUpdates) {
|
|
1176
|
+
return newPositions;
|
|
1177
|
+
}
|
|
1178
|
+
return this.filterBySymbolsSinceLimit(cache, symbols, since, limit, true);
|
|
1179
|
+
}
|
|
1180
|
+
setPositionsCache(client, symbols = undefined) {
|
|
1181
|
+
if (this.positions !== undefined) {
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
this.positions = new ArrayCacheBySymbolBySide();
|
|
1185
|
+
}
|
|
1186
|
+
handlePositions(client, message) {
|
|
1187
|
+
if (this.positions === undefined) {
|
|
1188
|
+
this.positions = new ArrayCacheBySymbolBySide();
|
|
1189
|
+
}
|
|
1190
|
+
const cache = this.positions;
|
|
1191
|
+
const data = this.safeDict(message, 'data', {});
|
|
1192
|
+
const clearinghouseState = this.safeDict(data, 'clearinghouseState', {});
|
|
1193
|
+
const newPositions = [];
|
|
1194
|
+
const rawPositions = this.safeList(clearinghouseState, 'assetPositions', []);
|
|
1195
|
+
for (let i = 0; i < rawPositions.length; i++) {
|
|
1196
|
+
const rawPosition = rawPositions[i];
|
|
1197
|
+
const position = this.parsePosition(rawPosition);
|
|
1198
|
+
newPositions.push(position);
|
|
1199
|
+
cache.append(position);
|
|
1200
|
+
}
|
|
1201
|
+
const baseMessageHash = 'clearinghouseState::positions';
|
|
1202
|
+
const messageHashes = this.findMessageHashes(client, baseMessageHash);
|
|
1203
|
+
for (let i = 0; i < messageHashes.length; i++) {
|
|
1204
|
+
const messageHash = messageHashes[i];
|
|
1205
|
+
const parts = messageHash.split('::');
|
|
1206
|
+
const symbolsString = this.safeString(parts, 2);
|
|
1207
|
+
if (symbolsString === undefined) {
|
|
1208
|
+
continue;
|
|
1209
|
+
}
|
|
1210
|
+
const symbols = symbolsString.split(',');
|
|
1211
|
+
const positions = this.filterByArray(newPositions, 'symbol', symbols, false);
|
|
1212
|
+
if (!this.isEmpty(positions)) {
|
|
1213
|
+
client.resolve(positions, messageHash);
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
client.resolve(newPositions, baseMessageHash);
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* @method
|
|
1220
|
+
* @name hyperliquid#unWatchPositions
|
|
1221
|
+
* @description unWatches all open positions
|
|
1222
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
1223
|
+
* @param {string[]} [symbols] list of unified market symbols
|
|
1224
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1225
|
+
* @returns {object} status of the unwatch request
|
|
1226
|
+
*/
|
|
1227
|
+
async unWatchPositions(symbols = undefined, params = {}) {
|
|
1228
|
+
await this.loadMarkets();
|
|
1229
|
+
if (!this.isEmpty(symbols)) {
|
|
1230
|
+
throw new NotSupported(this.id + ' unWatchPositions() does not support a symbol parameter, you must unwatch all orders');
|
|
1231
|
+
}
|
|
1232
|
+
const messageHash = 'unsubscribe:clearinghouseState';
|
|
1233
|
+
const url = this.urls['api']['ws']['public'];
|
|
1234
|
+
let userAddress = undefined;
|
|
1235
|
+
[userAddress, params] = this.handlePublicAddress('unWatchPositions', params);
|
|
1236
|
+
const request = {
|
|
1237
|
+
'method': 'unsubscribe',
|
|
1238
|
+
'subscription': {
|
|
1239
|
+
'type': 'clearinghouseState',
|
|
1240
|
+
'user': userAddress,
|
|
1241
|
+
},
|
|
1242
|
+
};
|
|
1243
|
+
const message = this.extend(request, params);
|
|
1244
|
+
return await this.watch(url, messageHash, message, messageHash);
|
|
1245
|
+
}
|
|
915
1246
|
/**
|
|
916
1247
|
* @method
|
|
917
1248
|
* @name hyperliquid#watchOrders
|
|
@@ -1166,6 +1497,27 @@ export default class hyperliquid extends hyperliquidRest {
|
|
|
1166
1497
|
};
|
|
1167
1498
|
this.cleanCache(topicStructure);
|
|
1168
1499
|
}
|
|
1500
|
+
handlePositionsUnsubscription(client, subscription) {
|
|
1501
|
+
const subHash = 'clearinghouseState';
|
|
1502
|
+
const unSubHash = 'unsubscribe:' + subHash;
|
|
1503
|
+
this.cleanUnsubscription(client, subHash, unSubHash, true);
|
|
1504
|
+
const topicStructure = {
|
|
1505
|
+
'topic': 'positions',
|
|
1506
|
+
};
|
|
1507
|
+
this.cleanCache(topicStructure);
|
|
1508
|
+
// clean swap balance if it existed
|
|
1509
|
+
if ('swap' in this.balance) {
|
|
1510
|
+
delete this.balance['swap'];
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
handleSpotBalanceUnsubscription(client, subscription) {
|
|
1514
|
+
const subHash = 'spotState';
|
|
1515
|
+
const unSubHash = 'unsubscribe:' + subHash;
|
|
1516
|
+
this.cleanUnsubscription(client, subHash, unSubHash, true);
|
|
1517
|
+
if ('spot' in this.balance) {
|
|
1518
|
+
delete this.balance['spot'];
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1169
1521
|
handleSubscriptionResponse(client, message) {
|
|
1170
1522
|
// {
|
|
1171
1523
|
// "channel":"subscriptionResponse",
|
|
@@ -1214,6 +1566,12 @@ export default class hyperliquid extends hyperliquidRest {
|
|
|
1214
1566
|
else if (type === 'userFills') {
|
|
1215
1567
|
this.handleMyTradesUnsubscription(client, subscription);
|
|
1216
1568
|
}
|
|
1569
|
+
else if (type === 'clearinghoustState') {
|
|
1570
|
+
this.handlePositionsUnsubscription(client, subscription);
|
|
1571
|
+
}
|
|
1572
|
+
else if (type === 'spotState') {
|
|
1573
|
+
this.handleSpotBalanceUnsubscription(client, subscription);
|
|
1574
|
+
}
|
|
1217
1575
|
}
|
|
1218
1576
|
}
|
|
1219
1577
|
handleMessage(client, message) {
|
|
@@ -1246,6 +1604,8 @@ export default class hyperliquid extends hyperliquidRest {
|
|
|
1246
1604
|
'allMids': this.handleWsTickers,
|
|
1247
1605
|
'post': this.handleWsPost,
|
|
1248
1606
|
'subscriptionResponse': this.handleSubscriptionResponse,
|
|
1607
|
+
'clearinghouseState': this.handleBalance,
|
|
1608
|
+
'spotState': this.handleBalance,
|
|
1249
1609
|
};
|
|
1250
1610
|
const exacMethod = this.safeValue(methods, topic);
|
|
1251
1611
|
if (exacMethod !== undefined) {
|
package/js/src/pro/lighter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Dict, Int, Liquidation, OrderBook, Str, Strings, Ticker, Tickers, Trade } from '../base/types.js';
|
|
1
|
+
import type { Balances, Dict, Int, Liquidation, Order, OrderBook, Str, Strings, Ticker, Tickers, Trade } from '../base/types.js';
|
|
2
2
|
import Client from '../base/ws/Client.js';
|
|
3
3
|
import lighterRest from '../lighter.js';
|
|
4
4
|
export default class lighter extends lighterRest {
|
|
@@ -6,7 +6,8 @@ export default class lighter extends lighterRest {
|
|
|
6
6
|
getMessageHash(unifiedChannel: string, symbol?: Str, extra?: Str): string;
|
|
7
7
|
subscribePublic(messageHash: any, params?: {}): Promise<any>;
|
|
8
8
|
subscribePublicMultiple(messageHashes: any, params?: {}): Promise<any>;
|
|
9
|
-
|
|
9
|
+
unsubscribe(messageHash: any, params?: {}): Promise<any>;
|
|
10
|
+
subscribePrivate(messageHash: any, params?: {}): Promise<any>;
|
|
10
11
|
handleDelta(bookside: any, delta: any): void;
|
|
11
12
|
handleDeltas(bookside: any, deltas: any): void;
|
|
12
13
|
handleOrderBookMessage(client: Client, message: any, orderbook: any): any;
|
|
@@ -138,6 +139,7 @@ export default class lighter extends lighterRest {
|
|
|
138
139
|
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
139
140
|
*/
|
|
140
141
|
unWatchTrades(symbol: string, params?: {}): Promise<any>;
|
|
142
|
+
parseWsOrderTrade(trade: any, market?: any): Trade;
|
|
141
143
|
handleMyTrades(client: Client, message: any): boolean;
|
|
142
144
|
/**
|
|
143
145
|
* @method
|
|
@@ -175,6 +177,39 @@ export default class lighter extends lighterRest {
|
|
|
175
177
|
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
176
178
|
*/
|
|
177
179
|
watchLiquidations(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Liquidation[]>;
|
|
180
|
+
/**
|
|
181
|
+
* @method
|
|
182
|
+
* @name lighter#watchBalance
|
|
183
|
+
* @description watch balance and get the amount of funds available for trading or funds locked in orders
|
|
184
|
+
* @see https://apidocs.lighter.xyz/docs/websocket-reference#account-all-assets
|
|
185
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
186
|
+
* @param {string} [params.type] 'spot' or 'swap', default is 'swap'
|
|
187
|
+
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
|
|
188
|
+
*/
|
|
189
|
+
watchBalance(params?: {}): Promise<Balances>;
|
|
190
|
+
handleBalance(client: Client, message: any): boolean;
|
|
191
|
+
/**
|
|
192
|
+
* @name lighter#watchOrders
|
|
193
|
+
* @description watches information on multiple orders made by the user
|
|
194
|
+
* @see https://apidocs.lighter.xyz/docs/websocket-reference#account-all-orders
|
|
195
|
+
* @param {string} symbol unified market symbol of the market orders were made in
|
|
196
|
+
* @param {int} [since] the earliest time in ms to fetch orders for
|
|
197
|
+
* @param {int} [limit] the maximum number of order structures to retrieve
|
|
198
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
199
|
+
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
|
|
200
|
+
*/
|
|
201
|
+
watchOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
|
|
202
|
+
/**
|
|
203
|
+
* @method
|
|
204
|
+
* @name lighter#unWatchOrders
|
|
205
|
+
* @description unWatches information on multiple orders made by the user
|
|
206
|
+
* @see https://apidocs.lighter.xyz/docs/websocket-reference#account-all-orders
|
|
207
|
+
* @param {string} symbol unified market symbol of the market orders were made in
|
|
208
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
209
|
+
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
|
|
210
|
+
*/
|
|
211
|
+
unWatchOrders(symbol?: Str, params?: {}): Promise<any>;
|
|
212
|
+
handleOrders(client: Client, message: any): boolean;
|
|
178
213
|
handleErrorMessage(client: any, message: any): boolean;
|
|
179
214
|
handleMessage(client: Client, message: any): void;
|
|
180
215
|
handleSubscriptionStatus(client: Client, message: any): any;
|