gateio-api 1.2.4 → 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/README.md +65 -9
- package/dist/cjs/RestClient.d.ts +24 -2
- package/dist/cjs/RestClient.js +21 -0
- package/dist/cjs/RestClient.js.map +1 -1
- package/dist/cjs/types/request/futures.d.ts +4 -0
- package/dist/cjs/types/response/delivery.d.ts +1 -0
- package/dist/cjs/types/response/futures.d.ts +9 -0
- package/dist/mjs/RestClient.d.ts +24 -2
- package/dist/mjs/RestClient.js +21 -0
- package/dist/mjs/RestClient.js.map +1 -1
- package/dist/mjs/types/request/futures.d.ts +4 -0
- package/dist/mjs/types/response/delivery.d.ts +1 -0
- package/dist/mjs/types/response/futures.d.ts +9 -0
- package/llms.txt +1094 -989
- package/package.json +1 -1
package/llms.txt
CHANGED
|
@@ -2356,42 +2356,6 @@ File: tsconfig.esm.json
|
|
|
2356
2356
|
"include": ["src/**/*.*"]
|
|
2357
2357
|
}
|
|
2358
2358
|
|
|
2359
|
-
================
|
|
2360
|
-
File: tsconfig.json
|
|
2361
|
-
================
|
|
2362
|
-
{
|
|
2363
|
-
"compilerOptions": {
|
|
2364
|
-
"allowSyntheticDefaultImports": true,
|
|
2365
|
-
"baseUrl": "src",
|
|
2366
|
-
"noEmitOnError": true,
|
|
2367
|
-
"declaration": true,
|
|
2368
|
-
"esModuleInterop": true,
|
|
2369
|
-
"forceConsistentCasingInFileNames": false,
|
|
2370
|
-
"inlineSourceMap": false,
|
|
2371
|
-
"lib": ["esnext"],
|
|
2372
|
-
"listEmittedFiles": false,
|
|
2373
|
-
"listFiles": false,
|
|
2374
|
-
"moduleResolution": "node",
|
|
2375
|
-
"noFallthroughCasesInSwitch": true,
|
|
2376
|
-
"noImplicitAny": true,
|
|
2377
|
-
"noUnusedParameters": true,
|
|
2378
|
-
"pretty": true,
|
|
2379
|
-
"removeComments": false,
|
|
2380
|
-
"resolveJsonModule": true,
|
|
2381
|
-
"skipLibCheck": false,
|
|
2382
|
-
"sourceMap": true,
|
|
2383
|
-
"strict": true,
|
|
2384
|
-
"strictNullChecks": true,
|
|
2385
|
-
"types": ["node", "jest"],
|
|
2386
|
-
"module": "commonjs",
|
|
2387
|
-
"outDir": "dist/cjs",
|
|
2388
|
-
"target": "esnext"
|
|
2389
|
-
},
|
|
2390
|
-
"compileOnSave": true,
|
|
2391
|
-
"exclude": ["node_modules", "dist"],
|
|
2392
|
-
"include": ["src/**/*.*", "test/**/*.*", ".eslintrc.cjs"]
|
|
2393
|
-
}
|
|
2394
|
-
|
|
2395
2359
|
================
|
|
2396
2360
|
File: tsconfig.linting.json
|
|
2397
2361
|
================
|
|
@@ -3408,6 +3372,7 @@ export interface DeliveryAccount {
|
|
|
3408
3372
|
bonus_dnw: string;
|
|
3409
3373
|
bonus_offset: string;
|
|
3410
3374
|
};
|
|
3375
|
+
enable_tiered_mm: boolean;
|
|
3411
3376
|
}
|
|
3412
3377
|
⋮----
|
|
3413
3378
|
export interface DeliveryBook {
|
|
@@ -3774,6 +3739,223 @@ export interface PartnerTransaction {
|
|
|
3774
3739
|
source: string;
|
|
3775
3740
|
}
|
|
3776
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
|
+
|
|
3777
3959
|
================
|
|
3778
3960
|
File: src/index.ts
|
|
3779
3961
|
================
|
|
@@ -3786,49 +3968,45 @@ File: src/index.ts
|
|
|
3786
3968
|
// Shared Types
|
|
3787
3969
|
|
|
3788
3970
|
================
|
|
3789
|
-
File: .
|
|
3971
|
+
File: .nvmrc
|
|
3790
3972
|
================
|
|
3791
|
-
|
|
3792
|
-
.DS_STORE
|
|
3793
|
-
*.log
|
|
3794
|
-
npm-debug.log*
|
|
3795
|
-
yarn-debug.log*
|
|
3796
|
-
yarn-error.log*
|
|
3797
|
-
lerna-debug.log*
|
|
3798
|
-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
3799
|
-
pids
|
|
3800
|
-
*.pid
|
|
3801
|
-
*.seed
|
|
3802
|
-
*.pid.lock
|
|
3803
|
-
node_modules/
|
|
3804
|
-
.npm
|
|
3805
|
-
.eslintcache
|
|
3806
|
-
.node_repl_history
|
|
3807
|
-
*.tgz
|
|
3808
|
-
.yarn-integrity
|
|
3809
|
-
.env
|
|
3810
|
-
.env.test
|
|
3811
|
-
.cache
|
|
3812
|
-
bundleReport.html
|
|
3813
|
-
.history/
|
|
3814
|
-
dist
|
|
3815
|
-
coverage
|
|
3816
|
-
localtest.sh
|
|
3817
|
-
repomix.sh
|
|
3818
|
-
|
|
3819
|
-
ws-private-spot-wsapi-performance.ts
|
|
3820
|
-
ws-private-perp-futures-wsapi-readonly.ts
|
|
3821
|
-
privatetest.ts
|
|
3822
|
-
|
|
3823
|
-
privaterepotracker
|
|
3824
|
-
restClientRegex.ts
|
|
3825
|
-
|
|
3826
|
-
testfile.ts
|
|
3973
|
+
v22.17.0
|
|
3827
3974
|
|
|
3828
3975
|
================
|
|
3829
|
-
File: .
|
|
3976
|
+
File: tsconfig.json
|
|
3830
3977
|
================
|
|
3831
|
-
|
|
3978
|
+
{
|
|
3979
|
+
"compilerOptions": {
|
|
3980
|
+
"allowSyntheticDefaultImports": true,
|
|
3981
|
+
"baseUrl": ".",
|
|
3982
|
+
"noEmitOnError": true,
|
|
3983
|
+
"declaration": true,
|
|
3984
|
+
"esModuleInterop": true,
|
|
3985
|
+
"forceConsistentCasingInFileNames": false,
|
|
3986
|
+
"inlineSourceMap": false,
|
|
3987
|
+
"lib": ["esnext"],
|
|
3988
|
+
"listEmittedFiles": false,
|
|
3989
|
+
"listFiles": false,
|
|
3990
|
+
"moduleResolution": "node",
|
|
3991
|
+
"noFallthroughCasesInSwitch": true,
|
|
3992
|
+
"noImplicitAny": true,
|
|
3993
|
+
"noUnusedParameters": true,
|
|
3994
|
+
"pretty": true,
|
|
3995
|
+
"removeComments": false,
|
|
3996
|
+
"resolveJsonModule": true,
|
|
3997
|
+
"skipLibCheck": false,
|
|
3998
|
+
"sourceMap": true,
|
|
3999
|
+
"strict": true,
|
|
4000
|
+
"strictNullChecks": true,
|
|
4001
|
+
"types": ["node", "jest"],
|
|
4002
|
+
"module": "commonjs",
|
|
4003
|
+
"outDir": "dist/cjs",
|
|
4004
|
+
"target": "esnext"
|
|
4005
|
+
},
|
|
4006
|
+
"compileOnSave": true,
|
|
4007
|
+
"exclude": ["node_modules", "dist"],
|
|
4008
|
+
"include": ["src/**/*.*", "test/**/*.*", ".eslintrc.cjs"]
|
|
4009
|
+
}
|
|
3832
4010
|
|
|
3833
4011
|
================
|
|
3834
4012
|
File: examples/ws-private-spot-wsapi.ts
|
|
@@ -4070,291 +4248,74 @@ export function safeTerminateWs(
|
|
|
4070
4248
|
): boolean
|
|
4071
4249
|
|
|
4072
4250
|
================
|
|
4073
|
-
File: src/types/
|
|
4251
|
+
File: src/types/request/futures.ts
|
|
4074
4252
|
================
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4253
|
+
/**==========================================================================================================================
|
|
4254
|
+
* FUTURES
|
|
4255
|
+
* ==========================================================================================================================
|
|
4256
|
+
*/
|
|
4257
|
+
⋮----
|
|
4258
|
+
export interface GetFuturesOrderBookReq {
|
|
4259
|
+
settle: 'btc' | 'usdt' | 'usd';
|
|
4260
|
+
contract: string;
|
|
4261
|
+
interval?: string;
|
|
4262
|
+
limit?: number;
|
|
4263
|
+
with_id?: boolean;
|
|
4084
4264
|
}
|
|
4085
4265
|
⋮----
|
|
4086
|
-
export interface
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
obtain_failed: number;
|
|
4095
|
-
}[];
|
|
4266
|
+
export interface GetFuturesTradesReq {
|
|
4267
|
+
settle: 'btc' | 'usdt' | 'usd';
|
|
4268
|
+
contract: string;
|
|
4269
|
+
limit?: number;
|
|
4270
|
+
offset?: number;
|
|
4271
|
+
last_id?: string;
|
|
4272
|
+
from?: number;
|
|
4273
|
+
to?: number;
|
|
4096
4274
|
}
|
|
4097
4275
|
⋮----
|
|
4098
|
-
export interface
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
timest: string;
|
|
4106
|
-
source: string;
|
|
4107
|
-
sub_account_type: 'spot' | 'futures' | 'cross_margin' | 'delivery';
|
|
4276
|
+
export interface GetFuturesCandlesReq {
|
|
4277
|
+
settle: 'btc' | 'usdt' | 'usd';
|
|
4278
|
+
contract: string;
|
|
4279
|
+
from?: number;
|
|
4280
|
+
to?: number;
|
|
4281
|
+
limit?: number;
|
|
4282
|
+
interval?: string;
|
|
4108
4283
|
}
|
|
4109
4284
|
⋮----
|
|
4110
|
-
export interface
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
withdraw_fix: string;
|
|
4117
|
-
withdraw_day_limit: string;
|
|
4118
|
-
withdraw_amount_mini: string;
|
|
4119
|
-
withdraw_day_limit_remain: string;
|
|
4120
|
-
withdraw_eachtime_limit: string;
|
|
4121
|
-
withdraw_fix_on_chains: { [key: string]: string };
|
|
4122
|
-
withdraw_percent_on_chains: { [key: string]: string };
|
|
4285
|
+
export interface GetFuturesStatsReq {
|
|
4286
|
+
settle: 'btc' | 'usdt' | 'usd';
|
|
4287
|
+
contract: string;
|
|
4288
|
+
from?: number;
|
|
4289
|
+
interval?: string;
|
|
4290
|
+
limit?: number;
|
|
4123
4291
|
}
|
|
4124
4292
|
⋮----
|
|
4125
|
-
export interface
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
available: string;
|
|
4132
|
-
locked: string;
|
|
4133
|
-
borrowed: string;
|
|
4134
|
-
interest: string;
|
|
4135
|
-
};
|
|
4136
|
-
quote: {
|
|
4137
|
-
currency: string;
|
|
4138
|
-
available: string;
|
|
4139
|
-
locked: string;
|
|
4140
|
-
borrowed: string;
|
|
4141
|
-
interest: string;
|
|
4142
|
-
};
|
|
4293
|
+
export interface GetFundingRatesReq {
|
|
4294
|
+
settle: 'btc' | 'usdt' | 'usd';
|
|
4295
|
+
contract: string;
|
|
4296
|
+
limit?: number;
|
|
4297
|
+
from?: number;
|
|
4298
|
+
to?: number;
|
|
4143
4299
|
}
|
|
4144
4300
|
⋮----
|
|
4145
|
-
export interface
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
position_margin: string;
|
|
4152
|
-
order_margin: string;
|
|
4153
|
-
available: string;
|
|
4154
|
-
point: string;
|
|
4155
|
-
currency: string;
|
|
4156
|
-
in_dual_mode: boolean;
|
|
4157
|
-
enable_credit: boolean;
|
|
4158
|
-
position_initial_margin: string;
|
|
4159
|
-
maintenance_margin: string;
|
|
4160
|
-
bonus: string;
|
|
4161
|
-
enable_evolved_classic: boolean;
|
|
4162
|
-
cross_order_margin: string;
|
|
4163
|
-
cross_initial_margin: string;
|
|
4164
|
-
cross_maintenance_margin: string;
|
|
4165
|
-
cross_unrealised_pnl: string;
|
|
4166
|
-
cross_available: string;
|
|
4167
|
-
isolated_position_margin: string;
|
|
4168
|
-
history: {
|
|
4169
|
-
dnw: string;
|
|
4170
|
-
pnl: string;
|
|
4171
|
-
fee: string;
|
|
4172
|
-
refr: string;
|
|
4173
|
-
fund: string;
|
|
4174
|
-
point_dnw: string;
|
|
4175
|
-
point_fee: string;
|
|
4176
|
-
point_refr: string;
|
|
4177
|
-
bonus_dnw: string;
|
|
4178
|
-
bonus_offset: string;
|
|
4179
|
-
};
|
|
4180
|
-
};
|
|
4181
|
-
};
|
|
4301
|
+
export interface GetLiquidationHistoryReq {
|
|
4302
|
+
settle: 'btc' | 'usdt' | 'usd';
|
|
4303
|
+
contract?: string;
|
|
4304
|
+
from?: number;
|
|
4305
|
+
to?: number;
|
|
4306
|
+
limit?: number;
|
|
4182
4307
|
}
|
|
4183
4308
|
⋮----
|
|
4184
|
-
export interface
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
balances: {
|
|
4190
|
-
[key: string]: {
|
|
4191
|
-
available: string;
|
|
4192
|
-
freeze: string;
|
|
4193
|
-
borrowed: string;
|
|
4194
|
-
interest: string;
|
|
4195
|
-
};
|
|
4196
|
-
};
|
|
4197
|
-
total: string;
|
|
4198
|
-
borrowed: string;
|
|
4199
|
-
borrowed_net: string;
|
|
4200
|
-
net: string;
|
|
4201
|
-
leverage: string;
|
|
4202
|
-
interest: string;
|
|
4203
|
-
risk: string;
|
|
4204
|
-
total_initial_margin: string;
|
|
4205
|
-
total_margin_balance: string;
|
|
4206
|
-
total_maintenance_margin: string;
|
|
4207
|
-
total_initial_margin_rate: string;
|
|
4208
|
-
total_maintenance_margin_rate: string;
|
|
4209
|
-
total_available_margin: string;
|
|
4210
|
-
};
|
|
4309
|
+
export interface GetRiskLimitTiersReq {
|
|
4310
|
+
settle: 'btc' | 'usdt' | 'usd';
|
|
4311
|
+
contract: string;
|
|
4312
|
+
limit?: number;
|
|
4313
|
+
offset?: number;
|
|
4211
4314
|
}
|
|
4212
4315
|
⋮----
|
|
4213
|
-
export interface
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
address: string;
|
|
4217
|
-
name: string;
|
|
4218
|
-
tag: string;
|
|
4219
|
-
verified: string;
|
|
4220
|
-
}
|
|
4221
|
-
⋮----
|
|
4222
|
-
export interface TradingFees {
|
|
4223
|
-
user_id: number;
|
|
4224
|
-
taker_fee: string;
|
|
4225
|
-
maker_fee: string;
|
|
4226
|
-
gt_discount: boolean;
|
|
4227
|
-
gt_taker_fee: string;
|
|
4228
|
-
gt_maker_fee: string;
|
|
4229
|
-
loan_fee: string;
|
|
4230
|
-
point_type: string;
|
|
4231
|
-
futures_taker_fee: string;
|
|
4232
|
-
futures_maker_fee: string;
|
|
4233
|
-
delivery_taker_fee: string;
|
|
4234
|
-
delivery_maker_fee: string;
|
|
4235
|
-
debit_fee: number;
|
|
4236
|
-
}
|
|
4237
|
-
⋮----
|
|
4238
|
-
export interface GetBalancesResp {
|
|
4239
|
-
total: {
|
|
4240
|
-
amount: string;
|
|
4241
|
-
currency: string;
|
|
4242
|
-
unrealised_pnl?: string;
|
|
4243
|
-
borrowed?: string;
|
|
4244
|
-
};
|
|
4245
|
-
details: {
|
|
4246
|
-
[key: string]: {
|
|
4247
|
-
amount: string;
|
|
4248
|
-
currency: string;
|
|
4249
|
-
unrealised_pnl?: string;
|
|
4250
|
-
borrowed?: string;
|
|
4251
|
-
};
|
|
4252
|
-
};
|
|
4253
|
-
}
|
|
4254
|
-
⋮----
|
|
4255
|
-
export interface SmallBalanceRecord {
|
|
4256
|
-
currency: string;
|
|
4257
|
-
available_balance: string;
|
|
4258
|
-
estimated_as_btc: string;
|
|
4259
|
-
convertible_to_gt: string;
|
|
4260
|
-
}
|
|
4261
|
-
⋮----
|
|
4262
|
-
export interface SmallBalanceHistoryRecord {
|
|
4263
|
-
id: string;
|
|
4264
|
-
currency: string;
|
|
4265
|
-
amount: string;
|
|
4266
|
-
gt_amount: string;
|
|
4267
|
-
create_time: number;
|
|
4268
|
-
}
|
|
4269
|
-
⋮----
|
|
4270
|
-
export interface PushOrder {
|
|
4271
|
-
id: number;
|
|
4272
|
-
push_uid: number;
|
|
4273
|
-
receive_uid: number;
|
|
4274
|
-
currency: string;
|
|
4275
|
-
amount: string;
|
|
4276
|
-
create_time: number;
|
|
4277
|
-
status:
|
|
4278
|
-
| 'CREATING'
|
|
4279
|
-
| 'PENDING'
|
|
4280
|
-
| 'CANCELLING'
|
|
4281
|
-
| 'CANCELLED'
|
|
4282
|
-
| 'REFUSING'
|
|
4283
|
-
| 'REFUSED'
|
|
4284
|
-
| 'RECEIVING'
|
|
4285
|
-
| 'RECEIVED';
|
|
4286
|
-
message: string;
|
|
4287
|
-
}
|
|
4288
|
-
|
|
4289
|
-
================
|
|
4290
|
-
File: .eslintrc.cjs
|
|
4291
|
-
================
|
|
4292
|
-
// 'no-unused-vars': ['warn'],
|
|
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;
|
|
4308
|
-
}
|
|
4309
|
-
⋮----
|
|
4310
|
-
export interface GetFuturesTradesReq {
|
|
4311
|
-
settle: 'btc' | 'usdt' | 'usd';
|
|
4312
|
-
contract: string;
|
|
4313
|
-
limit?: number;
|
|
4314
|
-
offset?: number;
|
|
4315
|
-
last_id?: string;
|
|
4316
|
-
from?: number;
|
|
4317
|
-
to?: number;
|
|
4318
|
-
}
|
|
4319
|
-
⋮----
|
|
4320
|
-
export interface GetFuturesCandlesReq {
|
|
4321
|
-
settle: 'btc' | 'usdt' | 'usd';
|
|
4322
|
-
contract: string;
|
|
4323
|
-
from?: number;
|
|
4324
|
-
to?: number;
|
|
4325
|
-
limit?: number;
|
|
4326
|
-
interval?: string;
|
|
4327
|
-
}
|
|
4328
|
-
⋮----
|
|
4329
|
-
export interface GetFuturesStatsReq {
|
|
4330
|
-
settle: 'btc' | 'usdt' | 'usd';
|
|
4331
|
-
contract: string;
|
|
4332
|
-
from?: number;
|
|
4333
|
-
interval?: string;
|
|
4334
|
-
limit?: number;
|
|
4335
|
-
}
|
|
4336
|
-
⋮----
|
|
4337
|
-
export interface GetFundingRatesReq {
|
|
4338
|
-
settle: 'btc' | 'usdt' | 'usd';
|
|
4339
|
-
contract: string;
|
|
4340
|
-
limit?: number;
|
|
4341
|
-
from?: number;
|
|
4342
|
-
to?: number;
|
|
4343
|
-
}
|
|
4344
|
-
⋮----
|
|
4345
|
-
export interface GetLiquidationHistoryReq {
|
|
4346
|
-
settle: 'btc' | 'usdt' | 'usd';
|
|
4347
|
-
contract?: string;
|
|
4348
|
-
from?: number;
|
|
4349
|
-
to?: number;
|
|
4350
|
-
limit?: number;
|
|
4351
|
-
}
|
|
4352
|
-
⋮----
|
|
4353
|
-
export interface GetRiskLimitTiersReq {
|
|
4354
|
-
settle: 'btc' | 'usdt' | 'usd';
|
|
4355
|
-
contract: string;
|
|
4356
|
-
limit?: number;
|
|
4357
|
-
offset?: number;
|
|
4316
|
+
export interface GetRiskLimitTableReq {
|
|
4317
|
+
settle: 'btc' | 'usdt' | 'usd';
|
|
4318
|
+
table_id: string;
|
|
4358
4319
|
}
|
|
4359
4320
|
⋮----
|
|
4360
4321
|
export interface GetFuturesAccountBookReq {
|
|
@@ -4536,6 +4497,51 @@ size?: number; // The new order size, including the executed order size
|
|
|
4536
4497
|
price?: string; // New order price
|
|
4537
4498
|
amend_text?: string; // Custom info during amending order
|
|
4538
4499
|
|
|
4500
|
+
================
|
|
4501
|
+
File: .eslintrc.cjs
|
|
4502
|
+
================
|
|
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
|
+
|
|
4539
4545
|
================
|
|
4540
4546
|
File: src/types/response/unified.ts
|
|
4541
4547
|
================
|
|
@@ -5872,125 +5878,624 @@ export interface SpotHistoricTradeRecord {
|
|
|
5872
5878
|
}
|
|
5873
5879
|
|
|
5874
5880
|
================
|
|
5875
|
-
File: src/
|
|
5881
|
+
File: src/types/response/futures.ts
|
|
5876
5882
|
================
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
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
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
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
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
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;
|
|
5904
|
+
}
|
|
5935
5905
|
⋮----
|
|
5936
|
-
|
|
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;
|
|
5914
|
+
}
|
|
5937
5915
|
⋮----
|
|
5938
|
-
|
|
5916
|
+
export interface PremiumIndexKLine {
|
|
5917
|
+
t: number;
|
|
5918
|
+
c: string;
|
|
5919
|
+
h: string;
|
|
5920
|
+
l: string;
|
|
5921
|
+
o: string;
|
|
5922
|
+
}
|
|
5939
5923
|
⋮----
|
|
5940
|
-
|
|
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
|
+
}
|
|
5941
5949
|
⋮----
|
|
5942
|
-
|
|
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
|
+
}
|
|
5943
5965
|
⋮----
|
|
5944
|
-
export interface
|
|
5945
|
-
|
|
5946
|
-
|
|
5966
|
+
export interface IndexConstituents {
|
|
5967
|
+
index: string;
|
|
5968
|
+
constituents: {
|
|
5969
|
+
exchange: string;
|
|
5970
|
+
symbols: string[];
|
|
5971
|
+
}[];
|
|
5947
5972
|
}
|
|
5948
5973
|
⋮----
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
event: U,
|
|
5958
|
-
...args: Parameters<WSClientEventMap<TWSKey>[U]>
|
|
5959
|
-
): boolean;
|
|
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;
|
|
5960
5982
|
}
|
|
5961
5983
|
⋮----
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
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
|
+
}
|
|
5966
5992
|
⋮----
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
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
|
+
}
|
|
5971
6032
|
⋮----
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
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
|
+
}
|
|
5980
6043
|
⋮----
|
|
5981
|
-
|
|
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
|
+
}
|
|
5982
6081
|
⋮----
|
|
5983
|
-
|
|
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
|
+
}
|
|
5984
6119
|
⋮----
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
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
|
+
}
|
|
5990
6133
|
⋮----
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
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
|
+
*/
|
|
5994
6499
|
⋮----
|
|
5995
6500
|
/**
|
|
5996
6501
|
* State store to track a list of topics (topic requests) we are expected to be subscribed to if reconnected
|
|
@@ -6238,559 +6743,70 @@ private async onWsOpen(
|
|
|
6238
6743
|
⋮----
|
|
6239
6744
|
// Reconnect to topics known before it connected
|
|
6240
6745
|
⋮----
|
|
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
|
-
}
|
|
6331
|
-
⋮----
|
|
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
|
-
}
|
|
6746
|
+
// Request sub to public topics, if any
|
|
6341
6747
|
⋮----
|
|
6342
|
-
|
|
6343
|
-
t: number;
|
|
6344
|
-
c: string;
|
|
6345
|
-
h: string;
|
|
6346
|
-
l: string;
|
|
6347
|
-
o: string;
|
|
6348
|
-
}
|
|
6748
|
+
// Request sub to private topics, if auth on connect isn't needed
|
|
6349
6749
|
⋮----
|
|
6350
|
-
|
|
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
|
-
}
|
|
6750
|
+
// If enabled, automatically reauth WS API if reconnected
|
|
6375
6751
|
⋮----
|
|
6376
|
-
|
|
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
|
-
}
|
|
6752
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6391
6753
|
⋮----
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
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
|
+
)
|
|
6399
6763
|
⋮----
|
|
6400
|
-
|
|
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
|
-
}
|
|
6764
|
+
// Resolve & cleanup deferred "auth attempt in progress" promise
|
|
6409
6765
|
⋮----
|
|
6410
|
-
|
|
6411
|
-
tier: number;
|
|
6412
|
-
risk_limit: string;
|
|
6413
|
-
initial_rate: string;
|
|
6414
|
-
maintenance_rate: string;
|
|
6415
|
-
leverage_max: string;
|
|
6416
|
-
contract: string;
|
|
6417
|
-
}
|
|
6766
|
+
// Remove before continuing, in case there's more requests queued
|
|
6418
6767
|
⋮----
|
|
6419
|
-
|
|
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
|
-
}
|
|
6768
|
+
private onWsMessage(event: unknown, wsKey: TWSKey, ws: WebSocket)
|
|
6457
6769
|
⋮----
|
|
6458
|
-
|
|
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
|
-
}
|
|
6770
|
+
// any message can clear the pong timer - wouldn't get a message if the ws wasn't working
|
|
6468
6771
|
⋮----
|
|
6469
|
-
|
|
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
|
-
}
|
|
6772
|
+
// console.log(`raw event: `, { data, dataType, emittableEvents });
|
|
6506
6773
|
⋮----
|
|
6507
|
-
|
|
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
|
-
}
|
|
6774
|
+
private onWsClose(event: unknown, wsKey: TWSKey)
|
|
6544
6775
|
⋮----
|
|
6545
|
-
|
|
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
|
-
}
|
|
6776
|
+
// unintentional close, attempt recovery
|
|
6558
6777
|
⋮----
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
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
|
-
}
|
|
6778
|
+
// clean up any pending promises for this connection
|
|
6779
|
+
⋮----
|
|
6780
|
+
// intentional close - clean up
|
|
6781
|
+
// clean up any pending promises for this connection
|
|
6782
|
+
⋮----
|
|
6783
|
+
// clean up any pending promises for this connection
|
|
6574
6784
|
⋮----
|
|
6575
|
-
|
|
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
|
-
}
|
|
6785
|
+
// This was an intentional close, delete all state for this connection, as if it never existed:
|
|
6601
6786
|
⋮----
|
|
6602
|
-
|
|
6603
|
-
user_id: number;
|
|
6604
|
-
id: string;
|
|
6605
|
-
succeeded: boolean;
|
|
6606
|
-
message: string;
|
|
6607
|
-
}
|
|
6787
|
+
private getWs(wsKey: TWSKey)
|
|
6608
6788
|
⋮----
|
|
6609
|
-
|
|
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
|
-
}
|
|
6789
|
+
private setWsState(wsKey: TWSKey, state: WsConnectionStateEnum)
|
|
6647
6790
|
⋮----
|
|
6648
|
-
|
|
6649
|
-
|
|
6650
|
-
|
|
6651
|
-
|
|
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
|
-
}
|
|
6791
|
+
/**
|
|
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>
|
|
6685
6795
|
⋮----
|
|
6686
|
-
|
|
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
|
-
}
|
|
6796
|
+
// Already in progress? Await shared promise and retry
|
|
6726
6797
|
⋮----
|
|
6727
|
-
|
|
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
|
-
}
|
|
6798
|
+
// Start connection, it should automatically store/return a promise.
|
|
6763
6799
|
⋮----
|
|
6764
6800
|
/**
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
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
|
-
}
|
|
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
|
|
@@ -7073,32 +7089,66 @@ File: README.md
|
|
|
7073
7089
|
|
|
7074
7090
|
Updated & performant JavaScript & Node.js SDK for the Gate.com (gate.io) REST APIs and WebSockets:
|
|
7075
7091
|
|
|
7092
|
+
- Professional, robust & performant Gate.com SDK with extensive production use in live trading environments.
|
|
7076
7093
|
- Extensive integration with Gate.com (Gate.io) REST APIs and WebSockets.
|
|
7077
|
-
- TypeScript support (with type declarations for most API requests & responses).
|
|
7094
|
+
- Complete TypeScript support (with type declarations for most API requests & responses).
|
|
7095
|
+
- Strongly typed requests and responses.
|
|
7096
|
+
- Automated end-to-end tests ensuring reliability.
|
|
7097
|
+
- Actively maintained with a modern, promise-driven interface.
|
|
7078
7098
|
- Gate.com REST APIs for Gate.com Spot, Margin, Perpetual Futures, Delivery Futures, Options & Announcements APIs.
|
|
7099
|
+
- Unified RestClient for all Gate.com trading products.
|
|
7079
7100
|
- Strongly typed on most requests and responses.
|
|
7080
|
-
- Extremely robust & performant JavaScript/Node.js Gate.com SDK.
|
|
7081
|
-
- Actively maintained with a modern, promise-driven interface.
|
|
7082
7101
|
- Support for seamless API authentication for private Gate.com REST API and WebSocket calls.
|
|
7083
|
-
-
|
|
7102
|
+
- Robust WebSocket integration with configurable connection heartbeats & automatic reconnect then resubscribe workflows.
|
|
7084
7103
|
- Event driven messaging.
|
|
7085
|
-
- Smart websocket persistence
|
|
7104
|
+
- Smart websocket persistence with automatic reconnection handling.
|
|
7086
7105
|
- Automatically handle silent websocket disconnections through timed heartbeats, including the scheduled 24hr disconnect.
|
|
7087
7106
|
- Automatically handle listenKey persistence and expiration/refresh.
|
|
7088
7107
|
- Emit `reconnected` event when dropped connection is restored.
|
|
7089
|
-
-
|
|
7108
|
+
- Support for Gate.com Spot, Margin, Perpetual Futures, Delivery Futures & Options.
|
|
7109
|
+
- WebSocket API for Gate.com Spot, Margin, Perpetual Futures & Delivery Futures.
|
|
7090
7110
|
- Automatic connectivity via existing WebsocketClient, just call sendWSAPIRequest to trigger a request.
|
|
7091
7111
|
- Automatic authentication, just call sendWSAPIRequest with channel & parameters.
|
|
7092
7112
|
- Choose between two interfaces for WS API communication:
|
|
7093
7113
|
- Event-driven interface, fire & forget via sendWSAPIRequest and receive async replies via wsClient's event emitter.
|
|
7094
7114
|
- Promise-driven interface, simply use the WebsocketAPIClient for a REST-like experience. Use the WebSocket API like a REST API! See [examples/ws-api-client.ts](./examples/ws-api-client.ts) for a demonstration.
|
|
7115
|
+
- Heavy automated end-to-end testing with real API calls.
|
|
7095
7116
|
- Proxy support via axios integration.
|
|
7096
7117
|
- Active community support & collaboration in telegram: [Node.js Algo Traders](https://t.me/nodetraders).
|
|
7097
7118
|
|
|
7119
|
+
## Table of Contents
|
|
7120
|
+
|
|
7121
|
+
- [Installation](#installation)
|
|
7122
|
+
- [Examples](#examples)
|
|
7123
|
+
- [Issues & Discussion](#issues--discussion)
|
|
7124
|
+
- [Related Projects](#related-projects)
|
|
7125
|
+
- [Documentation](#documentation)
|
|
7126
|
+
- [Structure](#structure)
|
|
7127
|
+
- [Usage](#usage)
|
|
7128
|
+
- [REST API Client](#rest-api)
|
|
7129
|
+
- [WebSocket Client](#websockets)
|
|
7130
|
+
- [WebSocket Data Streams](#websocket-data-streams)
|
|
7131
|
+
- [WebSocket API](#websocket-api)
|
|
7132
|
+
- [Event Driven API](#event-driven-api)
|
|
7133
|
+
- [REST-like API](#rest-like-api)
|
|
7134
|
+
- [Customise Logging](#customise-logging)
|
|
7135
|
+
- [LLMs & AI](#use-with-llms--ai)
|
|
7136
|
+
- [Contributions & Thanks](#contributions--thanks)
|
|
7137
|
+
|
|
7098
7138
|
## Installation
|
|
7099
7139
|
|
|
7100
7140
|
`npm install --save gateio-api`
|
|
7101
7141
|
|
|
7142
|
+
## Examples
|
|
7143
|
+
|
|
7144
|
+
Refer to the [examples](./examples) folder for implementation demos, including:
|
|
7145
|
+
|
|
7146
|
+
- **REST API Examples**: spot trading, futures trading, account management
|
|
7147
|
+
- **WebSocket Examples**: public market data streams, private account data, WebSocket API usage
|
|
7148
|
+
- **Spot Trading**: comprehensive spot market examples
|
|
7149
|
+
- **Futures Trading**: perpetual and delivery futures examples
|
|
7150
|
+
- **WebSocket API**: both event-driven and promise-driven approaches
|
|
7151
|
+
|
|
7102
7152
|
## Issues & Discussion
|
|
7103
7153
|
|
|
7104
7154
|
- Issues? Check the [issues tab](https://github.com/tiagosiebler/gateio-api/issues).
|
|
@@ -7129,9 +7179,16 @@ Check out my related JavaScript/TypeScript/Node.js projects:
|
|
|
7129
7179
|
|
|
7130
7180
|
## Documentation
|
|
7131
7181
|
|
|
7132
|
-
Most methods accept JS objects. These can be populated using parameters specified by
|
|
7182
|
+
Most methods accept JS objects. These can be populated using parameters specified by Gate.com's API documentation, or check the type definition in each class within this repository.
|
|
7183
|
+
|
|
7184
|
+
### API Documentation Links
|
|
7133
7185
|
|
|
7134
7186
|
- [Gate.com/gate.io API Documentation](https://www.gate.com/docs/developers/apiv4/en/)
|
|
7187
|
+
- [Spot Trading API](https://www.gate.com/docs/developers/apiv4/en/#spot-new)
|
|
7188
|
+
- [Margin Trading API](https://www.gate.com/docs/developers/apiv4/en/#margin-new)
|
|
7189
|
+
- [Futures Trading API](https://www.gate.com/docs/developers/apiv4/en/#futures-new)
|
|
7190
|
+
- [Options Trading API](https://www.gate.com/docs/developers/apiv4/en/#options-new)
|
|
7191
|
+
- [WebSocket API](https://www.gate.com/docs/developers/apiv4/en/#websocket-api)
|
|
7135
7192
|
- [REST Endpoint Function List](./docs/endpointFunctionList.md)
|
|
7136
7193
|
- [TSDoc Documentation (autogenerated using typedoc)](https://tsdocs.dev/docs/gateio-api)
|
|
7137
7194
|
|
|
@@ -7146,11 +7203,13 @@ This project uses typescript. Resources are stored in 2 key structures:
|
|
|
7146
7203
|
|
|
7147
7204
|
# Usage
|
|
7148
7205
|
|
|
7149
|
-
Create API credentials
|
|
7206
|
+
Create API credentials on Gate.com's website:
|
|
7150
7207
|
|
|
7151
7208
|
- [Gate.com API Key Management](https://www.gate.com/myaccount/api_key_manage)
|
|
7152
7209
|
|
|
7153
|
-
|
|
7210
|
+
## REST API
|
|
7211
|
+
|
|
7212
|
+
The SDK provides a unified `RestClient` for all Gate.com trading products including Spot, Margin, Perpetual Futures, Delivery Futures, and Options. This single client handles all REST API operations across all trading markets.
|
|
7154
7213
|
|
|
7155
7214
|
To use any of Gate.com's REST APIs in JavaScript/TypeScript/Node.js, import (or require) the `RestClient`:
|
|
7156
7215
|
|
|
@@ -7191,6 +7250,19 @@ See [RestClient](./src/RestClient.ts) for further information, or the [examples]
|
|
|
7191
7250
|
|
|
7192
7251
|
## WebSockets
|
|
7193
7252
|
|
|
7253
|
+
All WebSocket functionality is supported via the unified `WebsocketClient`. This client handles all Gate.com WebSocket streams with automatic connection management and reconnection.
|
|
7254
|
+
|
|
7255
|
+
Key WebSocket features:
|
|
7256
|
+
|
|
7257
|
+
- Event driven messaging
|
|
7258
|
+
- Smart WebSocket persistence with automatic reconnection
|
|
7259
|
+
- Heartbeat mechanisms to detect disconnections
|
|
7260
|
+
- Automatic resubscription after reconnection
|
|
7261
|
+
- Support for all Gate.com trading products (Spot, Margin, Futures, Options)
|
|
7262
|
+
- WebSocket API support for real-time trading operations
|
|
7263
|
+
|
|
7264
|
+
### WebSocket Data Streams
|
|
7265
|
+
|
|
7194
7266
|
All available WebSockets can be used via a shared `WebsocketClient`. The WebSocket client will automatically open/track/manage connections as needed. Each unique connection (one per server URL) is tracked using a WsKey (each WsKey is a string - see [WS_KEY_MAP](src/lib/websocket/websocket-util.ts) for a list of supported values).
|
|
7195
7267
|
|
|
7196
7268
|
Any subscribe/unsubscribe events will need to include a WsKey, so the WebSocket client understands which connection the event should be routed to. See examples below or in the [examples](./examples/) folder on GitHub.
|
|
@@ -7428,6 +7500,12 @@ DefaultLogger.silly = () => {};
|
|
|
7428
7500
|
const ws = new WebsocketClient({ key: 'xxx', secret: 'yyy' }, DefaultLogger);
|
|
7429
7501
|
```
|
|
7430
7502
|
|
|
7503
|
+
## Use with LLMs & AI
|
|
7504
|
+
|
|
7505
|
+
This SDK includes a bundled `llms.txt` file in the root of the repository. If you're developing with LLMs, use the included `llms.txt` with your LLM - it will significantly improve the LLMs understanding of how to correctly use this SDK.
|
|
7506
|
+
|
|
7507
|
+
This file contains AI optimised structure of all the functions in this package, and their parameters for easier use with any learning models or artificial intelligence.
|
|
7508
|
+
|
|
7431
7509
|
---
|
|
7432
7510
|
|
|
7433
7511
|
<!-- template_contributions -->
|
|
@@ -7825,6 +7903,7 @@ import {
|
|
|
7825
7903
|
GetFuturesTradingHistoryByTimeRangeReq,
|
|
7826
7904
|
GetFuturesTradingHistoryReq,
|
|
7827
7905
|
GetLiquidationHistoryReq,
|
|
7906
|
+
GetRiskLimitTableReq,
|
|
7828
7907
|
GetRiskLimitTiersReq,
|
|
7829
7908
|
SubmitFuturesOrderReq,
|
|
7830
7909
|
SubmitFuturesTriggeredOrderReq,
|
|
@@ -7980,6 +8059,7 @@ import {
|
|
|
7980
8059
|
IndexConstituents,
|
|
7981
8060
|
LiquidationHistoryRecord,
|
|
7982
8061
|
PremiumIndexKLine,
|
|
8062
|
+
RiskLimitTableTier,
|
|
7983
8063
|
RiskLimitTier,
|
|
7984
8064
|
} from './types/response/futures.js';
|
|
7985
8065
|
import {
|
|
@@ -9134,6 +9214,20 @@ cancelSpotTriggeredOrder(params: {
|
|
|
9134
9214
|
order_id: string;
|
|
9135
9215
|
}): Promise<SpotPriceTriggeredOrder>
|
|
9136
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
|
+
⋮----
|
|
9137
9231
|
/**==========================================================================================================================
|
|
9138
9232
|
* MARGIN
|
|
9139
9233
|
* ==========================================================================================================================
|
|
@@ -10102,6 +10196,16 @@ batchUpdateFuturesOrders(params: {
|
|
|
10102
10196
|
orders: BatchAmendOrderReq[];
|
|
10103
10197
|
}): Promise<BatchAmendOrderResp[]>
|
|
10104
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
|
+
⋮----
|
|
10105
10209
|
/**
|
|
10106
10210
|
* Create a price-triggered order
|
|
10107
10211
|
*
|
|
@@ -11412,7 +11516,7 @@ File: package.json
|
|
|
11412
11516
|
================
|
|
11413
11517
|
{
|
|
11414
11518
|
"name": "gateio-api",
|
|
11415
|
-
"version": "1.2.
|
|
11519
|
+
"version": "1.2.6",
|
|
11416
11520
|
"description": "Complete & Robust Node.js SDK for Gate.com's REST APIs, WebSockets & WebSocket APIs, with TypeScript declarations.",
|
|
11417
11521
|
"scripts": {
|
|
11418
11522
|
"clean": "rm -rf dist/*",
|
|
@@ -11432,7 +11536,8 @@ File: package.json
|
|
|
11432
11536
|
},
|
|
11433
11537
|
"type": "module",
|
|
11434
11538
|
"files": [
|
|
11435
|
-
"dist/*"
|
|
11539
|
+
"dist/*",
|
|
11540
|
+
"llms.txt"
|
|
11436
11541
|
],
|
|
11437
11542
|
"author": "Tiago Siebler (https://github.com/tiagosiebler)",
|
|
11438
11543
|
"contributors": [
|