gateio-api 1.2.5 → 1.2.6

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/llms.txt CHANGED
@@ -3372,6 +3372,7 @@ export interface DeliveryAccount {
3372
3372
  bonus_dnw: string;
3373
3373
  bonus_offset: string;
3374
3374
  };
3375
+ enable_tiered_mm: boolean;
3375
3376
  }
3376
3377
  ⋮----
3377
3378
  export interface DeliveryBook {
@@ -3738,6 +3739,223 @@ export interface PartnerTransaction {
3738
3739
  source: string;
3739
3740
  }
3740
3741
 
3742
+ ================
3743
+ File: src/types/response/wallet.ts
3744
+ ================
3745
+ export interface CurrencyChain {
3746
+ chain: string;
3747
+ name_cn: string;
3748
+ name_en: string;
3749
+ contract_address: string;
3750
+ is_disabled: number;
3751
+ is_deposit_disabled: number;
3752
+ is_withdraw_disabled: number;
3753
+ decimal: string;
3754
+ }
3755
+ ⋮----
3756
+ export interface CreateDepositAddressResp {
3757
+ currency: string;
3758
+ address: string;
3759
+ multichain_addresses: {
3760
+ chain: string;
3761
+ address: string;
3762
+ payment_id: string;
3763
+ payment_name: string;
3764
+ obtain_failed: number;
3765
+ }[];
3766
+ }
3767
+ ⋮----
3768
+ export interface SubAccountTransferRecord {
3769
+ currency: string;
3770
+ sub_account: string;
3771
+ direction: 'to' | 'from';
3772
+ amount: string;
3773
+ uid: string;
3774
+ client_order_id: string;
3775
+ timest: string;
3776
+ source: string;
3777
+ sub_account_type: 'spot' | 'futures' | 'cross_margin' | 'delivery';
3778
+ }
3779
+ ⋮----
3780
+ export interface WithdrawalStatus {
3781
+ currency: string;
3782
+ name: string;
3783
+ name_cn: string;
3784
+ deposit: string;
3785
+ withdraw_percent: string;
3786
+ withdraw_fix: string;
3787
+ withdraw_day_limit: string;
3788
+ withdraw_amount_mini: string;
3789
+ withdraw_day_limit_remain: string;
3790
+ withdraw_eachtime_limit: string;
3791
+ withdraw_fix_on_chains: { [key: string]: string };
3792
+ withdraw_percent_on_chains: { [key: string]: string };
3793
+ }
3794
+ ⋮----
3795
+ export interface SubAccountMarginBalance {
3796
+ currency_pair: string;
3797
+ locked: boolean;
3798
+ risk: string;
3799
+ base: {
3800
+ currency: string;
3801
+ available: string;
3802
+ locked: string;
3803
+ borrowed: string;
3804
+ interest: string;
3805
+ };
3806
+ quote: {
3807
+ currency: string;
3808
+ available: string;
3809
+ locked: string;
3810
+ borrowed: string;
3811
+ interest: string;
3812
+ };
3813
+ }
3814
+ ⋮----
3815
+ export interface SubAccountFuturesBalancesResp {
3816
+ uid: string;
3817
+ available: {
3818
+ [key: string]: {
3819
+ total: string;
3820
+ unrealised_pnl: string;
3821
+ position_margin: string;
3822
+ order_margin: string;
3823
+ available: string;
3824
+ point: string;
3825
+ currency: string;
3826
+ in_dual_mode: boolean;
3827
+ enable_credit: boolean;
3828
+ position_initial_margin: string;
3829
+ maintenance_margin: string;
3830
+ bonus: string;
3831
+ enable_evolved_classic: boolean;
3832
+ cross_order_margin: string;
3833
+ cross_initial_margin: string;
3834
+ cross_maintenance_margin: string;
3835
+ cross_unrealised_pnl: string;
3836
+ cross_available: string;
3837
+ isolated_position_margin: string;
3838
+ history: {
3839
+ dnw: string;
3840
+ pnl: string;
3841
+ fee: string;
3842
+ refr: string;
3843
+ fund: string;
3844
+ point_dnw: string;
3845
+ point_fee: string;
3846
+ point_refr: string;
3847
+ bonus_dnw: string;
3848
+ bonus_offset: string;
3849
+ };
3850
+ };
3851
+ };
3852
+ }
3853
+ ⋮----
3854
+ export interface SubAccountCrossMarginBalancesResp {
3855
+ uid: string;
3856
+ available: {
3857
+ user_id: number;
3858
+ locked: boolean;
3859
+ balances: {
3860
+ [key: string]: {
3861
+ available: string;
3862
+ freeze: string;
3863
+ borrowed: string;
3864
+ interest: string;
3865
+ };
3866
+ };
3867
+ total: string;
3868
+ borrowed: string;
3869
+ borrowed_net: string;
3870
+ net: string;
3871
+ leverage: string;
3872
+ interest: string;
3873
+ risk: string;
3874
+ total_initial_margin: string;
3875
+ total_margin_balance: string;
3876
+ total_maintenance_margin: string;
3877
+ total_initial_margin_rate: string;
3878
+ total_maintenance_margin_rate: string;
3879
+ total_available_margin: string;
3880
+ };
3881
+ }
3882
+ ⋮----
3883
+ export interface SavedAddress {
3884
+ currency: string;
3885
+ chain: string;
3886
+ address: string;
3887
+ name: string;
3888
+ tag: string;
3889
+ verified: string;
3890
+ }
3891
+ ⋮----
3892
+ export interface TradingFees {
3893
+ user_id: number;
3894
+ taker_fee: string;
3895
+ maker_fee: string;
3896
+ gt_discount: boolean;
3897
+ gt_taker_fee: string;
3898
+ gt_maker_fee: string;
3899
+ loan_fee: string;
3900
+ point_type: string;
3901
+ futures_taker_fee: string;
3902
+ futures_maker_fee: string;
3903
+ delivery_taker_fee: string;
3904
+ delivery_maker_fee: string;
3905
+ debit_fee: number;
3906
+ }
3907
+ ⋮----
3908
+ export interface GetBalancesResp {
3909
+ total: {
3910
+ amount: string;
3911
+ currency: string;
3912
+ unrealised_pnl?: string;
3913
+ borrowed?: string;
3914
+ };
3915
+ details: {
3916
+ [key: string]: {
3917
+ amount: string;
3918
+ currency: string;
3919
+ unrealised_pnl?: string;
3920
+ borrowed?: string;
3921
+ };
3922
+ };
3923
+ }
3924
+ ⋮----
3925
+ export interface SmallBalanceRecord {
3926
+ currency: string;
3927
+ available_balance: string;
3928
+ estimated_as_btc: string;
3929
+ convertible_to_gt: string;
3930
+ }
3931
+ ⋮----
3932
+ export interface SmallBalanceHistoryRecord {
3933
+ id: string;
3934
+ currency: string;
3935
+ amount: string;
3936
+ gt_amount: string;
3937
+ create_time: number;
3938
+ }
3939
+ ⋮----
3940
+ export interface PushOrder {
3941
+ id: number;
3942
+ push_uid: number;
3943
+ receive_uid: number;
3944
+ currency: string;
3945
+ amount: string;
3946
+ create_time: number;
3947
+ status:
3948
+ | 'CREATING'
3949
+ | 'PENDING'
3950
+ | 'CANCELLING'
3951
+ | 'CANCELLED'
3952
+ | 'REFUSING'
3953
+ | 'REFUSED'
3954
+ | 'RECEIVING'
3955
+ | 'RECEIVED';
3956
+ message: string;
3957
+ }
3958
+
3741
3959
  ================
3742
3960
  File: src/index.ts
3743
3961
  ================
@@ -4030,281 +4248,19 @@ export function safeTerminateWs(
4030
4248
  ): boolean
4031
4249
 
4032
4250
  ================
4033
- File: src/types/response/wallet.ts
4251
+ File: src/types/request/futures.ts
4034
4252
  ================
4035
- export interface CurrencyChain {
4036
- chain: string;
4037
- name_cn: string;
4038
- name_en: string;
4039
- contract_address: string;
4040
- is_disabled: number;
4041
- is_deposit_disabled: number;
4042
- is_withdraw_disabled: number;
4043
- decimal: string;
4044
- }
4253
+ /**==========================================================================================================================
4254
+ * FUTURES
4255
+ * ==========================================================================================================================
4256
+ */
4045
4257
  ⋮----
4046
- export interface CreateDepositAddressResp {
4047
- currency: string;
4048
- address: string;
4049
- multichain_addresses: {
4050
- chain: string;
4051
- address: string;
4052
- payment_id: string;
4053
- payment_name: string;
4054
- obtain_failed: number;
4055
- }[];
4056
- }
4057
- ⋮----
4058
- export interface SubAccountTransferRecord {
4059
- currency: string;
4060
- sub_account: string;
4061
- direction: 'to' | 'from';
4062
- amount: string;
4063
- uid: string;
4064
- client_order_id: string;
4065
- timest: string;
4066
- source: string;
4067
- sub_account_type: 'spot' | 'futures' | 'cross_margin' | 'delivery';
4068
- }
4069
- ⋮----
4070
- export interface WithdrawalStatus {
4071
- currency: string;
4072
- name: string;
4073
- name_cn: string;
4074
- deposit: string;
4075
- withdraw_percent: string;
4076
- withdraw_fix: string;
4077
- withdraw_day_limit: string;
4078
- withdraw_amount_mini: string;
4079
- withdraw_day_limit_remain: string;
4080
- withdraw_eachtime_limit: string;
4081
- withdraw_fix_on_chains: { [key: string]: string };
4082
- withdraw_percent_on_chains: { [key: string]: string };
4083
- }
4084
- ⋮----
4085
- export interface SubAccountMarginBalance {
4086
- currency_pair: string;
4087
- locked: boolean;
4088
- risk: string;
4089
- base: {
4090
- currency: string;
4091
- available: string;
4092
- locked: string;
4093
- borrowed: string;
4094
- interest: string;
4095
- };
4096
- quote: {
4097
- currency: string;
4098
- available: string;
4099
- locked: string;
4100
- borrowed: string;
4101
- interest: string;
4102
- };
4103
- }
4104
- ⋮----
4105
- export interface SubAccountFuturesBalancesResp {
4106
- uid: string;
4107
- available: {
4108
- [key: string]: {
4109
- total: string;
4110
- unrealised_pnl: string;
4111
- position_margin: string;
4112
- order_margin: string;
4113
- available: string;
4114
- point: string;
4115
- currency: string;
4116
- in_dual_mode: boolean;
4117
- enable_credit: boolean;
4118
- position_initial_margin: string;
4119
- maintenance_margin: string;
4120
- bonus: string;
4121
- enable_evolved_classic: boolean;
4122
- cross_order_margin: string;
4123
- cross_initial_margin: string;
4124
- cross_maintenance_margin: string;
4125
- cross_unrealised_pnl: string;
4126
- cross_available: string;
4127
- isolated_position_margin: string;
4128
- history: {
4129
- dnw: string;
4130
- pnl: string;
4131
- fee: string;
4132
- refr: string;
4133
- fund: string;
4134
- point_dnw: string;
4135
- point_fee: string;
4136
- point_refr: string;
4137
- bonus_dnw: string;
4138
- bonus_offset: string;
4139
- };
4140
- };
4141
- };
4142
- }
4143
- ⋮----
4144
- export interface SubAccountCrossMarginBalancesResp {
4145
- uid: string;
4146
- available: {
4147
- user_id: number;
4148
- locked: boolean;
4149
- balances: {
4150
- [key: string]: {
4151
- available: string;
4152
- freeze: string;
4153
- borrowed: string;
4154
- interest: string;
4155
- };
4156
- };
4157
- total: string;
4158
- borrowed: string;
4159
- borrowed_net: string;
4160
- net: string;
4161
- leverage: string;
4162
- interest: string;
4163
- risk: string;
4164
- total_initial_margin: string;
4165
- total_margin_balance: string;
4166
- total_maintenance_margin: string;
4167
- total_initial_margin_rate: string;
4168
- total_maintenance_margin_rate: string;
4169
- total_available_margin: string;
4170
- };
4171
- }
4172
- ⋮----
4173
- export interface SavedAddress {
4174
- currency: string;
4175
- chain: string;
4176
- address: string;
4177
- name: string;
4178
- tag: string;
4179
- verified: string;
4180
- }
4181
- ⋮----
4182
- export interface TradingFees {
4183
- user_id: number;
4184
- taker_fee: string;
4185
- maker_fee: string;
4186
- gt_discount: boolean;
4187
- gt_taker_fee: string;
4188
- gt_maker_fee: string;
4189
- loan_fee: string;
4190
- point_type: string;
4191
- futures_taker_fee: string;
4192
- futures_maker_fee: string;
4193
- delivery_taker_fee: string;
4194
- delivery_maker_fee: string;
4195
- debit_fee: number;
4196
- }
4197
- ⋮----
4198
- export interface GetBalancesResp {
4199
- total: {
4200
- amount: string;
4201
- currency: string;
4202
- unrealised_pnl?: string;
4203
- borrowed?: string;
4204
- };
4205
- details: {
4206
- [key: string]: {
4207
- amount: string;
4208
- currency: string;
4209
- unrealised_pnl?: string;
4210
- borrowed?: string;
4211
- };
4212
- };
4213
- }
4214
- ⋮----
4215
- export interface SmallBalanceRecord {
4216
- currency: string;
4217
- available_balance: string;
4218
- estimated_as_btc: string;
4219
- convertible_to_gt: string;
4220
- }
4221
- ⋮----
4222
- export interface SmallBalanceHistoryRecord {
4223
- id: string;
4224
- currency: string;
4225
- amount: string;
4226
- gt_amount: string;
4227
- create_time: number;
4228
- }
4229
- ⋮----
4230
- export interface PushOrder {
4231
- id: number;
4232
- push_uid: number;
4233
- receive_uid: number;
4234
- currency: string;
4235
- amount: string;
4236
- create_time: number;
4237
- status:
4238
- | 'CREATING'
4239
- | 'PENDING'
4240
- | 'CANCELLING'
4241
- | 'CANCELLED'
4242
- | 'REFUSING'
4243
- | 'REFUSED'
4244
- | 'RECEIVING'
4245
- | 'RECEIVED';
4246
- message: string;
4247
- }
4248
-
4249
- ================
4250
- File: .eslintrc.cjs
4251
- ================
4252
- // 'no-unused-vars': ['warn'],
4253
-
4254
- ================
4255
- File: .gitignore
4256
- ================
4257
- !.gitkeep
4258
- .DS_STORE
4259
- *.log
4260
- npm-debug.log*
4261
- yarn-debug.log*
4262
- yarn-error.log*
4263
- lerna-debug.log*
4264
- report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
4265
- pids
4266
- *.pid
4267
- *.seed
4268
- *.pid.lock
4269
- node_modules/
4270
- .npm
4271
- .eslintcache
4272
- .node_repl_history
4273
- *.tgz
4274
- .yarn-integrity
4275
- .env
4276
- .env.test
4277
- .cache
4278
- bundleReport.html
4279
- .history/
4280
- dist
4281
- coverage
4282
- localtest.sh
4283
- repomix.sh
4284
-
4285
- ws-private-spot-wsapi-performance.ts
4286
- ws-private-perp-futures-wsapi-readonly.ts
4287
- privatetest.ts
4288
-
4289
- privaterepotracker
4290
- restClientRegex.ts
4291
-
4292
- testfile.ts
4293
-
4294
- ================
4295
- File: src/types/request/futures.ts
4296
- ================
4297
- /**==========================================================================================================================
4298
- * FUTURES
4299
- * ==========================================================================================================================
4300
- */
4301
- ⋮----
4302
- export interface GetFuturesOrderBookReq {
4303
- settle: 'btc' | 'usdt' | 'usd';
4304
- contract: string;
4305
- interval?: string;
4306
- limit?: number;
4307
- with_id?: boolean;
4258
+ export interface GetFuturesOrderBookReq {
4259
+ settle: 'btc' | 'usdt' | 'usd';
4260
+ contract: string;
4261
+ interval?: string;
4262
+ limit?: number;
4263
+ with_id?: boolean;
4308
4264
  }
4309
4265
  ⋮----
4310
4266
  export interface GetFuturesTradesReq {
@@ -4357,6 +4313,11 @@ export interface GetRiskLimitTiersReq {
4357
4313
  offset?: number;
4358
4314
  }
4359
4315
  ⋮----
4316
+ export interface GetRiskLimitTableReq {
4317
+ settle: 'btc' | 'usdt' | 'usd';
4318
+ table_id: string;
4319
+ }
4320
+ ⋮----
4360
4321
  export interface GetFuturesAccountBookReq {
4361
4322
  settle: 'btc' | 'usdt' | 'usd';
4362
4323
  contract?: string;
@@ -4537,14 +4498,59 @@ price?: string; // New order price
4537
4498
  amend_text?: string; // Custom info during amending order
4538
4499
 
4539
4500
  ================
4540
- File: src/types/response/unified.ts
4501
+ File: .eslintrc.cjs
4541
4502
  ================
4542
- export interface UnifiedAccountInfo {
4543
- user_id: number;
4544
- refresh_time: number;
4545
- locked: boolean;
4546
- balances: {
4547
- [key: string]: {
4503
+ // 'no-unused-vars': ['warn'],
4504
+
4505
+ ================
4506
+ File: .gitignore
4507
+ ================
4508
+ !.gitkeep
4509
+ .DS_STORE
4510
+ *.log
4511
+ npm-debug.log*
4512
+ yarn-debug.log*
4513
+ yarn-error.log*
4514
+ lerna-debug.log*
4515
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
4516
+ pids
4517
+ *.pid
4518
+ *.seed
4519
+ *.pid.lock
4520
+ node_modules/
4521
+ .npm
4522
+ .eslintcache
4523
+ .node_repl_history
4524
+ *.tgz
4525
+ .yarn-integrity
4526
+ .env
4527
+ .env.test
4528
+ .cache
4529
+ bundleReport.html
4530
+ .history/
4531
+ dist
4532
+ coverage
4533
+ localtest.sh
4534
+ repomix.sh
4535
+
4536
+ ws-private-spot-wsapi-performance.ts
4537
+ ws-private-perp-futures-wsapi-readonly.ts
4538
+ privatetest.ts
4539
+
4540
+ privaterepotracker
4541
+ restClientRegex.ts
4542
+
4543
+ testfile.ts
4544
+
4545
+ ================
4546
+ File: src/types/response/unified.ts
4547
+ ================
4548
+ export interface UnifiedAccountInfo {
4549
+ user_id: number;
4550
+ refresh_time: number;
4551
+ locked: boolean;
4552
+ balances: {
4553
+ [key: string]: {
4548
4554
  available: string;
4549
4555
  freeze: string;
4550
4556
  borrowed: string;
@@ -5872,127 +5878,626 @@ export interface SpotHistoricTradeRecord {
5872
5878
  }
5873
5879
 
5874
5880
  ================
5875
- File: src/lib/BaseWSClient.ts
5881
+ File: src/types/response/futures.ts
5876
5882
  ================
5877
- import EventEmitter from 'events';
5878
- import WebSocket from 'isomorphic-ws';
5879
- ⋮----
5880
- import {
5881
- WebsocketClientOptions,
5882
- WSClientConfigurableOptions,
5883
- } from '../types/websockets/client.js';
5884
- import { WsOperation } from '../types/websockets/requests.js';
5885
- import { WS_LOGGER_CATEGORY } from '../WebsocketClient.js';
5886
- import { DefaultLogger } from './logger.js';
5887
- import { isMessageEvent, MessageEventLike } from './requestUtils.js';
5888
- import {
5889
- safeTerminateWs,
5890
- WsTopicRequest,
5891
- WsTopicRequestOrStringTopic,
5892
- } from './websocket/websocket-util.js';
5893
- import { WsStore } from './websocket/WsStore.js';
5894
- import {
5895
- WSConnectedResult,
5896
- WsConnectionStateEnum,
5897
- } from './websocket/WsStore.types.js';
5883
+ /**==========================================================================================================================
5884
+ * FUTURES
5885
+ * ==========================================================================================================================
5886
+ */
5898
5887
  ⋮----
5899
- interface WSClientEventMap<WsKey extends string> {
5900
- /** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */
5901
- open: (evt: {
5902
- wsKey: WsKey;
5903
- event: any;
5904
- wsUrl: string;
5905
- ws: WebSocket;
5906
- }) => void /** Reconnecting a dropped connection */;
5907
- reconnect: (evt: { wsKey: WsKey; event: any }) => void;
5908
- /** Successfully reconnected a connection that dropped */
5909
- reconnected: (evt: {
5910
- wsKey: WsKey;
5911
- event: any;
5912
- wsUrl: string;
5913
- ws: WebSocket;
5914
- }) => void;
5915
- /** Connection closed */
5916
- close: (evt: { wsKey: WsKey; event: any }) => void;
5917
- /** Received reply to websocket command (e.g. after subscribing to topics) */
5918
- response: (response: any & { wsKey: WsKey }) => void;
5919
- /** Received data for topic */
5920
- update: (response: any & { wsKey: WsKey }) => void;
5921
- /** Exception from ws client OR custom listeners (e.g. if you throw inside your event handler) */
5922
- exception: (response: any & { wsKey: WsKey }) => void;
5923
- error: (response: any & { wsKey: WsKey }) => void;
5924
- /** Confirmation that a connection successfully authenticated */
5925
- authenticated: (event: { wsKey: WsKey; event: any }) => void;
5888
+ export interface FuturesOrderBook {
5889
+ id?: number;
5890
+ current: number;
5891
+ update: number;
5892
+ asks: { p: string; s: number }[];
5893
+ bids: { p: string; s: number }[];
5926
5894
  }
5927
5895
  ⋮----
5928
- /** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */
5929
- ⋮----
5930
- }) => void /** Reconnecting a dropped connection */;
5931
- ⋮----
5932
- /** Successfully reconnected a connection that dropped */
5933
- ⋮----
5934
- /** Connection closed */
5935
- ⋮----
5936
- /** Received reply to websocket command (e.g. after subscribing to topics) */
5937
- ⋮----
5938
- /** Received data for topic */
5939
- ⋮----
5940
- /** Exception from ws client OR custom listeners (e.g. if you throw inside your event handler) */
5941
- ⋮----
5942
- /** Confirmation that a connection successfully authenticated */
5943
- ⋮----
5944
- export interface EmittableEvent<TEvent = any> {
5945
- eventType: 'response' | 'update' | 'exception' | 'authenticated';
5946
- event: TEvent;
5896
+ export interface FuturesTrade {
5897
+ id: number;
5898
+ create_time: number;
5899
+ create_time_ms: number;
5900
+ contract: string;
5901
+ size: number;
5902
+ price: string;
5903
+ is_internal?: boolean;
5947
5904
  }
5948
5905
  ⋮----
5949
- // Type safety for on and emit handlers: https://stackoverflow.com/a/61609010/880837
5950
- export interface BaseWebsocketClient<TWSKey extends string> {
5951
- on<U extends keyof WSClientEventMap<TWSKey>>(
5952
- event: U,
5953
- listener: WSClientEventMap<TWSKey>[U],
5954
- ): this;
5955
-
5956
- emit<U extends keyof WSClientEventMap<TWSKey>>(
5957
- event: U,
5958
- ...args: Parameters<WSClientEventMap<TWSKey>[U]>
5959
- ): boolean;
5906
+ export interface FuturesCandle {
5907
+ t: number;
5908
+ v?: number;
5909
+ c: string;
5910
+ h: string;
5911
+ l: string;
5912
+ o: string;
5913
+ sum: string;
5960
5914
  }
5961
5915
  ⋮----
5962
- on<U extends keyof WSClientEventMap<TWSKey>>(
5963
- event: U,
5964
- listener: WSClientEventMap<TWSKey>[U],
5965
- ): this;
5966
- ⋮----
5967
- emit<U extends keyof WSClientEventMap<TWSKey>>(
5968
- event: U,
5969
- ...args: Parameters<WSClientEventMap<TWSKey>[U]>
5970
- ): boolean;
5916
+ export interface PremiumIndexKLine {
5917
+ t: number;
5918
+ c: string;
5919
+ h: string;
5920
+ l: string;
5921
+ o: string;
5922
+ }
5971
5923
  ⋮----
5972
- /**
5973
- * Users can conveniently pass topics as strings or objects (object has topic name + optional params).
5974
- *
5975
- * This method normalises topics into objects (object has topic name + optional params).
5976
- */
5977
- function getNormalisedTopicRequests(
5978
- wsTopicRequests: WsTopicRequestOrStringTopic<string>[],
5979
- ): WsTopicRequest<string>[]
5924
+ export interface FuturesTicker {
5925
+ contract: string;
5926
+ last: string;
5927
+ change_percentage: string;
5928
+ total_size: string;
5929
+ low_24h: string;
5930
+ high_24h: string;
5931
+ volume_24h: string;
5932
+ volume_24h_btc?: string;
5933
+ volume_24h_usd?: string;
5934
+ volume_24h_base: string;
5935
+ volume_24h_quote: string;
5936
+ volume_24h_settle: string;
5937
+ mark_price: string;
5938
+ funding_rate: string;
5939
+ funding_rate_indicative: string;
5940
+ index_price: string;
5941
+ quanto_base_rate?: string;
5942
+ basis_rate: string;
5943
+ basis_value: string;
5944
+ lowest_ask: string;
5945
+ highest_bid: string;
5946
+ lowest_size: string;
5947
+ highest_size: string;
5948
+ }
5980
5949
  ⋮----
5981
- // passed as string, convert to object
5950
+ export interface FuturesStats {
5951
+ time: number;
5952
+ lsr_taker: number;
5953
+ lsr_account: number;
5954
+ long_liq_size: number;
5955
+ long_liq_amount: number;
5956
+ long_liq_usd: number;
5957
+ short_liq_size: number;
5958
+ short_liq_amount: number;
5959
+ short_liq_usd: number;
5960
+ open_interest: number;
5961
+ open_interest_usd: number;
5962
+ top_lsr_account: number;
5963
+ top_lsr_size: number;
5964
+ }
5982
5965
  ⋮----
5983
- // already a normalised object, thanks to user
5966
+ export interface IndexConstituents {
5967
+ index: string;
5968
+ constituents: {
5969
+ exchange: string;
5970
+ symbols: string[];
5971
+ }[];
5972
+ }
5984
5973
  ⋮----
5985
- /**
5986
- * Base WebSocket abstraction layer. Handles connections, tracking each connection as a unique "WS Key"
5987
- */
5988
- // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
5989
- export abstract class BaseWebsocketClient<
5974
+ export interface LiquidationHistoryRecord {
5975
+ time: number;
5976
+ contract: string;
5977
+ size: number;
5978
+ order_size: number;
5979
+ order_price: string;
5980
+ fill_price: string;
5981
+ left: number;
5982
+ }
5990
5983
  ⋮----
5991
- /**
5992
- * The WS connections supported by the client, each identified by a unique primary key
5993
- */
5984
+ export interface RiskLimitTier {
5985
+ tier: number;
5986
+ risk_limit: string;
5987
+ initial_rate: string;
5988
+ maintenance_rate: string;
5989
+ leverage_max: string;
5990
+ contract: string;
5991
+ }
5994
5992
  ⋮----
5995
- /**
5993
+ export interface FuturesAccount {
5994
+ total: string;
5995
+ unrealised_pnl: string;
5996
+ position_margin: string;
5997
+ order_margin: string;
5998
+ available: string;
5999
+ point: string;
6000
+ currency: string;
6001
+ in_dual_mode: boolean;
6002
+ enable_credit: boolean;
6003
+ position_initial_margin: string;
6004
+ maintenance_margin: string;
6005
+ bonus: string;
6006
+ enable_evolved_classic: boolean;
6007
+ cross_order_margin: string;
6008
+ cross_initial_margin: string;
6009
+ cross_maintenance_margin: string;
6010
+ cross_unrealised_pnl: string;
6011
+ cross_available: string;
6012
+ cross_margin_balance: string;
6013
+ cross_mmr: string;
6014
+ cross_imr: string;
6015
+ isolated_position_margin: string;
6016
+ enable_new_dual_mode: boolean;
6017
+ margin_mode: number;
6018
+ history: {
6019
+ dnw: string;
6020
+ pnl: string;
6021
+ fee: string;
6022
+ refr: string;
6023
+ fund: string;
6024
+ point_dnw: string;
6025
+ point_fee: string;
6026
+ point_refr: string;
6027
+ bonus_dnw: string;
6028
+ bonus_offset: string;
6029
+ };
6030
+ enable_tiered_mm: boolean;
6031
+ }
6032
+ ⋮----
6033
+ export interface FuturesAccountBookRecord {
6034
+ time: number;
6035
+ change: string;
6036
+ balance: string;
6037
+ type: string;
6038
+ text: string;
6039
+ contract?: string;
6040
+ trade_id: string;
6041
+ id: string;
6042
+ }
6043
+ ⋮----
6044
+ export interface FuturesOrder {
6045
+ id?: number;
6046
+ user?: number;
6047
+ create_time?: number;
6048
+ finish_time?: number;
6049
+ finish_as?:
6050
+ | 'filled'
6051
+ | 'cancelled'
6052
+ | 'liquidated'
6053
+ | 'ioc'
6054
+ | 'auto_deleveraged'
6055
+ | 'reduce_only'
6056
+ | 'position_closed'
6057
+ | 'stp';
6058
+ status?: 'open' | 'finished';
6059
+ contract: string;
6060
+ size: number;
6061
+ iceberg?: number;
6062
+ price?: string;
6063
+ close?: boolean;
6064
+ is_close?: boolean;
6065
+ reduce_only?: boolean;
6066
+ is_reduce_only?: boolean;
6067
+ is_liq?: boolean;
6068
+ tif?: 'gtc' | 'ioc' | 'poc' | 'fok';
6069
+ left?: number;
6070
+ fill_price?: string;
6071
+ text?: string;
6072
+ tkfr?: string;
6073
+ mkfr?: string;
6074
+ refu?: number;
6075
+ auto_size?: 'close_long' | 'close_short';
6076
+ stp_id?: number;
6077
+ stp_act?: 'cn' | 'co' | 'cb' | '-';
6078
+ amend_text?: string;
6079
+ biz_info?: string;
6080
+ }
6081
+ ⋮----
6082
+ export interface FuturesPosition {
6083
+ user?: number;
6084
+ contract?: string;
6085
+ size?: number;
6086
+ leverage?: string;
6087
+ risk_limit?: string;
6088
+ leverage_max?: string;
6089
+ maintenance_rate?: string;
6090
+ value?: string;
6091
+ margin?: string;
6092
+ entry_price?: string;
6093
+ liq_price?: string;
6094
+ mark_price?: string;
6095
+ initial_margin?: string;
6096
+ maintenance_margin?: string;
6097
+ unrealised_pnl?: string;
6098
+ realised_pnl?: string;
6099
+ pnl_pnl?: string;
6100
+ pnl_fund?: string;
6101
+ pnl_fee?: string;
6102
+ history_pnl?: string;
6103
+ last_close_pnl?: string;
6104
+ realised_point?: string;
6105
+ history_point?: string;
6106
+ adl_ranking?: number;
6107
+ pending_orders?: number;
6108
+ close_order?: {
6109
+ id?: number;
6110
+ price?: string;
6111
+ is_liq?: boolean;
6112
+ } | null;
6113
+ mode?: 'single' | 'dual_long' | 'dual_short';
6114
+ cross_leverage_limit?: string;
6115
+ update_time?: number;
6116
+ update_id?: number;
6117
+ open_time?: number;
6118
+ }
6119
+ ⋮----
6120
+ export interface FuturesTradingHistoryRecord {
6121
+ id: number;
6122
+ create_time: number;
6123
+ contract: string;
6124
+ order_id: string;
6125
+ size: number;
6126
+ price: string;
6127
+ role: 'taker' | 'maker';
6128
+ text: string;
6129
+ fee: string;
6130
+ point_fee: string;
6131
+ close_size: number;
6132
+ }
6133
+ ⋮----
6134
+ export interface FuturesPositionHistoryRecord {
6135
+ time: number;
6136
+ contract: string;
6137
+ side: 'long' | 'short';
6138
+ pnl: string;
6139
+ pnl_pnl: string;
6140
+ pnl_fund: string;
6141
+ pnl_fee: string;
6142
+ text: string;
6143
+ max_size: string;
6144
+ first_open_time: number;
6145
+ long_price: string;
6146
+ short_price: string;
6147
+ accum_size: string;
6148
+ }
6149
+ ⋮----
6150
+ export interface FuturesLiquidationHistoryRecord {
6151
+ time: number;
6152
+ contract: string;
6153
+ leverage: string;
6154
+ size: number;
6155
+ margin: string;
6156
+ entry_price: string;
6157
+ liq_price: string;
6158
+ mark_price: string;
6159
+ order_id: number;
6160
+ order_price: string;
6161
+ fill_price: string;
6162
+ left: number;
6163
+ }
6164
+ export interface FuturesAutoDeleveragingHistoryRecord {
6165
+ time: number;
6166
+ user: number;
6167
+ order_id: number;
6168
+ contract: string;
6169
+ leverage: string;
6170
+ cross_leverage_limit: string;
6171
+ entry_price: string;
6172
+ fill_price: string;
6173
+ trade_size: number;
6174
+ position_size: number;
6175
+ }
6176
+ ⋮----
6177
+ export interface DeleteFuturesBatchOrdersResp {
6178
+ user_id: number;
6179
+ id: string;
6180
+ succeeded: boolean;
6181
+ message: string;
6182
+ }
6183
+ ⋮----
6184
+ export interface FuturesContract {
6185
+ name?: string;
6186
+ type?: 'inverse' | 'direct';
6187
+ quanto_multiplier?: string;
6188
+ leverage_min?: string;
6189
+ leverage_max?: string;
6190
+ maintenance_rate?: string;
6191
+ mark_type?: 'internal' | 'index';
6192
+ mark_price?: string;
6193
+ index_price?: string;
6194
+ last_price?: string;
6195
+ maker_fee_rate?: string;
6196
+ taker_fee_rate?: string;
6197
+ order_price_round?: string;
6198
+ mark_price_round?: string;
6199
+ funding_rate?: string;
6200
+ funding_interval?: number;
6201
+ funding_next_apply?: number;
6202
+ risk_limit_base?: string;
6203
+ risk_limit_step?: string;
6204
+ risk_limit_max?: string;
6205
+ order_size_min?: number;
6206
+ order_size_max?: number;
6207
+ order_price_deviate?: string;
6208
+ ref_discount_rate?: string;
6209
+ ref_rebate_rate?: string;
6210
+ orderbook_id?: number;
6211
+ trade_id?: number;
6212
+ trade_size?: number;
6213
+ position_size?: number;
6214
+ config_change_time?: number;
6215
+ in_delisting?: boolean;
6216
+ orders_limit?: number;
6217
+ enable_bonus?: boolean;
6218
+ enable_credit?: boolean;
6219
+ create_time?: number;
6220
+ funding_cap_ratio?: string;
6221
+ }
6222
+ ⋮----
6223
+ export interface FuturesPriceTriggeredOrder {
6224
+ initial: {
6225
+ contract: string;
6226
+ size?: number;
6227
+ price?: string;
6228
+ close?: boolean;
6229
+ tif?: 'gtc' | 'ioc';
6230
+ text?: string;
6231
+ reduce_only?: boolean;
6232
+ auto_size?: string;
6233
+ is_reduce_only?: boolean;
6234
+ is_close?: boolean;
6235
+ };
6236
+ trigger: {
6237
+ strategy_type?: 0 | 1;
6238
+ price_type?: 0 | 1 | 2;
6239
+ price?: string;
6240
+ rule?: 1 | 2;
6241
+ expiration?: number;
6242
+ };
6243
+ id?: number;
6244
+ user?: number;
6245
+ create_time?: number;
6246
+ finish_time?: number;
6247
+ trade_id?: number;
6248
+ status?: 'open' | 'finished' | 'inactive' | 'invalid';
6249
+ finish_as?: 'cancelled' | 'succeeded' | 'failed' | 'expired';
6250
+ reason?: string;
6251
+ order_type?:
6252
+ | 'close-long-order'
6253
+ | 'close-short-order'
6254
+ | 'close-long-position'
6255
+ | 'close-short-position'
6256
+ | 'plan-close-long-position'
6257
+ | 'plan-close-short-position';
6258
+ me_order_id?: number;
6259
+ }
6260
+ ⋮----
6261
+ export interface FuturesDeliveryContract {
6262
+ name?: string;
6263
+ underlying?: string;
6264
+ cycle?: 'WEEKLY' | 'BI-WEEKLY' | 'QUARTERLY' | 'BI-QUARTERLY';
6265
+ type?: 'inverse' | 'direct';
6266
+ quanto_multiplier?: string;
6267
+ leverage_min?: string;
6268
+ leverage_max?: string;
6269
+ maintenance_rate?: string;
6270
+ mark_type?: 'internal' | 'index';
6271
+ mark_price?: string;
6272
+ index_price?: string;
6273
+ last_price?: string;
6274
+ maker_fee_rate?: string;
6275
+ taker_fee_rate?: string;
6276
+ order_price_round?: string;
6277
+ mark_price_round?: string;
6278
+ basis_rate?: string;
6279
+ basis_value?: string;
6280
+ basis_impact_value?: string;
6281
+ settle_price?: string;
6282
+ settle_price_interval?: number;
6283
+ settle_price_duration?: number;
6284
+ expire_time?: number;
6285
+ risk_limit_base?: string;
6286
+ risk_limit_step?: string;
6287
+ risk_limit_max?: string;
6288
+ order_size_min?: number;
6289
+ order_size_max?: number;
6290
+ order_price_deviate?: string;
6291
+ ref_discount_rate?: string;
6292
+ ref_rebate_rate?: string;
6293
+ orderbook_id?: number;
6294
+ trade_id?: number;
6295
+ trade_size?: number;
6296
+ position_size?: number;
6297
+ config_change_time?: number;
6298
+ in_delisting?: boolean;
6299
+ orders_limit?: number;
6300
+ }
6301
+ ⋮----
6302
+ export interface BatchAmendOrderResp {
6303
+ succeeded: boolean;
6304
+ label?: string;
6305
+ detail?: string;
6306
+ id: number;
6307
+ user: number;
6308
+ create_time: number;
6309
+ finish_time?: number;
6310
+ finish_as?:
6311
+ | 'filled'
6312
+ | 'cancelled'
6313
+ | 'liquidated'
6314
+ | 'ioc'
6315
+ | 'auto_deleveraged'
6316
+ | 'reduce_only'
6317
+ | 'position_closed'
6318
+ | 'reduce_out'
6319
+ | 'stp';
6320
+ status: 'open' | 'finished';
6321
+ contract: string;
6322
+ size: number;
6323
+ iceberg: number;
6324
+ price: string;
6325
+ is_close: boolean;
6326
+ is_reduce_only: boolean;
6327
+ is_liq: boolean;
6328
+ tif: 'gtc' | 'ioc' | 'poc' | 'fok';
6329
+ left: number;
6330
+ fill_price: string;
6331
+ text: string;
6332
+ tkfr: string;
6333
+ mkfr: string;
6334
+ refu: number;
6335
+ stp_act: 'co' | 'cn' | 'cb' | '-';
6336
+ stp_id: number;
6337
+ }
6338
+ ⋮----
6339
+ /**
6340
+ * @deprecated - Use FuturesAccount instead
6341
+ */
6342
+ export interface UpdateFuturesDualModeResp {
6343
+ total: string;
6344
+ unrealised_pnl: string;
6345
+ position_margin: string;
6346
+ order_margin: string;
6347
+ available: string;
6348
+ point: string;
6349
+ currency: string;
6350
+ in_dual_mode: boolean;
6351
+ enable_credit: boolean;
6352
+ position_initial_margin: string;
6353
+ maintenance_margin: string;
6354
+ bonus: string;
6355
+ enable_evolved_classic: boolean;
6356
+ history: {
6357
+ dnw: string;
6358
+ pnl: string;
6359
+ fee: string;
6360
+ refr: string;
6361
+ fund: string;
6362
+ point_dnw: string;
6363
+ point_fee: string;
6364
+ point_refr: string;
6365
+ bonus_dnw: string;
6366
+ bonus_offset: string;
6367
+ };
6368
+ }
6369
+ ⋮----
6370
+ export interface RiskLimitTableTier {
6371
+ tier: number;
6372
+ risk_limit: string;
6373
+ initial_rate: string;
6374
+ maintenance_rate: string;
6375
+ leverage_max: string;
6376
+ deduction: string;
6377
+ }
6378
+
6379
+ ================
6380
+ File: src/lib/BaseWSClient.ts
6381
+ ================
6382
+ import EventEmitter from 'events';
6383
+ import WebSocket from 'isomorphic-ws';
6384
+ ⋮----
6385
+ import {
6386
+ WebsocketClientOptions,
6387
+ WSClientConfigurableOptions,
6388
+ } from '../types/websockets/client.js';
6389
+ import { WsOperation } from '../types/websockets/requests.js';
6390
+ import { WS_LOGGER_CATEGORY } from '../WebsocketClient.js';
6391
+ import { DefaultLogger } from './logger.js';
6392
+ import { isMessageEvent, MessageEventLike } from './requestUtils.js';
6393
+ import {
6394
+ safeTerminateWs,
6395
+ WsTopicRequest,
6396
+ WsTopicRequestOrStringTopic,
6397
+ } from './websocket/websocket-util.js';
6398
+ import { WsStore } from './websocket/WsStore.js';
6399
+ import {
6400
+ WSConnectedResult,
6401
+ WsConnectionStateEnum,
6402
+ } from './websocket/WsStore.types.js';
6403
+ ⋮----
6404
+ interface WSClientEventMap<WsKey extends string> {
6405
+ /** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */
6406
+ open: (evt: {
6407
+ wsKey: WsKey;
6408
+ event: any;
6409
+ wsUrl: string;
6410
+ ws: WebSocket;
6411
+ }) => void /** Reconnecting a dropped connection */;
6412
+ reconnect: (evt: { wsKey: WsKey; event: any }) => void;
6413
+ /** Successfully reconnected a connection that dropped */
6414
+ reconnected: (evt: {
6415
+ wsKey: WsKey;
6416
+ event: any;
6417
+ wsUrl: string;
6418
+ ws: WebSocket;
6419
+ }) => void;
6420
+ /** Connection closed */
6421
+ close: (evt: { wsKey: WsKey; event: any }) => void;
6422
+ /** Received reply to websocket command (e.g. after subscribing to topics) */
6423
+ response: (response: any & { wsKey: WsKey }) => void;
6424
+ /** Received data for topic */
6425
+ update: (response: any & { wsKey: WsKey }) => void;
6426
+ /** Exception from ws client OR custom listeners (e.g. if you throw inside your event handler) */
6427
+ exception: (response: any & { wsKey: WsKey }) => void;
6428
+ error: (response: any & { wsKey: WsKey }) => void;
6429
+ /** Confirmation that a connection successfully authenticated */
6430
+ authenticated: (event: { wsKey: WsKey; event: any }) => void;
6431
+ }
6432
+ ⋮----
6433
+ /** Connection opened. If this connection was previously opened and reconnected, expect the reconnected event instead */
6434
+ ⋮----
6435
+ }) => void /** Reconnecting a dropped connection */;
6436
+ ⋮----
6437
+ /** Successfully reconnected a connection that dropped */
6438
+ ⋮----
6439
+ /** Connection closed */
6440
+ ⋮----
6441
+ /** Received reply to websocket command (e.g. after subscribing to topics) */
6442
+ ⋮----
6443
+ /** Received data for topic */
6444
+ ⋮----
6445
+ /** Exception from ws client OR custom listeners (e.g. if you throw inside your event handler) */
6446
+ ⋮----
6447
+ /** Confirmation that a connection successfully authenticated */
6448
+ ⋮----
6449
+ export interface EmittableEvent<TEvent = any> {
6450
+ eventType: 'response' | 'update' | 'exception' | 'authenticated';
6451
+ event: TEvent;
6452
+ }
6453
+ ⋮----
6454
+ // Type safety for on and emit handlers: https://stackoverflow.com/a/61609010/880837
6455
+ export interface BaseWebsocketClient<TWSKey extends string> {
6456
+ on<U extends keyof WSClientEventMap<TWSKey>>(
6457
+ event: U,
6458
+ listener: WSClientEventMap<TWSKey>[U],
6459
+ ): this;
6460
+
6461
+ emit<U extends keyof WSClientEventMap<TWSKey>>(
6462
+ event: U,
6463
+ ...args: Parameters<WSClientEventMap<TWSKey>[U]>
6464
+ ): boolean;
6465
+ }
6466
+ ⋮----
6467
+ on<U extends keyof WSClientEventMap<TWSKey>>(
6468
+ event: U,
6469
+ listener: WSClientEventMap<TWSKey>[U],
6470
+ ): this;
6471
+ ⋮----
6472
+ emit<U extends keyof WSClientEventMap<TWSKey>>(
6473
+ event: U,
6474
+ ...args: Parameters<WSClientEventMap<TWSKey>[U]>
6475
+ ): boolean;
6476
+ ⋮----
6477
+ /**
6478
+ * Users can conveniently pass topics as strings or objects (object has topic name + optional params).
6479
+ *
6480
+ * This method normalises topics into objects (object has topic name + optional params).
6481
+ */
6482
+ function getNormalisedTopicRequests(
6483
+ wsTopicRequests: WsTopicRequestOrStringTopic<string>[],
6484
+ ): WsTopicRequest<string>[]
6485
+ ⋮----
6486
+ // passed as string, convert to object
6487
+ ⋮----
6488
+ // already a normalised object, thanks to user
6489
+ ⋮----
6490
+ /**
6491
+ * Base WebSocket abstraction layer. Handles connections, tracking each connection as a unique "WS Key"
6492
+ */
6493
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
6494
+ export abstract class BaseWebsocketClient<
6495
+ ⋮----
6496
+ /**
6497
+ * The WS connections supported by the client, each identified by a unique primary key
6498
+ */
6499
+ ⋮----
6500
+ /**
5996
6501
  * State store to track a list of topics (topic requests) we are expected to be subscribed to if reconnected
5997
6502
  */
5998
6503
  ⋮----
@@ -6222,575 +6727,86 @@ public tryWsSend(
6222
6727
  )
6223
6728
  ⋮----
6224
6729
  private async onWsOpen(
6225
- event: any,
6226
- wsKey: TWSKey,
6227
- url: string,
6228
- ws: WebSocket,
6229
- )
6230
- ⋮----
6231
- // Resolve & cleanup deferred "connection attempt in progress" promise
6232
- ⋮----
6233
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
6234
- ⋮----
6235
- // Remove before resolving, in case there's more requests queued
6236
- ⋮----
6237
- // Some websockets require an auth packet to be sent after opening the connection
6238
- ⋮----
6239
- // Reconnect to topics known before it connected
6240
- ⋮----
6241
- // Request sub to public topics, if any
6242
- ⋮----
6243
- // Request sub to private topics, if auth on connect isn't needed
6244
- ⋮----
6245
- // If enabled, automatically reauth WS API if reconnected
6246
- ⋮----
6247
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
6248
- ⋮----
6249
- /**
6250
- * Handle subscription to private topics _after_ authentication successfully completes asynchronously.
6251
- *
6252
- * Only used for exchanges that require auth before sending private topic subscription requests
6253
- */
6254
- private onWsAuthenticated(
6255
- wsKey: TWSKey,
6256
- event: { isWSAPI?: boolean; WSAPIAuthChannel?: string },
6257
- )
6258
- ⋮----
6259
- // Resolve & cleanup deferred "auth attempt in progress" promise
6260
- ⋮----
6261
- // Remove before continuing, in case there's more requests queued
6262
- ⋮----
6263
- private onWsMessage(event: unknown, wsKey: TWSKey, ws: WebSocket)
6264
- ⋮----
6265
- // any message can clear the pong timer - wouldn't get a message if the ws wasn't working
6266
- ⋮----
6267
- // console.log(`raw event: `, { data, dataType, emittableEvents });
6268
- ⋮----
6269
- private onWsClose(event: unknown, wsKey: TWSKey)
6270
- ⋮----
6271
- // unintentional close, attempt recovery
6272
- ⋮----
6273
- // clean up any pending promises for this connection
6274
- ⋮----
6275
- // intentional close - clean up
6276
- // clean up any pending promises for this connection
6277
- ⋮----
6278
- // clean up any pending promises for this connection
6279
- ⋮----
6280
- // This was an intentional close, delete all state for this connection, as if it never existed:
6281
- ⋮----
6282
- private getWs(wsKey: TWSKey)
6283
- ⋮----
6284
- private setWsState(wsKey: TWSKey, state: WsConnectionStateEnum)
6285
- ⋮----
6286
- /**
6287
- * Promise-driven method to assert that a ws has successfully connected (will await until connection is open)
6288
- */
6289
- protected async assertIsConnected(wsKey: TWSKey): Promise<unknown>
6290
- ⋮----
6291
- // Already in progress? Await shared promise and retry
6292
- ⋮----
6293
- // Start connection, it should automatically store/return a promise.
6294
- ⋮----
6295
- /**
6296
- * Promise-driven method to assert that a ws has been successfully authenticated (will await until auth is confirmed)
6297
- */
6298
- public async assertIsAuthenticated(wsKey: TWSKey): Promise<unknown>
6299
- ⋮----
6300
- // Already in progress? Await shared promise and retry
6301
- ⋮----
6302
- // this.logger.trace('assertIsAuthenticated(): ok');
6303
- ⋮----
6304
- // Start authentication, it should automatically store/return a promise.
6305
-
6306
- ================
6307
- File: src/types/response/futures.ts
6308
- ================
6309
- /**==========================================================================================================================
6310
- * FUTURES
6311
- * ==========================================================================================================================
6312
- */
6313
- ⋮----
6314
- export interface FuturesOrderBook {
6315
- id?: number;
6316
- current: number;
6317
- update: number;
6318
- asks: { p: string; s: number }[];
6319
- bids: { p: string; s: number }[];
6320
- }
6321
- ⋮----
6322
- export interface FuturesTrade {
6323
- id: number;
6324
- create_time: number;
6325
- create_time_ms: number;
6326
- contract: string;
6327
- size: number;
6328
- price: string;
6329
- is_internal?: boolean;
6330
- }
6730
+ event: any,
6731
+ wsKey: TWSKey,
6732
+ url: string,
6733
+ ws: WebSocket,
6734
+ )
6331
6735
  ⋮----
6332
- export interface FuturesCandle {
6333
- t: number;
6334
- v?: number;
6335
- c: string;
6336
- h: string;
6337
- l: string;
6338
- o: string;
6339
- sum: string;
6340
- }
6736
+ // Resolve & cleanup deferred "connection attempt in progress" promise
6341
6737
  ⋮----
6342
- export interface PremiumIndexKLine {
6343
- t: number;
6344
- c: string;
6345
- h: string;
6346
- l: string;
6347
- o: string;
6348
- }
6738
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
6349
6739
  ⋮----
6350
- export interface FuturesTicker {
6351
- contract: string;
6352
- last: string;
6353
- change_percentage: string;
6354
- total_size: string;
6355
- low_24h: string;
6356
- high_24h: string;
6357
- volume_24h: string;
6358
- volume_24h_btc?: string;
6359
- volume_24h_usd?: string;
6360
- volume_24h_base: string;
6361
- volume_24h_quote: string;
6362
- volume_24h_settle: string;
6363
- mark_price: string;
6364
- funding_rate: string;
6365
- funding_rate_indicative: string;
6366
- index_price: string;
6367
- quanto_base_rate?: string;
6368
- basis_rate: string;
6369
- basis_value: string;
6370
- lowest_ask: string;
6371
- highest_bid: string;
6372
- lowest_size: string;
6373
- highest_size: string;
6374
- }
6740
+ // Remove before resolving, in case there's more requests queued
6375
6741
  ⋮----
6376
- export interface FuturesStats {
6377
- time: number;
6378
- lsr_taker: number;
6379
- lsr_account: number;
6380
- long_liq_size: number;
6381
- long_liq_amount: number;
6382
- long_liq_usd: number;
6383
- short_liq_size: number;
6384
- short_liq_amount: number;
6385
- short_liq_usd: number;
6386
- open_interest: number;
6387
- open_interest_usd: number;
6388
- top_lsr_account: number;
6389
- top_lsr_size: number;
6390
- }
6742
+ // Some websockets require an auth packet to be sent after opening the connection
6391
6743
  ⋮----
6392
- export interface IndexConstituents {
6393
- index: string;
6394
- constituents: {
6395
- exchange: string;
6396
- symbols: string[];
6397
- }[];
6398
- }
6744
+ // Reconnect to topics known before it connected
6399
6745
  ⋮----
6400
- export interface LiquidationHistoryRecord {
6401
- time: number;
6402
- contract: string;
6403
- size: number;
6404
- order_size: number;
6405
- order_price: string;
6406
- fill_price: string;
6407
- left: number;
6408
- }
6746
+ // Request sub to public topics, if any
6409
6747
  ⋮----
6410
- export interface RiskLimitTier {
6411
- tier: number;
6412
- risk_limit: string;
6413
- initial_rate: string;
6414
- maintenance_rate: string;
6415
- leverage_max: string;
6416
- contract: string;
6417
- }
6748
+ // Request sub to private topics, if auth on connect isn't needed
6418
6749
  ⋮----
6419
- export interface FuturesAccount {
6420
- total: string;
6421
- unrealised_pnl: string;
6422
- position_margin: string;
6423
- order_margin: string;
6424
- available: string;
6425
- point: string;
6426
- currency: string;
6427
- in_dual_mode: boolean;
6428
- enable_credit: boolean;
6429
- position_initial_margin: string;
6430
- maintenance_margin: string;
6431
- bonus: string;
6432
- enable_evolved_classic: boolean;
6433
- cross_order_margin: string;
6434
- cross_initial_margin: string;
6435
- cross_maintenance_margin: string;
6436
- cross_unrealised_pnl: string;
6437
- cross_available: string;
6438
- cross_margin_balance: string;
6439
- cross_mmr: string;
6440
- cross_imr: string;
6441
- isolated_position_margin: string;
6442
- enable_new_dual_mode: boolean;
6443
- margin_mode: number;
6444
- history: {
6445
- dnw: string;
6446
- pnl: string;
6447
- fee: string;
6448
- refr: string;
6449
- fund: string;
6450
- point_dnw: string;
6451
- point_fee: string;
6452
- point_refr: string;
6453
- bonus_dnw: string;
6454
- bonus_offset: string;
6455
- };
6456
- }
6750
+ // If enabled, automatically reauth WS API if reconnected
6457
6751
  ⋮----
6458
- export interface FuturesAccountBookRecord {
6459
- time: number;
6460
- change: string;
6461
- balance: string;
6462
- type: string;
6463
- text: string;
6464
- contract?: string;
6465
- trade_id: string;
6466
- id: string;
6467
- }
6752
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
6468
6753
  ⋮----
6469
- export interface FuturesOrder {
6470
- id?: number;
6471
- user?: number;
6472
- create_time?: number;
6473
- finish_time?: number;
6474
- finish_as?:
6475
- | 'filled'
6476
- | 'cancelled'
6477
- | 'liquidated'
6478
- | 'ioc'
6479
- | 'auto_deleveraged'
6480
- | 'reduce_only'
6481
- | 'position_closed'
6482
- | 'stp';
6483
- status?: 'open' | 'finished';
6484
- contract: string;
6485
- size: number;
6486
- iceberg?: number;
6487
- price?: string;
6488
- close?: boolean;
6489
- is_close?: boolean;
6490
- reduce_only?: boolean;
6491
- is_reduce_only?: boolean;
6492
- is_liq?: boolean;
6493
- tif?: 'gtc' | 'ioc' | 'poc' | 'fok';
6494
- left?: number;
6495
- fill_price?: string;
6496
- text?: string;
6497
- tkfr?: string;
6498
- mkfr?: string;
6499
- refu?: number;
6500
- auto_size?: 'close_long' | 'close_short';
6501
- stp_id?: number;
6502
- stp_act?: 'cn' | 'co' | 'cb' | '-';
6503
- amend_text?: string;
6504
- biz_info?: string;
6505
- }
6754
+ /**
6755
+ * Handle subscription to private topics _after_ authentication successfully completes asynchronously.
6756
+ *
6757
+ * Only used for exchanges that require auth before sending private topic subscription requests
6758
+ */
6759
+ private onWsAuthenticated(
6760
+ wsKey: TWSKey,
6761
+ event: { isWSAPI?: boolean; WSAPIAuthChannel?: string },
6762
+ )
6506
6763
  ⋮----
6507
- export interface FuturesPosition {
6508
- user?: number;
6509
- contract?: string;
6510
- size?: number;
6511
- leverage?: string;
6512
- risk_limit?: string;
6513
- leverage_max?: string;
6514
- maintenance_rate?: string;
6515
- value?: string;
6516
- margin?: string;
6517
- entry_price?: string;
6518
- liq_price?: string;
6519
- mark_price?: string;
6520
- initial_margin?: string;
6521
- maintenance_margin?: string;
6522
- unrealised_pnl?: string;
6523
- realised_pnl?: string;
6524
- pnl_pnl?: string;
6525
- pnl_fund?: string;
6526
- pnl_fee?: string;
6527
- history_pnl?: string;
6528
- last_close_pnl?: string;
6529
- realised_point?: string;
6530
- history_point?: string;
6531
- adl_ranking?: number;
6532
- pending_orders?: number;
6533
- close_order?: {
6534
- id?: number;
6535
- price?: string;
6536
- is_liq?: boolean;
6537
- } | null;
6538
- mode?: 'single' | 'dual_long' | 'dual_short';
6539
- cross_leverage_limit?: string;
6540
- update_time?: number;
6541
- update_id?: number;
6542
- open_time?: number;
6543
- }
6764
+ // Resolve & cleanup deferred "auth attempt in progress" promise
6544
6765
  ⋮----
6545
- export interface FuturesTradingHistoryRecord {
6546
- id: number;
6547
- create_time: number;
6548
- contract: string;
6549
- order_id: string;
6550
- size: number;
6551
- price: string;
6552
- role: 'taker' | 'maker';
6553
- text: string;
6554
- fee: string;
6555
- point_fee: string;
6556
- close_size: number;
6557
- }
6766
+ // Remove before continuing, in case there's more requests queued
6558
6767
  ⋮----
6559
- export interface FuturesPositionHistoryRecord {
6560
- time: number;
6561
- contract: string;
6562
- side: 'long' | 'short';
6563
- pnl: string;
6564
- pnl_pnl: string;
6565
- pnl_fund: string;
6566
- pnl_fee: string;
6567
- text: string;
6568
- max_size: string;
6569
- first_open_time: number;
6570
- long_price: string;
6571
- short_price: string;
6572
- accum_size: string;
6573
- }
6768
+ private onWsMessage(event: unknown, wsKey: TWSKey, ws: WebSocket)
6574
6769
  ⋮----
6575
- export interface FuturesLiquidationHistoryRecord {
6576
- time: number;
6577
- contract: string;
6578
- leverage: string;
6579
- size: number;
6580
- margin: string;
6581
- entry_price: string;
6582
- liq_price: string;
6583
- mark_price: string;
6584
- order_id: number;
6585
- order_price: string;
6586
- fill_price: string;
6587
- left: number;
6588
- }
6589
- export interface FuturesAutoDeleveragingHistoryRecord {
6590
- time: number;
6591
- user: number;
6592
- order_id: number;
6593
- contract: string;
6594
- leverage: string;
6595
- cross_leverage_limit: string;
6596
- entry_price: string;
6597
- fill_price: string;
6598
- trade_size: number;
6599
- position_size: number;
6600
- }
6770
+ // any message can clear the pong timer - wouldn't get a message if the ws wasn't working
6601
6771
  ⋮----
6602
- export interface DeleteFuturesBatchOrdersResp {
6603
- user_id: number;
6604
- id: string;
6605
- succeeded: boolean;
6606
- message: string;
6607
- }
6772
+ // console.log(`raw event: `, { data, dataType, emittableEvents });
6608
6773
  ⋮----
6609
- export interface FuturesContract {
6610
- name?: string;
6611
- type?: 'inverse' | 'direct';
6612
- quanto_multiplier?: string;
6613
- leverage_min?: string;
6614
- leverage_max?: string;
6615
- maintenance_rate?: string;
6616
- mark_type?: 'internal' | 'index';
6617
- mark_price?: string;
6618
- index_price?: string;
6619
- last_price?: string;
6620
- maker_fee_rate?: string;
6621
- taker_fee_rate?: string;
6622
- order_price_round?: string;
6623
- mark_price_round?: string;
6624
- funding_rate?: string;
6625
- funding_interval?: number;
6626
- funding_next_apply?: number;
6627
- risk_limit_base?: string;
6628
- risk_limit_step?: string;
6629
- risk_limit_max?: string;
6630
- order_size_min?: number;
6631
- order_size_max?: number;
6632
- order_price_deviate?: string;
6633
- ref_discount_rate?: string;
6634
- ref_rebate_rate?: string;
6635
- orderbook_id?: number;
6636
- trade_id?: number;
6637
- trade_size?: number;
6638
- position_size?: number;
6639
- config_change_time?: number;
6640
- in_delisting?: boolean;
6641
- orders_limit?: number;
6642
- enable_bonus?: boolean;
6643
- enable_credit?: boolean;
6644
- create_time?: number;
6645
- funding_cap_ratio?: string;
6646
- }
6774
+ private onWsClose(event: unknown, wsKey: TWSKey)
6647
6775
  ⋮----
6648
- export interface FuturesPriceTriggeredOrder {
6649
- initial: {
6650
- contract: string;
6651
- size?: number;
6652
- price?: string;
6653
- close?: boolean;
6654
- tif?: 'gtc' | 'ioc';
6655
- text?: string;
6656
- reduce_only?: boolean;
6657
- auto_size?: string;
6658
- is_reduce_only?: boolean;
6659
- is_close?: boolean;
6660
- };
6661
- trigger: {
6662
- strategy_type?: 0 | 1;
6663
- price_type?: 0 | 1 | 2;
6664
- price?: string;
6665
- rule?: 1 | 2;
6666
- expiration?: number;
6667
- };
6668
- id?: number;
6669
- user?: number;
6670
- create_time?: number;
6671
- finish_time?: number;
6672
- trade_id?: number;
6673
- status?: 'open' | 'finished' | 'inactive' | 'invalid';
6674
- finish_as?: 'cancelled' | 'succeeded' | 'failed' | 'expired';
6675
- reason?: string;
6676
- order_type?:
6677
- | 'close-long-order'
6678
- | 'close-short-order'
6679
- | 'close-long-position'
6680
- | 'close-short-position'
6681
- | 'plan-close-long-position'
6682
- | 'plan-close-short-position';
6683
- me_order_id?: number;
6684
- }
6776
+ // unintentional close, attempt recovery
6685
6777
  ⋮----
6686
- export interface FuturesDeliveryContract {
6687
- name?: string;
6688
- underlying?: string;
6689
- cycle?: 'WEEKLY' | 'BI-WEEKLY' | 'QUARTERLY' | 'BI-QUARTERLY';
6690
- type?: 'inverse' | 'direct';
6691
- quanto_multiplier?: string;
6692
- leverage_min?: string;
6693
- leverage_max?: string;
6694
- maintenance_rate?: string;
6695
- mark_type?: 'internal' | 'index';
6696
- mark_price?: string;
6697
- index_price?: string;
6698
- last_price?: string;
6699
- maker_fee_rate?: string;
6700
- taker_fee_rate?: string;
6701
- order_price_round?: string;
6702
- mark_price_round?: string;
6703
- basis_rate?: string;
6704
- basis_value?: string;
6705
- basis_impact_value?: string;
6706
- settle_price?: string;
6707
- settle_price_interval?: number;
6708
- settle_price_duration?: number;
6709
- expire_time?: number;
6710
- risk_limit_base?: string;
6711
- risk_limit_step?: string;
6712
- risk_limit_max?: string;
6713
- order_size_min?: number;
6714
- order_size_max?: number;
6715
- order_price_deviate?: string;
6716
- ref_discount_rate?: string;
6717
- ref_rebate_rate?: string;
6718
- orderbook_id?: number;
6719
- trade_id?: number;
6720
- trade_size?: number;
6721
- position_size?: number;
6722
- config_change_time?: number;
6723
- in_delisting?: boolean;
6724
- orders_limit?: number;
6725
- }
6778
+ // clean up any pending promises for this connection
6726
6779
  ⋮----
6727
- export interface BatchAmendOrderResp {
6728
- succeeded: boolean;
6729
- label?: string;
6730
- detail?: string;
6731
- id: number;
6732
- user: number;
6733
- create_time: number;
6734
- finish_time?: number;
6735
- finish_as?:
6736
- | 'filled'
6737
- | 'cancelled'
6738
- | 'liquidated'
6739
- | 'ioc'
6740
- | 'auto_deleveraged'
6741
- | 'reduce_only'
6742
- | 'position_closed'
6743
- | 'reduce_out'
6744
- | 'stp';
6745
- status: 'open' | 'finished';
6746
- contract: string;
6747
- size: number;
6748
- iceberg: number;
6749
- price: string;
6750
- is_close: boolean;
6751
- is_reduce_only: boolean;
6752
- is_liq: boolean;
6753
- tif: 'gtc' | 'ioc' | 'poc' | 'fok';
6754
- left: number;
6755
- fill_price: string;
6756
- text: string;
6757
- tkfr: string;
6758
- mkfr: string;
6759
- refu: number;
6760
- stp_act: 'co' | 'cn' | 'cb' | '-';
6761
- stp_id: number;
6762
- }
6780
+ // intentional close - clean up
6781
+ // clean up any pending promises for this connection
6782
+ ⋮----
6783
+ // clean up any pending promises for this connection
6784
+ ⋮----
6785
+ // This was an intentional close, delete all state for this connection, as if it never existed:
6786
+ ⋮----
6787
+ private getWs(wsKey: TWSKey)
6788
+ ⋮----
6789
+ private setWsState(wsKey: TWSKey, state: WsConnectionStateEnum)
6763
6790
  ⋮----
6764
6791
  /**
6765
- * @deprecated - Use FuturesAccount instead
6766
- */
6767
- export interface UpdateFuturesDualModeResp {
6768
- total: string;
6769
- unrealised_pnl: string;
6770
- position_margin: string;
6771
- order_margin: string;
6772
- available: string;
6773
- point: string;
6774
- currency: string;
6775
- in_dual_mode: boolean;
6776
- enable_credit: boolean;
6777
- position_initial_margin: string;
6778
- maintenance_margin: string;
6779
- bonus: string;
6780
- enable_evolved_classic: boolean;
6781
- history: {
6782
- dnw: string;
6783
- pnl: string;
6784
- fee: string;
6785
- refr: string;
6786
- fund: string;
6787
- point_dnw: string;
6788
- point_fee: string;
6789
- point_refr: string;
6790
- bonus_dnw: string;
6791
- bonus_offset: string;
6792
- };
6793
- }
6792
+ * Promise-driven method to assert that a ws has successfully connected (will await until connection is open)
6793
+ */
6794
+ protected async assertIsConnected(wsKey: TWSKey): Promise<unknown>
6795
+ ⋮----
6796
+ // Already in progress? Await shared promise and retry
6797
+ ⋮----
6798
+ // Start connection, it should automatically store/return a promise.
6799
+ ⋮----
6800
+ /**
6801
+ * Promise-driven method to assert that a ws has been successfully authenticated (will await until auth is confirmed)
6802
+ */
6803
+ public async assertIsAuthenticated(wsKey: TWSKey): Promise<unknown>
6804
+ ⋮----
6805
+ // Already in progress? Await shared promise and retry
6806
+ ⋮----
6807
+ // this.logger.trace('assertIsAuthenticated(): ok');
6808
+ ⋮----
6809
+ // Start authentication, it should automatically store/return a promise.
6794
6810
 
6795
6811
  ================
6796
6812
  File: src/WebsocketAPIClient.ts
@@ -7887,6 +7903,7 @@ import {
7887
7903
  GetFuturesTradingHistoryByTimeRangeReq,
7888
7904
  GetFuturesTradingHistoryReq,
7889
7905
  GetLiquidationHistoryReq,
7906
+ GetRiskLimitTableReq,
7890
7907
  GetRiskLimitTiersReq,
7891
7908
  SubmitFuturesOrderReq,
7892
7909
  SubmitFuturesTriggeredOrderReq,
@@ -8042,6 +8059,7 @@ import {
8042
8059
  IndexConstituents,
8043
8060
  LiquidationHistoryRecord,
8044
8061
  PremiumIndexKLine,
8062
+ RiskLimitTableTier,
8045
8063
  RiskLimitTier,
8046
8064
  } from './types/response/futures.js';
8047
8065
  import {
@@ -9196,6 +9214,20 @@ cancelSpotTriggeredOrder(params: {
9196
9214
  order_id: string;
9197
9215
  }): Promise<SpotPriceTriggeredOrder>
9198
9216
  ⋮----
9217
+ /**
9218
+ * Set collateral currency
9219
+ *
9220
+ * @param params Parameters for setting collateral currency
9221
+ * @returns Promise<{
9222
+ * is_success: boolean;
9223
+ * }>
9224
+ */
9225
+ setCollateralCurrency(params: {
9226
+ collateral_type: 0 | 1;
9227
+ enable_list?: string[];
9228
+ disable_list?: string[];
9229
+ }): Promise<
9230
+ ⋮----
9199
9231
  /**==========================================================================================================================
9200
9232
  * MARGIN
9201
9233
  * ==========================================================================================================================
@@ -10164,6 +10196,16 @@ batchUpdateFuturesOrders(params: {
10164
10196
  orders: BatchAmendOrderReq[];
10165
10197
  }): Promise<BatchAmendOrderResp[]>
10166
10198
  ⋮----
10199
+ /**
10200
+ * Query risk limit table by table_id
10201
+ *
10202
+ * @param params Parameters for querying risk limit table
10203
+ * @returns Promise<RiskLimitTableTier[]>
10204
+ */
10205
+ getRiskLimitTable(
10206
+ params: GetRiskLimitTableReq,
10207
+ ): Promise<RiskLimitTableTier[]>
10208
+ ⋮----
10167
10209
  /**
10168
10210
  * Create a price-triggered order
10169
10211
  *
@@ -11474,7 +11516,7 @@ File: package.json
11474
11516
  ================
11475
11517
  {
11476
11518
  "name": "gateio-api",
11477
- "version": "1.2.4",
11519
+ "version": "1.2.6",
11478
11520
  "description": "Complete & Robust Node.js SDK for Gate.com's REST APIs, WebSockets & WebSocket APIs, with TypeScript declarations.",
11479
11521
  "scripts": {
11480
11522
  "clean": "rm -rf dist/*",