bitget-api 3.1.4 → 3.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/rest-client-v3.d.ts +61 -4
- package/dist/cjs/rest-client-v3.js +83 -0
- package/dist/cjs/rest-client-v3.js.map +1 -1
- package/dist/cjs/types/request/v3/account.d.ts +4 -0
- package/dist/cjs/types/request/v3/loan.d.ts +72 -0
- package/dist/cjs/types/request/v3/public.d.ts +7 -0
- package/dist/cjs/types/response/v3/loan.d.ts +120 -0
- package/dist/cjs/types/response/v3/public.d.ts +25 -1
- package/dist/cjs/websocket-client-v3.js +5 -0
- package/dist/cjs/websocket-client-v3.js.map +1 -1
- package/dist/mjs/rest-client-v3.d.ts +61 -4
- package/dist/mjs/rest-client-v3.js +83 -0
- package/dist/mjs/rest-client-v3.js.map +1 -1
- package/dist/mjs/types/request/v3/account.d.ts +4 -0
- package/dist/mjs/types/request/v3/loan.d.ts +72 -0
- package/dist/mjs/types/request/v3/public.d.ts +7 -0
- package/dist/mjs/types/response/v3/loan.d.ts +120 -0
- package/dist/mjs/types/response/v3/public.d.ts +25 -1
- package/dist/mjs/websocket-client-v3.js +5 -0
- package/dist/mjs/websocket-client-v3.js.map +1 -1
- package/llms.txt +1568 -1184
- package/package.json +1 -1
package/llms.txt
CHANGED
|
@@ -141,7 +141,6 @@ LICENSE.md
|
|
|
141
141
|
package.json
|
|
142
142
|
postBuild.sh
|
|
143
143
|
README.md
|
|
144
|
-
tea.yaml
|
|
145
144
|
tsconfig.cjs.json
|
|
146
145
|
tsconfig.esm.json
|
|
147
146
|
tsconfig.json
|
|
@@ -1462,6 +1461,90 @@ export interface BindUidRequestV3 {
|
|
|
1462
1461
|
export interface GetLTVConvertRequestV3 {
|
|
1463
1462
|
riskUnitId?: string;
|
|
1464
1463
|
}
|
|
1464
|
+
⋮----
|
|
1465
|
+
/* Unified Account Staking & Lending (Crypto Loans) - /api/v3/loan/* */
|
|
1466
|
+
⋮----
|
|
1467
|
+
export interface GetLoanCoinsRequestV3 {
|
|
1468
|
+
coin?: string;
|
|
1469
|
+
}
|
|
1470
|
+
⋮----
|
|
1471
|
+
export interface GetLoanInterestRequestV3 {
|
|
1472
|
+
loanCoin: string;
|
|
1473
|
+
pledgeCoin: string;
|
|
1474
|
+
daily: 'SEVEN' | 'THIRTY' | 'FLEXIBLE';
|
|
1475
|
+
pledgeAmount: string;
|
|
1476
|
+
}
|
|
1477
|
+
⋮----
|
|
1478
|
+
export interface LoanBorrowRequestV3 {
|
|
1479
|
+
loanCoin: string;
|
|
1480
|
+
pledgeCoin: string;
|
|
1481
|
+
daily: 'SEVEN' | 'THIRTY' | 'FLEXIBLE';
|
|
1482
|
+
pledgeAmount?: string;
|
|
1483
|
+
loanAmount?: string;
|
|
1484
|
+
}
|
|
1485
|
+
⋮----
|
|
1486
|
+
export interface GetLoanBorrowOngoingRequestV3 {
|
|
1487
|
+
orderId?: string;
|
|
1488
|
+
loanCoin?: string;
|
|
1489
|
+
pledgeCoin?: string;
|
|
1490
|
+
}
|
|
1491
|
+
⋮----
|
|
1492
|
+
export interface GetLoanBorrowHistoryRequestV3 {
|
|
1493
|
+
orderId?: string;
|
|
1494
|
+
loanCoin?: string;
|
|
1495
|
+
pledgeCoin?: string;
|
|
1496
|
+
status?: 'ROLLBACK' | 'FORCE' | 'REPAY';
|
|
1497
|
+
startTime: string;
|
|
1498
|
+
endTime: string;
|
|
1499
|
+
pageNum?: string;
|
|
1500
|
+
pageSize?: string;
|
|
1501
|
+
}
|
|
1502
|
+
⋮----
|
|
1503
|
+
export interface LoanRepayRequestV3 {
|
|
1504
|
+
orderId: string;
|
|
1505
|
+
method: 'borrowed_coin' | 'collateral';
|
|
1506
|
+
repayAll: 'yes' | 'no';
|
|
1507
|
+
amount?: string;
|
|
1508
|
+
repayUnlock?: 'yes' | 'no';
|
|
1509
|
+
}
|
|
1510
|
+
⋮----
|
|
1511
|
+
export interface GetLoanRepayHistoryRequestV3 {
|
|
1512
|
+
orderId?: string;
|
|
1513
|
+
loanCoin?: string;
|
|
1514
|
+
pledgeCoin?: string;
|
|
1515
|
+
startTime: string;
|
|
1516
|
+
endTime: string;
|
|
1517
|
+
pageNum?: string;
|
|
1518
|
+
pageSize?: string;
|
|
1519
|
+
}
|
|
1520
|
+
⋮----
|
|
1521
|
+
export interface LoanRevisePledgeRequestV3 {
|
|
1522
|
+
orderId: string;
|
|
1523
|
+
amount: string;
|
|
1524
|
+
pledgeCoin: string;
|
|
1525
|
+
reviseType?: 'OUT' | 'IN';
|
|
1526
|
+
}
|
|
1527
|
+
⋮----
|
|
1528
|
+
export interface GetLoanPledgeRateHistoryRequestV3 {
|
|
1529
|
+
orderId?: string;
|
|
1530
|
+
reviseSide?: 'down' | 'up';
|
|
1531
|
+
pledgeCoin?: string;
|
|
1532
|
+
startTime: string;
|
|
1533
|
+
endTime: string;
|
|
1534
|
+
pageNum?: string;
|
|
1535
|
+
pageSize?: string;
|
|
1536
|
+
}
|
|
1537
|
+
⋮----
|
|
1538
|
+
export interface GetLoanReducesRequestV3 {
|
|
1539
|
+
orderId?: string;
|
|
1540
|
+
loanCoin?: string;
|
|
1541
|
+
pledgeCoin?: string;
|
|
1542
|
+
status?: 'COMPLETE' | 'WAIT';
|
|
1543
|
+
startTime: string;
|
|
1544
|
+
endTime: string;
|
|
1545
|
+
pageNum?: string;
|
|
1546
|
+
pageSize?: string;
|
|
1547
|
+
}
|
|
1465
1548
|
|
|
1466
1549
|
================
|
|
1467
1550
|
File: src/types/request/v3/strategy.ts
|
|
@@ -4379,6 +4462,8 @@ protected resolveEmittableEvents(
|
|
|
4379
4462
|
// messageType: typeof msg,
|
|
4380
4463
|
// messageString: JSON.stringify(msg),
|
|
4381
4464
|
⋮----
|
|
4465
|
+
// Service upgrade (30033): Bitget sends this ~60s before disconnect. Proactively close to trigger reconnect.
|
|
4466
|
+
⋮----
|
|
4382
4467
|
// messageType: typeof msg,
|
|
4383
4468
|
// messageString: JSON.stringify(msg),
|
|
4384
4469
|
⋮----
|
|
@@ -4422,6 +4507,11 @@ async sendWSAPIRequest<
|
|
|
4422
4507
|
⋮----
|
|
4423
4508
|
// Return deferred promise, so caller can await this call
|
|
4424
4509
|
|
|
4510
|
+
================
|
|
4511
|
+
File: .eslintrc.cjs
|
|
4512
|
+
================
|
|
4513
|
+
// 'no-unused-vars': ['warn'],
|
|
4514
|
+
|
|
4425
4515
|
================
|
|
4426
4516
|
File: .jshintrc
|
|
4427
4517
|
================
|
|
@@ -4446,6 +4536,194 @@ File: .prettierrc
|
|
|
4446
4536
|
"trailingComma": "all"
|
|
4447
4537
|
}
|
|
4448
4538
|
|
|
4539
|
+
================
|
|
4540
|
+
File: jest.config.ts
|
|
4541
|
+
================
|
|
4542
|
+
/**
|
|
4543
|
+
* For a detailed explanation regarding each configuration property, visit:
|
|
4544
|
+
* https://jestjs.io/docs/configuration
|
|
4545
|
+
*/
|
|
4546
|
+
⋮----
|
|
4547
|
+
import type { Config } from 'jest';
|
|
4548
|
+
⋮----
|
|
4549
|
+
// All imported modules in your tests should be mocked automatically
|
|
4550
|
+
// automock: false,
|
|
4551
|
+
⋮----
|
|
4552
|
+
// Stop running tests after `n` failures
|
|
4553
|
+
// bail: 0,
|
|
4554
|
+
bail: false, // enable to stop test when an error occur,
|
|
4555
|
+
⋮----
|
|
4556
|
+
// The directory where Jest should store its cached dependency information
|
|
4557
|
+
// cacheDirectory: "/private/var/folders/kf/2k3sz4px6c9cbyzj1h_b192h0000gn/T/jest_dx",
|
|
4558
|
+
⋮----
|
|
4559
|
+
// Automatically clear mock calls, instances, contexts and results before every test
|
|
4560
|
+
⋮----
|
|
4561
|
+
// Indicates whether the coverage information should be collected while executing the test
|
|
4562
|
+
⋮----
|
|
4563
|
+
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
4564
|
+
⋮----
|
|
4565
|
+
// The directory where Jest should output its coverage files
|
|
4566
|
+
⋮----
|
|
4567
|
+
// An array of regexp pattern strings used to skip coverage collection
|
|
4568
|
+
// coveragePathIgnorePatterns: [
|
|
4569
|
+
// "/node_modules/"
|
|
4570
|
+
// ],
|
|
4571
|
+
⋮----
|
|
4572
|
+
// Indicates which provider should be used to instrument code for coverage
|
|
4573
|
+
⋮----
|
|
4574
|
+
// A list of reporter names that Jest uses when writing coverage reports
|
|
4575
|
+
// coverageReporters: [
|
|
4576
|
+
// "json",
|
|
4577
|
+
// "text",
|
|
4578
|
+
// "lcov",
|
|
4579
|
+
// "clover"
|
|
4580
|
+
// ],
|
|
4581
|
+
⋮----
|
|
4582
|
+
// An object that configures minimum threshold enforcement for coverage results
|
|
4583
|
+
// coverageThreshold: undefined,
|
|
4584
|
+
⋮----
|
|
4585
|
+
// A path to a custom dependency extractor
|
|
4586
|
+
// dependencyExtractor: undefined,
|
|
4587
|
+
⋮----
|
|
4588
|
+
// Make calling deprecated APIs throw helpful error messages
|
|
4589
|
+
// errorOnDeprecated: false,
|
|
4590
|
+
⋮----
|
|
4591
|
+
// The default configuration for fake timers
|
|
4592
|
+
// fakeTimers: {
|
|
4593
|
+
// "enableGlobally": false
|
|
4594
|
+
// },
|
|
4595
|
+
⋮----
|
|
4596
|
+
// Force coverage collection from ignored files using an array of glob patterns
|
|
4597
|
+
// forceCoverageMatch: [],
|
|
4598
|
+
⋮----
|
|
4599
|
+
// A path to a module which exports an async function that is triggered once before all test suites
|
|
4600
|
+
// globalSetup: undefined,
|
|
4601
|
+
⋮----
|
|
4602
|
+
// A path to a module which exports an async function that is triggered once after all test suites
|
|
4603
|
+
// globalTeardown: undefined,
|
|
4604
|
+
⋮----
|
|
4605
|
+
// A set of global variables that need to be available in all test environments
|
|
4606
|
+
// globals: {},
|
|
4607
|
+
⋮----
|
|
4608
|
+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
4609
|
+
// maxWorkers: "50%",
|
|
4610
|
+
⋮----
|
|
4611
|
+
// An array of directory names to be searched recursively up from the requiring module's location
|
|
4612
|
+
// moduleDirectories: [
|
|
4613
|
+
// "node_modules"
|
|
4614
|
+
// ],
|
|
4615
|
+
⋮----
|
|
4616
|
+
// An array of file extensions your modules use
|
|
4617
|
+
⋮----
|
|
4618
|
+
// modulePaths: ['src'],
|
|
4619
|
+
⋮----
|
|
4620
|
+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
4621
|
+
// moduleNameMapper: {},
|
|
4622
|
+
⋮----
|
|
4623
|
+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
4624
|
+
// modulePathIgnorePatterns: [],
|
|
4625
|
+
⋮----
|
|
4626
|
+
// Activates notifications for test results
|
|
4627
|
+
// notify: false,
|
|
4628
|
+
⋮----
|
|
4629
|
+
// An enum that specifies notification mode. Requires { notify: true }
|
|
4630
|
+
// notifyMode: "failure-change",
|
|
4631
|
+
⋮----
|
|
4632
|
+
// A preset that is used as a base for Jest's configuration
|
|
4633
|
+
// preset: undefined,
|
|
4634
|
+
⋮----
|
|
4635
|
+
// Run tests from one or more projects
|
|
4636
|
+
// projects: undefined,
|
|
4637
|
+
⋮----
|
|
4638
|
+
// Use this configuration option to add custom reporters to Jest
|
|
4639
|
+
// reporters: undefined,
|
|
4640
|
+
⋮----
|
|
4641
|
+
// Automatically reset mock state before every test
|
|
4642
|
+
// resetMocks: false,
|
|
4643
|
+
⋮----
|
|
4644
|
+
// Reset the module registry before running each individual test
|
|
4645
|
+
// resetModules: false,
|
|
4646
|
+
⋮----
|
|
4647
|
+
// A path to a custom resolver
|
|
4648
|
+
// resolver: undefined,
|
|
4649
|
+
⋮----
|
|
4650
|
+
// Automatically restore mock state and implementation before every test
|
|
4651
|
+
// restoreMocks: false,
|
|
4652
|
+
⋮----
|
|
4653
|
+
// The root directory that Jest should scan for tests and modules within
|
|
4654
|
+
// rootDir: undefined,
|
|
4655
|
+
⋮----
|
|
4656
|
+
// A list of paths to directories that Jest should use to search for files in
|
|
4657
|
+
// roots: [
|
|
4658
|
+
// "<rootDir>"
|
|
4659
|
+
// ],
|
|
4660
|
+
⋮----
|
|
4661
|
+
// Allows you to use a custom runner instead of Jest's default test runner
|
|
4662
|
+
// runner: "jest-runner",
|
|
4663
|
+
⋮----
|
|
4664
|
+
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
4665
|
+
// setupFiles: [],
|
|
4666
|
+
⋮----
|
|
4667
|
+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
4668
|
+
// setupFilesAfterEnv: [],
|
|
4669
|
+
⋮----
|
|
4670
|
+
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
4671
|
+
// slowTestThreshold: 5,
|
|
4672
|
+
⋮----
|
|
4673
|
+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
4674
|
+
// snapshotSerializers: [],
|
|
4675
|
+
⋮----
|
|
4676
|
+
// The test environment that will be used for testing
|
|
4677
|
+
// testEnvironment: "jest-environment-node",
|
|
4678
|
+
⋮----
|
|
4679
|
+
// Options that will be passed to the testEnvironment
|
|
4680
|
+
// testEnvironmentOptions: {},
|
|
4681
|
+
⋮----
|
|
4682
|
+
// Adds a location field to test results
|
|
4683
|
+
// testLocationInResults: false,
|
|
4684
|
+
⋮----
|
|
4685
|
+
// The glob patterns Jest uses to detect test files
|
|
4686
|
+
⋮----
|
|
4687
|
+
// "**/__tests__/**/*.[jt]s?(x)",
|
|
4688
|
+
⋮----
|
|
4689
|
+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
4690
|
+
// testPathIgnorePatterns: [
|
|
4691
|
+
// "/node_modules/"
|
|
4692
|
+
// ],
|
|
4693
|
+
⋮----
|
|
4694
|
+
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
4695
|
+
// testRegex: [],
|
|
4696
|
+
⋮----
|
|
4697
|
+
// This option allows the use of a custom results processor
|
|
4698
|
+
// testResultsProcessor: undefined,
|
|
4699
|
+
⋮----
|
|
4700
|
+
// This option allows use of a custom test runner
|
|
4701
|
+
// testRunner: "jest-circus/runner",
|
|
4702
|
+
⋮----
|
|
4703
|
+
// A map from regular expressions to paths to transformers
|
|
4704
|
+
// transform: undefined,
|
|
4705
|
+
⋮----
|
|
4706
|
+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
4707
|
+
// transformIgnorePatterns: [
|
|
4708
|
+
// "/node_modules/",
|
|
4709
|
+
// "\\.pnp\\.[^\\/]+$"
|
|
4710
|
+
// ],
|
|
4711
|
+
⋮----
|
|
4712
|
+
// Prevents import esm module error from v1 axios release, issue #5026
|
|
4713
|
+
⋮----
|
|
4714
|
+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
4715
|
+
// unmockedModulePathPatterns: undefined,
|
|
4716
|
+
⋮----
|
|
4717
|
+
// Indicates whether each individual test should be reported during the run
|
|
4718
|
+
// verbose: undefined,
|
|
4719
|
+
verbose: true, // report individual test
|
|
4720
|
+
⋮----
|
|
4721
|
+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
4722
|
+
// watchPathIgnorePatterns: [],
|
|
4723
|
+
⋮----
|
|
4724
|
+
// Whether to use watchman for file crawling
|
|
4725
|
+
// watchman: true,
|
|
4726
|
+
|
|
4449
4727
|
================
|
|
4450
4728
|
File: LICENSE.md
|
|
4451
4729
|
================
|
|
@@ -4593,248 +4871,7 @@ import { RestClientV2 } from '../../../src/index.js';
|
|
|
4593
4871
|
// import { RestClientV2 } from 'bitget-api';
|
|
4594
4872
|
|
|
4595
4873
|
================
|
|
4596
|
-
File: examples/
|
|
4597
|
-
================
|
|
4598
|
-
import {
|
|
4599
|
-
FuturesPlaceOrderRequestV2,
|
|
4600
|
-
RestClientV2,
|
|
4601
|
-
WebsocketClientV2,
|
|
4602
|
-
} from '../../../src/index.js';
|
|
4603
|
-
⋮----
|
|
4604
|
-
// or
|
|
4605
|
-
// import { FuturesPlaceOrderRequestV2, RestClientV2, WebsocketClientV2 } from '../src';
|
|
4606
|
-
⋮----
|
|
4607
|
-
// read from environmental variables
|
|
4608
|
-
⋮----
|
|
4609
|
-
// If running from CLI in unix, you can pass env vars as such:
|
|
4610
|
-
// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/rest-trade-futures.ts
|
|
4611
|
-
⋮----
|
|
4612
|
-
// note the single quotes, preventing special characters such as $ from being incorrectly passed
|
|
4613
|
-
⋮----
|
|
4614
|
-
// apiKey: 'apiKeyHere',
|
|
4615
|
-
// apiSecret: 'apiSecretHere',
|
|
4616
|
-
// apiPass: 'apiPassHere',
|
|
4617
|
-
⋮----
|
|
4618
|
-
function logWSEvent(type: string, data: any)
|
|
4619
|
-
⋮----
|
|
4620
|
-
// simple sleep function
|
|
4621
|
-
function promiseSleep(milliseconds: number)
|
|
4622
|
-
⋮----
|
|
4623
|
-
/**
|
|
4624
|
-
* This is a simple script wrapped in a immediately invoked function expression (to execute the below workflow immediately).
|
|
4625
|
-
*
|
|
4626
|
-
* It is designed to:
|
|
4627
|
-
* - open a private websocket channel to log account events
|
|
4628
|
-
* - check for any available USDT balance in the futures account
|
|
4629
|
-
* - immediately open a minimum sized long position on BTCUSDT
|
|
4630
|
-
* - check active positions
|
|
4631
|
-
* - immediately send closing orders for any active futures positions
|
|
4632
|
-
* - check positions again
|
|
4633
|
-
*
|
|
4634
|
-
*/
|
|
4635
|
-
⋮----
|
|
4636
|
-
// Add event listeners to log websocket events on account
|
|
4637
|
-
⋮----
|
|
4638
|
-
// futures private
|
|
4639
|
-
// : account updates
|
|
4640
|
-
⋮----
|
|
4641
|
-
// : position updates
|
|
4642
|
-
⋮----
|
|
4643
|
-
// : order updates
|
|
4644
|
-
⋮----
|
|
4645
|
-
// wait briefly for ws to be ready (could also use the response or authenticated events, to make sure topics are subscribed to before starting)
|
|
4646
|
-
⋮----
|
|
4647
|
-
// const balances = allBalances.filter((bal) => Number(bal.available) != 0);
|
|
4648
|
-
⋮----
|
|
4649
|
-
// Loop through any active positions and send a closing market order on each position
|
|
4650
|
-
|
|
4651
|
-
================
|
|
4652
|
-
File: examples/V2 - Classic/Rest/rest-trade-spot.ts
|
|
4653
|
-
================
|
|
4654
|
-
import {
|
|
4655
|
-
RestClientV2,
|
|
4656
|
-
SpotOrderRequestV2,
|
|
4657
|
-
WebsocketClientV2,
|
|
4658
|
-
} from '../../../src/index.js';
|
|
4659
|
-
⋮----
|
|
4660
|
-
// import { RestClientV2, WebsocketClient } from '../src/index';
|
|
4661
|
-
⋮----
|
|
4662
|
-
// read from environmental variables
|
|
4663
|
-
⋮----
|
|
4664
|
-
// If running from CLI in unix, you can pass env vars as such:
|
|
4665
|
-
// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/rest-trade-spot.ts
|
|
4666
|
-
⋮----
|
|
4667
|
-
// note the single quotes, preventing special characters such as $ from being incorrectly passed
|
|
4668
|
-
⋮----
|
|
4669
|
-
// apiKey: 'apiKeyHere',
|
|
4670
|
-
// apiSecret: 'apiSecretHere',
|
|
4671
|
-
// apiPass: 'apiPassHere',
|
|
4672
|
-
⋮----
|
|
4673
|
-
function logWSEvent(type: string, data: any)
|
|
4674
|
-
⋮----
|
|
4675
|
-
// simple sleep function
|
|
4676
|
-
function promiseSleep(milliseconds: number)
|
|
4677
|
-
⋮----
|
|
4678
|
-
/** This is a simple script wrapped in a immediately invoked function expression, designed to check for any available BTC balance and immediately sell the full amount for USDT */
|
|
4679
|
-
⋮----
|
|
4680
|
-
// Add event listeners to log websocket events on account
|
|
4681
|
-
⋮----
|
|
4682
|
-
// Subscribe to private account topics
|
|
4683
|
-
// spot private
|
|
4684
|
-
// : account updates
|
|
4685
|
-
⋮----
|
|
4686
|
-
// : order updates (note: symbol is required)
|
|
4687
|
-
⋮----
|
|
4688
|
-
// wait briefly for ws to be ready (could also use the response or authenticated events, to make sure topics are subscribed to before starting)
|
|
4689
|
-
⋮----
|
|
4690
|
-
// console.log('balance: ', JSON.stringify(balances, null, 2));
|
|
4691
|
-
|
|
4692
|
-
================
|
|
4693
|
-
File: examples/V2 - Classic/Websocket/ws-demo-trading.ts
|
|
4694
|
-
================
|
|
4695
|
-
import { DefaultLogger, WebsocketClientV2 } from '../../../src/index.js';
|
|
4696
|
-
⋮----
|
|
4697
|
-
// or
|
|
4698
|
-
// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api';
|
|
4699
|
-
⋮----
|
|
4700
|
-
// If running from CLI in unix, you can pass env vars as such:
|
|
4701
|
-
// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts
|
|
4702
|
-
⋮----
|
|
4703
|
-
// restOptions: {
|
|
4704
|
-
// optionally provide rest options, e.g. to pass through a proxy
|
|
4705
|
-
// },
|
|
4706
|
-
⋮----
|
|
4707
|
-
// Set demoTrading to true, to route all connections to the demo trading wss URLs:
|
|
4708
|
-
⋮----
|
|
4709
|
-
// If using private topics, make sure to include API keys
|
|
4710
|
-
⋮----
|
|
4711
|
-
// console.log('WS raw message received ', JSON.stringify(data, null, 2));
|
|
4712
|
-
⋮----
|
|
4713
|
-
/**
|
|
4714
|
-
* Public events
|
|
4715
|
-
*/
|
|
4716
|
-
|
|
4717
|
-
================
|
|
4718
|
-
File: examples/V2 - Classic/Websocket/ws-private.ts
|
|
4719
|
-
================
|
|
4720
|
-
import { DefaultLogger, WebsocketClientV2 } from '../../../src/index.js';
|
|
4721
|
-
⋮----
|
|
4722
|
-
// or
|
|
4723
|
-
// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api';
|
|
4724
|
-
⋮----
|
|
4725
|
-
// If running from CLI in unix, you can pass env vars as such:
|
|
4726
|
-
// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts
|
|
4727
|
-
⋮----
|
|
4728
|
-
// note the single quotes, preventing special characters such as $ from being incorrectly passed
|
|
4729
|
-
⋮----
|
|
4730
|
-
// restOptions: {
|
|
4731
|
-
// optionally provide rest options, e.g. to pass through a proxy
|
|
4732
|
-
// },
|
|
4733
|
-
⋮----
|
|
4734
|
-
// console.log('WS raw message received ', JSON.stringify(data, null, 2));
|
|
4735
|
-
⋮----
|
|
4736
|
-
// auth happens async after the ws connection opens
|
|
4737
|
-
⋮----
|
|
4738
|
-
// wsClient.subscribePublicSpotTickers(['BTCUSDT', 'LTCUSDT']);
|
|
4739
|
-
⋮----
|
|
4740
|
-
/**
|
|
4741
|
-
* Private account updates
|
|
4742
|
-
*/
|
|
4743
|
-
⋮----
|
|
4744
|
-
// spot private
|
|
4745
|
-
// : account updates
|
|
4746
|
-
⋮----
|
|
4747
|
-
// : order updates (note: symbol is required)
|
|
4748
|
-
// wsClient.subscribeTopic('SPOT', 'orders', 'BTCUSDT');
|
|
4749
|
-
⋮----
|
|
4750
|
-
// futures private
|
|
4751
|
-
// : account updates
|
|
4752
|
-
⋮----
|
|
4753
|
-
// : position updates
|
|
4754
|
-
// wsClient.subscribeTopic('USDT-FUTURES', 'positions');
|
|
4755
|
-
⋮----
|
|
4756
|
-
// : order updates
|
|
4757
|
-
// wsClient.subscribeTopic('USDT-FUTURES', 'orders');
|
|
4758
|
-
⋮----
|
|
4759
|
-
// : plan order updates
|
|
4760
|
-
// wsClient.subscribeTopic('USDT-FUTURES', 'orders-algo');
|
|
4761
|
-
⋮----
|
|
4762
|
-
// wsClient
|
|
4763
|
-
// .getWsStore()
|
|
4764
|
-
// .getKeys()
|
|
4765
|
-
// .forEach((wsKey) => {
|
|
4766
|
-
// const state = wsClient.getWsStore().get(wsKey);
|
|
4767
|
-
// console.log(`${wsKey} state: `, state.subscribedTopics.values());
|
|
4768
|
-
// });
|
|
4769
|
-
⋮----
|
|
4770
|
-
// setTimeout(() => {
|
|
4771
|
-
// wsClient.unsubscribeTopic('USDT-FUTURES', 'account');
|
|
4772
|
-
// }, 1000 * 2);
|
|
4773
|
-
⋮----
|
|
4774
|
-
// setTimeout(() => {
|
|
4775
|
-
// wsClient
|
|
4776
|
-
// .getWsStore()
|
|
4777
|
-
// .getKeys()
|
|
4778
|
-
// .forEach((wsKey) => {
|
|
4779
|
-
// const state = wsClient.getWsStore().get(wsKey);
|
|
4780
|
-
// console.log(`${wsKey} state: `, state.subscribedTopics.values());
|
|
4781
|
-
// });
|
|
4782
|
-
// }, 1000 * 5);
|
|
4783
|
-
|
|
4784
|
-
================
|
|
4785
|
-
File: examples/V2 - Classic/Websocket/ws-public.ts
|
|
4786
|
-
================
|
|
4787
|
-
import {
|
|
4788
|
-
DefaultLogger,
|
|
4789
|
-
WebsocketClientV2,
|
|
4790
|
-
WS_KEY_MAP,
|
|
4791
|
-
} from '../../../src/index.js';
|
|
4792
|
-
⋮----
|
|
4793
|
-
// or
|
|
4794
|
-
// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api';
|
|
4795
|
-
⋮----
|
|
4796
|
-
// restOptions: {
|
|
4797
|
-
// optionally provide rest options, e.g. to pass through a proxy
|
|
4798
|
-
// },
|
|
4799
|
-
⋮----
|
|
4800
|
-
// console.log('WS raw message received ', JSON.stringify(data, null, 2));
|
|
4801
|
-
⋮----
|
|
4802
|
-
/**
|
|
4803
|
-
* Public events
|
|
4804
|
-
*/
|
|
4805
|
-
⋮----
|
|
4806
|
-
// Spot public
|
|
4807
|
-
⋮----
|
|
4808
|
-
// tickers
|
|
4809
|
-
⋮----
|
|
4810
|
-
// candles
|
|
4811
|
-
// wsClient.subscribeTopic('SPOT', 'candle1m', symbol);
|
|
4812
|
-
⋮----
|
|
4813
|
-
// orderbook updates
|
|
4814
|
-
// wsClient.subscribeTopic('SPOT', 'books', symbol);
|
|
4815
|
-
⋮----
|
|
4816
|
-
// trades
|
|
4817
|
-
// wsClient.subscribeTopic('SPOT', 'trade', symbol);
|
|
4818
|
-
⋮----
|
|
4819
|
-
// Futures public
|
|
4820
|
-
⋮----
|
|
4821
|
-
// tickers
|
|
4822
|
-
// wsClient.subscribeTopic('USDT-FUTURES', 'ticker', symbol);
|
|
4823
|
-
⋮----
|
|
4824
|
-
// candles
|
|
4825
|
-
// wsClient.subscribeTopic('USDT-FUTURES', 'candle1m', symbol);
|
|
4826
|
-
⋮----
|
|
4827
|
-
// orderbook updates
|
|
4828
|
-
// wsClient.subscribeTopic('USDT-FUTURES', 'books', symbol);
|
|
4829
|
-
⋮----
|
|
4830
|
-
// trades
|
|
4831
|
-
// wsClient.subscribeTopic('USDT-FUTURES', 'trade', symbol);
|
|
4832
|
-
⋮----
|
|
4833
|
-
// Topics are tracked per websocket type
|
|
4834
|
-
// Get a list of subscribed topics (e.g. all public topics) (after a 5 second delay)
|
|
4835
|
-
|
|
4836
|
-
================
|
|
4837
|
-
File: examples/V3 - UTA/Rest/rest-private.ts
|
|
4874
|
+
File: examples/V3 - UTA/Rest/rest-private.ts
|
|
4838
4875
|
================
|
|
4839
4876
|
import { RestClientV3 } from '../../../src/index.js';
|
|
4840
4877
|
⋮----
|
|
@@ -4871,1157 +4908,1175 @@ import { RestClientV3 } from '../../../src/index.js';
|
|
|
4871
4908
|
// import { RestClientV3 } from 'bitget-api';
|
|
4872
4909
|
|
|
4873
4910
|
================
|
|
4874
|
-
File: examples/
|
|
4911
|
+
File: examples/README.md
|
|
4875
4912
|
================
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
//
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
//
|
|
4913
|
+
# Examples
|
|
4914
|
+
|
|
4915
|
+
These samples can be executed using `ts-node`:
|
|
4916
|
+
|
|
4917
|
+
```
|
|
4918
|
+
ts-node ./examples/rest-spot-public.ts
|
|
4919
|
+
```
|
|
4920
|
+
|
|
4921
|
+
Samples that require authentication can be edited directly but also support environmental variables. E.g. on mac/unix:
|
|
4922
|
+
|
|
4923
|
+
```
|
|
4924
|
+
API_KEY_COM='yourkeyhere' API_SECRET_COM='yoursecrethere' API_PASS_COM='yourapipasshere' ts-node examples/rest-trade-futures.ts
|
|
4925
|
+
```
|
|
4926
|
+
|
|
4927
|
+
They can also be converted to JavaScript by changing the imports to require & removing any type annotations.
|
|
4928
|
+
|
|
4929
|
+
## V3 / Unified Trading Account (UTA)
|
|
4930
|
+
|
|
4931
|
+
These newer examples are for Bitget's V3 APIs and WebSockets. They can be found in the examples/V3 folder.
|
|
4932
|
+
|
|
4933
|
+
Refer to the V3 / UTA API documentation for more information on the V3 APIs:
|
|
4934
|
+
https://www.bitget.com/api-doc/uta/intro
|
|
4935
|
+
|
|
4936
|
+
These APIs require your account to be upgraded to the Unified Trading Account, if you plan on using the account-level REST APIs and WebSockets. Once upgraded, the V2 APIs are no longer available to you, unless you revert back to Classic Account mode.
|
|
4937
|
+
|
|
4938
|
+
### WebSocket API (WS API)
|
|
4939
|
+
|
|
4940
|
+
The V3/UTA API introduces order placement via a persisted WebSocket connection. This Bitget Node.js, JavaScript & TypeScript SDK supports Bitget's full V3 API offering, including the WebSocket API.
|
|
4941
|
+
|
|
4942
|
+
There are two approaches to placing orders via the Bitget WebSocket APIs
|
|
4943
|
+
|
|
4944
|
+
#### WebsocketAPIClient (recommended)
|
|
4945
|
+
|
|
4946
|
+
This integration looks & feels like a REST API client, but uses WebSockets, via the WebsocketClient's sendWSAPIRequest method. It returns promises and has end to end types.
|
|
4947
|
+
|
|
4948
|
+
This is the recommended approach to easily start sending orders via an automatically persisted WebSocket connection. A simple example is below, but for a more thorough example, check the example here: [./V3/ws-api-client-trade.ts](./V3/ws-api-client-trade.ts)
|
|
4949
|
+
|
|
4950
|
+
```typescript
|
|
4951
|
+
import { WebsocketAPIClient } from 'bitget-api';
|
|
4952
|
+
// or if you prefer require:
|
|
4953
|
+
// const { WebsocketAPIClient } = require("bitget-api");
|
|
4954
|
+
|
|
4955
|
+
// Make an instance of the WS API Client class with your API keys
|
|
4956
|
+
const wsClient = new WebsocketAPIClient({
|
|
4957
|
+
apiKey: API_KEY,
|
|
4958
|
+
apiSecret: API_SECRET,
|
|
4959
|
+
apiPass: API_PASS,
|
|
4960
|
+
|
|
4961
|
+
// Whether to use the demo trading wss connection
|
|
4962
|
+
// demoTrading: true,
|
|
4963
|
+
});
|
|
4964
|
+
|
|
4965
|
+
async function start() {
|
|
4966
|
+
// Start using it like a REST API. All actions are sent via a persisted WebSocket connection.
|
|
4967
|
+
|
|
4968
|
+
/**
|
|
4969
|
+
* Place Order
|
|
4970
|
+
* https://www.bitget.com/api-doc/uta/websocket/private/Place-Order-Channel#request-parameters
|
|
4971
|
+
*/
|
|
4972
|
+
try {
|
|
4973
|
+
const res = await wsClient.submitNewOrder('spot', {
|
|
4974
|
+
orderType: 'limit',
|
|
4975
|
+
price: '100',
|
|
4976
|
+
qty: '0.1',
|
|
4977
|
+
side: 'buy',
|
|
4978
|
+
symbol: 'BTCUSDT',
|
|
4979
|
+
timeInForce: 'gtc',
|
|
4980
|
+
});
|
|
4981
|
+
|
|
4982
|
+
console.log(new Date(), 'WS API "submitNewOrder()" result: ', res);
|
|
4983
|
+
} catch (e) {
|
|
4984
|
+
console.error(new Date(), 'Exception with WS API "submitNewOrder()": ', e);
|
|
4985
|
+
}
|
|
4986
|
+
}
|
|
4987
|
+
|
|
4988
|
+
start().catch((e) => console.error('Exception in example: '.e));
|
|
4989
|
+
```
|
|
4990
|
+
|
|
4991
|
+
#### ws.sendWSAPIRequest(wsKey, command, category, operation)
|
|
4992
|
+
|
|
4993
|
+
This is the "raw" integration within the existing WebSocket client. It uses an automatically persisted & authenticated connection to send events through Bitget's WebSocket API. It automatically tracks and connects outgoing requests with incoming responses, and returns promises that resolve/reject when a matching response is received.
|
|
4994
|
+
|
|
4995
|
+
Refer to [V3/ws-api-trade-raw.ts](./V3/ws-api-trade-raw.ts) to see an example.
|
|
4996
|
+
|
|
4997
|
+
Note: The WebsocketClient is built around this. For a more user friendly experience, it is recommended to use the WebsocketClient for WS API requests. It uses this method but has the convenience of behaving similar to a REST API (while all communication automatically happens over a persisted WebSocket connection).
|
|
4998
|
+
|
|
4999
|
+
## V2
|
|
5000
|
+
|
|
5001
|
+
These examples are for Bitget's V2 APIs and WebSockets. They can be found in the examples/V2 folder.
|
|
5002
|
+
|
|
5003
|
+
Refer to the V2 API documentation for more information on the V2 APIs:
|
|
5004
|
+
https://www.bitget.com/api-doc/common/intro
|
|
4926
5005
|
|
|
4927
5006
|
================
|
|
4928
|
-
File:
|
|
5007
|
+
File: src/constants/enum.ts
|
|
4929
5008
|
================
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
// read from environmental variables
|
|
5009
|
+
/** Parameter verification exception margin mode == FIXED */
|
|
5010
|
+
|
|
5011
|
+
================
|
|
5012
|
+
File: src/types/request/v3/broker.ts
|
|
5013
|
+
================
|
|
5014
|
+
export interface CreateBrokerSubAccountRequestV3 {
|
|
5015
|
+
subaccountName: string;
|
|
5016
|
+
label: string;
|
|
5017
|
+
}
|
|
4940
5018
|
⋮----
|
|
4941
|
-
|
|
4942
|
-
|
|
5019
|
+
export interface GetBrokerSubAccountListRequestV3 {
|
|
5020
|
+
limit?: string;
|
|
5021
|
+
cursor?: string;
|
|
5022
|
+
status?: 'normal' | 'freeze';
|
|
5023
|
+
}
|
|
4943
5024
|
⋮----
|
|
4944
|
-
|
|
5025
|
+
export interface ModifyBrokerSubAccountRequestV3 {
|
|
5026
|
+
subUid: string;
|
|
5027
|
+
status?: 'normal' | 'freeze';
|
|
5028
|
+
permList?: string[];
|
|
5029
|
+
}
|
|
4945
5030
|
⋮----
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
5031
|
+
export interface BrokerSubWithdrawalRequestV3 {
|
|
5032
|
+
subUid: string;
|
|
5033
|
+
coin: string;
|
|
5034
|
+
dest: 'on_chain' | 'internal_transfer';
|
|
5035
|
+
address: string;
|
|
5036
|
+
amount: string;
|
|
5037
|
+
chain?: string;
|
|
5038
|
+
tag?: string;
|
|
5039
|
+
clientOid?: string;
|
|
5040
|
+
}
|
|
4949
5041
|
⋮----
|
|
4950
|
-
|
|
5042
|
+
export interface GetBrokerSubDepositAddressRequestV3 {
|
|
5043
|
+
subUid: string;
|
|
5044
|
+
coin: string;
|
|
5045
|
+
chain?: string;
|
|
5046
|
+
}
|
|
4951
5047
|
⋮----
|
|
4952
|
-
|
|
4953
|
-
|
|
5048
|
+
export interface GetBrokerAllSubDepositWithdrawalRequestV3 {
|
|
5049
|
+
startTime?: string;
|
|
5050
|
+
endTime?: string;
|
|
5051
|
+
limit?: string;
|
|
5052
|
+
cursor?: string;
|
|
5053
|
+
status?: 'pending' | 'fail' | 'success';
|
|
5054
|
+
}
|
|
4954
5055
|
⋮----
|
|
4955
|
-
|
|
5056
|
+
export interface GetBrokerCommissionRequestV3 {
|
|
5057
|
+
startTime?: string;
|
|
5058
|
+
endTime?: string;
|
|
5059
|
+
pageSize?: string;
|
|
5060
|
+
pageNo?: string;
|
|
5061
|
+
bizType?: 'spot' | 'futures';
|
|
5062
|
+
subBizType?:
|
|
5063
|
+
| 'spot_trade'
|
|
5064
|
+
| 'spot_margin'
|
|
5065
|
+
| 'usdt_futures'
|
|
5066
|
+
| 'usdc_futures'
|
|
5067
|
+
| 'coin_futures';
|
|
5068
|
+
}
|
|
4956
5069
|
⋮----
|
|
4957
|
-
|
|
5070
|
+
export interface CreateBrokerSubApiKeyRequestV3 {
|
|
5071
|
+
subUid: string;
|
|
5072
|
+
passphrase: string;
|
|
5073
|
+
label: string;
|
|
5074
|
+
ipList?: string[];
|
|
5075
|
+
permType: 'read_and_write' | 'readonly';
|
|
5076
|
+
permList: string[];
|
|
5077
|
+
}
|
|
4958
5078
|
⋮----
|
|
4959
|
-
|
|
4960
|
-
|
|
5079
|
+
export interface ModifyBrokerSubApiKeyRequestV3 {
|
|
5080
|
+
subUid: string;
|
|
5081
|
+
passphrase: string;
|
|
5082
|
+
apiKey: string;
|
|
5083
|
+
label?: string;
|
|
5084
|
+
ipList?: string[];
|
|
5085
|
+
permType?: 'read_and_write' | 'readonly';
|
|
5086
|
+
permList?: string[];
|
|
5087
|
+
}
|
|
4961
5088
|
⋮----
|
|
4962
|
-
|
|
5089
|
+
export interface DeleteBrokerSubApiKeyRequestV3 {
|
|
5090
|
+
subUid: string;
|
|
5091
|
+
apiKey: string;
|
|
5092
|
+
}
|
|
4963
5093
|
⋮----
|
|
4964
|
-
|
|
5094
|
+
export interface GetBrokerSubApiKeyRequestV3 {
|
|
5095
|
+
subUid: string;
|
|
5096
|
+
}
|
|
4965
5097
|
|
|
4966
5098
|
================
|
|
4967
|
-
File:
|
|
5099
|
+
File: src/types/request/v3/public.ts
|
|
4968
5100
|
================
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
5101
|
+
export interface GetPublicFillsRequestV3 {
|
|
5102
|
+
category:
|
|
5103
|
+
| 'SPOT'
|
|
5104
|
+
| 'MARGIN'
|
|
5105
|
+
| 'USDT-FUTURES'
|
|
5106
|
+
| 'COIN-FUTURES'
|
|
5107
|
+
| 'USDC-FUTURES';
|
|
5108
|
+
symbol?: string;
|
|
5109
|
+
limit?: string;
|
|
5110
|
+
}
|
|
4977
5111
|
⋮----
|
|
4978
|
-
|
|
4979
|
-
|
|
5112
|
+
export interface GetCandlesRequestV3 {
|
|
5113
|
+
category: 'SPOT' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES';
|
|
5114
|
+
symbol: string;
|
|
5115
|
+
interval:
|
|
5116
|
+
| '1m'
|
|
5117
|
+
| '3m'
|
|
5118
|
+
| '5m'
|
|
5119
|
+
| '15m'
|
|
5120
|
+
| '30m'
|
|
5121
|
+
| '1H'
|
|
5122
|
+
| '4H'
|
|
5123
|
+
| '6H'
|
|
5124
|
+
| '12H'
|
|
5125
|
+
| '1D';
|
|
5126
|
+
startTime?: string;
|
|
5127
|
+
endTime?: string;
|
|
5128
|
+
type?: 'MARKET' | 'MARK' | 'INDEX';
|
|
5129
|
+
limit?: string;
|
|
5130
|
+
}
|
|
4980
5131
|
⋮----
|
|
4981
|
-
|
|
5132
|
+
export interface GetHistoryCandlesRequestV3 {
|
|
5133
|
+
category: 'SPOT' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES';
|
|
5134
|
+
symbol: string;
|
|
5135
|
+
interval:
|
|
5136
|
+
| '1m'
|
|
5137
|
+
| '3m'
|
|
5138
|
+
| '5m'
|
|
5139
|
+
| '15m'
|
|
5140
|
+
| '30m'
|
|
5141
|
+
| '1H'
|
|
5142
|
+
| '4H'
|
|
5143
|
+
| '6H'
|
|
5144
|
+
| '12H'
|
|
5145
|
+
| '1D';
|
|
5146
|
+
startTime?: string;
|
|
5147
|
+
endTime?: string;
|
|
5148
|
+
type?: 'MARKET' | 'MARK' | 'INDEX';
|
|
5149
|
+
limit?: string;
|
|
5150
|
+
}
|
|
4982
5151
|
⋮----
|
|
4983
|
-
|
|
5152
|
+
export interface GetContractsOiRequestV3 {
|
|
5153
|
+
symbol?: string;
|
|
5154
|
+
category: 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES';
|
|
5155
|
+
}
|
|
4984
5156
|
⋮----
|
|
4985
|
-
|
|
5157
|
+
export interface GetCurrentFundingRateRequestV3 {
|
|
5158
|
+
symbol: string;
|
|
5159
|
+
}
|
|
4986
5160
|
⋮----
|
|
4987
|
-
|
|
5161
|
+
export interface GetHistoryFundingRateRequestV3 {
|
|
5162
|
+
category: 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES';
|
|
5163
|
+
symbol: string;
|
|
5164
|
+
cursor?: string;
|
|
5165
|
+
limit?: string;
|
|
5166
|
+
}
|
|
4988
5167
|
⋮----
|
|
4989
|
-
|
|
5168
|
+
export interface GetMarginLoansRequestV3 {
|
|
5169
|
+
coin: string;
|
|
5170
|
+
}
|
|
4990
5171
|
⋮----
|
|
4991
|
-
|
|
5172
|
+
export interface GetOpenInterestRequestV3 {
|
|
5173
|
+
category: 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES';
|
|
5174
|
+
symbol?: string;
|
|
5175
|
+
}
|
|
4992
5176
|
⋮----
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
================
|
|
4999
|
-
import {
|
|
5000
|
-
DefaultLogger,
|
|
5001
|
-
WebsocketClientV3,
|
|
5002
|
-
WS_KEY_MAP,
|
|
5003
|
-
} from '../../../src/index.js';
|
|
5177
|
+
export interface GetPositionTierRequestV3 {
|
|
5178
|
+
category: 'MARGIN' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES';
|
|
5179
|
+
symbol?: string;
|
|
5180
|
+
coin?: string;
|
|
5181
|
+
}
|
|
5004
5182
|
⋮----
|
|
5005
|
-
|
|
5006
|
-
|
|
5183
|
+
export interface GetRiskReserveRequestV3 {
|
|
5184
|
+
category: 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES';
|
|
5185
|
+
symbol: string;
|
|
5186
|
+
}
|
|
5007
5187
|
⋮----
|
|
5008
|
-
|
|
5188
|
+
export interface GetInstrumentsRequestV3 {
|
|
5189
|
+
category:
|
|
5190
|
+
| 'SPOT'
|
|
5191
|
+
| 'MARGIN'
|
|
5192
|
+
| 'USDT-FUTURES'
|
|
5193
|
+
| 'COIN-FUTURES'
|
|
5194
|
+
| 'USDC-FUTURES';
|
|
5195
|
+
symbol?: string;
|
|
5196
|
+
}
|
|
5009
5197
|
⋮----
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5198
|
+
export interface GetMarketFeeGroupRequestV3 {
|
|
5199
|
+
category: 'SPOT' | 'FUTURES';
|
|
5200
|
+
group?: 'GROUP_A' | 'GROUP_B' | 'GROUP_C';
|
|
5201
|
+
}
|
|
5013
5202
|
⋮----
|
|
5014
|
-
|
|
5203
|
+
export interface GetMarketScoreWeightsRequestV3 {
|
|
5204
|
+
category?: 'SPOT' | 'FUTURES';
|
|
5205
|
+
}
|
|
5015
5206
|
⋮----
|
|
5016
|
-
|
|
5207
|
+
export interface GetOrderBookRequestV3 {
|
|
5208
|
+
category: 'SPOT' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES';
|
|
5209
|
+
symbol: string;
|
|
5210
|
+
limit?: string;
|
|
5211
|
+
}
|
|
5017
5212
|
⋮----
|
|
5018
|
-
|
|
5213
|
+
export interface GetTickersRequestV3 {
|
|
5214
|
+
category: 'SPOT' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES';
|
|
5215
|
+
symbol?: string;
|
|
5216
|
+
}
|
|
5019
5217
|
⋮----
|
|
5020
|
-
|
|
5021
|
-
|
|
5218
|
+
export interface GetIndexComponentsRequestV3 {
|
|
5219
|
+
symbol: string;
|
|
5220
|
+
}
|
|
5022
5221
|
|
|
5023
5222
|
================
|
|
5024
|
-
File:
|
|
5223
|
+
File: src/types/response/v3/broker.ts
|
|
5025
5224
|
================
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5225
|
+
export interface CreateBrokerSubAccountResponseV3 {
|
|
5226
|
+
subUid: string;
|
|
5227
|
+
subaccountName: string;
|
|
5228
|
+
subaccountEmail: string;
|
|
5229
|
+
status: 'normal' | 'freeze';
|
|
5230
|
+
permList: string[];
|
|
5231
|
+
label: string;
|
|
5232
|
+
cTime: string;
|
|
5233
|
+
}
|
|
5031
5234
|
⋮----
|
|
5032
|
-
|
|
5033
|
-
|
|
5235
|
+
export interface BrokerSubAccountV3 {
|
|
5236
|
+
subUid: string;
|
|
5237
|
+
subaccountName: string;
|
|
5238
|
+
subaccountEmail: string | null;
|
|
5239
|
+
status: 'normal' | 'freeze';
|
|
5240
|
+
permList: string[];
|
|
5241
|
+
label: string;
|
|
5242
|
+
language: string;
|
|
5243
|
+
cTime: string;
|
|
5244
|
+
uTime: string;
|
|
5245
|
+
}
|
|
5034
5246
|
⋮----
|
|
5035
|
-
|
|
5036
|
-
|
|
5247
|
+
export interface GetBrokerSubAccountListResponseV3 {
|
|
5248
|
+
subList: BrokerSubAccountV3[];
|
|
5249
|
+
}
|
|
5037
5250
|
⋮----
|
|
5038
|
-
|
|
5251
|
+
export interface ModifyBrokerSubAccountResponseV3 {
|
|
5252
|
+
subUid: string;
|
|
5253
|
+
subaccountName: string;
|
|
5254
|
+
status: 'normal' | 'freeze';
|
|
5255
|
+
permList: string[];
|
|
5256
|
+
label: string;
|
|
5257
|
+
cTime: string;
|
|
5258
|
+
uTime: string;
|
|
5259
|
+
}
|
|
5039
5260
|
⋮----
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
*
|
|
5045
|
-
* Note: this requires V3/UTA API keys!
|
|
5046
|
-
* Note: for a better user experience, it is recommended to use the WebsocketAPIClient.
|
|
5047
|
-
*/
|
|
5261
|
+
export interface BrokerSubWithdrawalResponseV3 {
|
|
5262
|
+
orderId: string;
|
|
5263
|
+
clientOid: string;
|
|
5264
|
+
}
|
|
5048
5265
|
⋮----
|
|
5049
|
-
|
|
5266
|
+
export interface BrokerSubDepositAddressV3 {
|
|
5267
|
+
subUid: string;
|
|
5268
|
+
coin: string;
|
|
5269
|
+
address: string;
|
|
5270
|
+
chain: string;
|
|
5271
|
+
tag: string | null;
|
|
5272
|
+
url: string;
|
|
5273
|
+
cTime: string;
|
|
5274
|
+
}
|
|
5050
5275
|
⋮----
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5276
|
+
export interface BrokerSubDepositWithdrawalRecordV3 {
|
|
5277
|
+
uid: string;
|
|
5278
|
+
txId: string;
|
|
5279
|
+
type: 'deposit' | 'withdrawal';
|
|
5280
|
+
subType: 'onchain' | 'internal' | 'fast';
|
|
5281
|
+
coin: string;
|
|
5282
|
+
amount: string;
|
|
5283
|
+
status: 'pending' | 'fail' | 'success';
|
|
5284
|
+
ts: string;
|
|
5285
|
+
}
|
|
5055
5286
|
⋮----
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
"category": "spot",
|
|
5061
|
-
"topic": "place-order",
|
|
5062
|
-
"args": [
|
|
5063
|
-
{
|
|
5064
|
-
"symbol": "BTCUSDT",
|
|
5065
|
-
"orderId": "xxxxxxxx",
|
|
5066
|
-
"clientOid": "xxxxxxxx",
|
|
5067
|
-
"cTime": "1750034397008"
|
|
5068
|
-
}
|
|
5069
|
-
],
|
|
5070
|
-
"code": "0",
|
|
5071
|
-
"msg": "success",
|
|
5072
|
-
"ts": "1750034397076"
|
|
5073
|
-
};
|
|
5074
|
-
*/
|
|
5287
|
+
export interface GetBrokerAllSubDepositWithdrawalResponseV3 {
|
|
5288
|
+
list: BrokerSubDepositWithdrawalRecordV3[];
|
|
5289
|
+
endId: string;
|
|
5290
|
+
}
|
|
5075
5291
|
⋮----
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5292
|
+
export interface BrokerCommissionRecordV3 {
|
|
5293
|
+
uid: string;
|
|
5294
|
+
coin: string;
|
|
5295
|
+
symbol: string;
|
|
5296
|
+
dealtAmount: string;
|
|
5297
|
+
totalFee: string;
|
|
5298
|
+
deductedFee: string;
|
|
5299
|
+
paidFee: string;
|
|
5300
|
+
markUpFee: string;
|
|
5301
|
+
totalCommission: string;
|
|
5302
|
+
}
|
|
5080
5303
|
⋮----
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5304
|
+
export interface CreateBrokerSubApiKeyResponseV3 {
|
|
5305
|
+
subUid: string;
|
|
5306
|
+
label: string;
|
|
5307
|
+
apiKey: string;
|
|
5308
|
+
secretKey: string;
|
|
5309
|
+
permType: 'read_and_write' | 'readonly';
|
|
5310
|
+
permList: string[];
|
|
5311
|
+
ipList: string[] | null;
|
|
5312
|
+
}
|
|
5084
5313
|
⋮----
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
"code": "0",
|
|
5094
|
-
"msg": "Success",
|
|
5095
|
-
"symbol": "BTCUSDT",
|
|
5096
|
-
"orderId": "xxxxxxxx",
|
|
5097
|
-
"clientOid": "xxxxxxxx"
|
|
5098
|
-
},
|
|
5099
|
-
{
|
|
5100
|
-
"code": "0",
|
|
5101
|
-
"msg": "Success",
|
|
5102
|
-
"symbol": "BTCUSDT",
|
|
5103
|
-
"orderId": "xxxxxxxx",
|
|
5104
|
-
"clientOid": "xxxxxxxx"
|
|
5105
|
-
}
|
|
5106
|
-
],
|
|
5107
|
-
"code": "0",
|
|
5108
|
-
"msg": "Success",
|
|
5109
|
-
"ts": "1750035029925"
|
|
5110
|
-
}
|
|
5111
|
-
*/
|
|
5112
|
-
⋮----
|
|
5113
|
-
/**
|
|
5114
|
-
* Cancel Order
|
|
5115
|
-
* https://www.bitget.com/api-doc/uta/websocket/private/Cancel-Order-Channel
|
|
5116
|
-
*/
|
|
5117
|
-
⋮----
|
|
5118
|
-
/**
|
|
5119
|
-
const res = {
|
|
5120
|
-
"event": "trade",
|
|
5121
|
-
"id": "1750034870205",
|
|
5122
|
-
"topic": "cancel-order",
|
|
5123
|
-
"args": [
|
|
5124
|
-
{
|
|
5125
|
-
"orderId": "xxxxxxxx",
|
|
5126
|
-
"clientOid": "xxxxxxxx"
|
|
5127
|
-
}
|
|
5128
|
-
],
|
|
5129
|
-
"code": "0",
|
|
5130
|
-
"msg": "Success",
|
|
5131
|
-
"ts": "1750034870597"
|
|
5132
|
-
}
|
|
5133
|
-
*/
|
|
5134
|
-
⋮----
|
|
5135
|
-
/**
|
|
5136
|
-
* Batch Cancel Order
|
|
5137
|
-
* https://www.bitget.com/api-doc/uta/websocket/private/Batch-Cancel-Order-Channel
|
|
5138
|
-
*/
|
|
5314
|
+
export interface ModifyBrokerSubApiKeyResponseV3 {
|
|
5315
|
+
subUid: string;
|
|
5316
|
+
label: string;
|
|
5317
|
+
apiKey: string;
|
|
5318
|
+
permType: 'read_and_write' | 'readonly';
|
|
5319
|
+
permList: string[];
|
|
5320
|
+
ipList: string[];
|
|
5321
|
+
}
|
|
5139
5322
|
⋮----
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
"msg": "Success",
|
|
5149
|
-
"orderId": "xxxxxxxxxxxxx"
|
|
5150
|
-
},
|
|
5151
|
-
{
|
|
5152
|
-
"code": "25204",
|
|
5153
|
-
"msg": "Order does not exist",
|
|
5154
|
-
"orderId": "xxxxxxxxxxxxx"
|
|
5155
|
-
}
|
|
5156
|
-
],
|
|
5157
|
-
"code": "0",
|
|
5158
|
-
"msg": "Success",
|
|
5159
|
-
"ts": "1751980011084"
|
|
5160
|
-
}
|
|
5161
|
-
*/
|
|
5162
|
-
|
|
5163
|
-
================
|
|
5164
|
-
File: examples/README.md
|
|
5165
|
-
================
|
|
5166
|
-
# Examples
|
|
5167
|
-
|
|
5168
|
-
These samples can be executed using `ts-node`:
|
|
5169
|
-
|
|
5170
|
-
```
|
|
5171
|
-
ts-node ./examples/rest-spot-public.ts
|
|
5172
|
-
```
|
|
5173
|
-
|
|
5174
|
-
Samples that require authentication can be edited directly but also support environmental variables. E.g. on mac/unix:
|
|
5175
|
-
|
|
5176
|
-
```
|
|
5177
|
-
API_KEY_COM='yourkeyhere' API_SECRET_COM='yoursecrethere' API_PASS_COM='yourapipasshere' ts-node examples/rest-trade-futures.ts
|
|
5178
|
-
```
|
|
5179
|
-
|
|
5180
|
-
They can also be converted to JavaScript by changing the imports to require & removing any type annotations.
|
|
5181
|
-
|
|
5182
|
-
## V3 / Unified Trading Account (UTA)
|
|
5183
|
-
|
|
5184
|
-
These newer examples are for Bitget's V3 APIs and WebSockets. They can be found in the examples/V3 folder.
|
|
5185
|
-
|
|
5186
|
-
Refer to the V3 / UTA API documentation for more information on the V3 APIs:
|
|
5187
|
-
https://www.bitget.com/api-doc/uta/intro
|
|
5188
|
-
|
|
5189
|
-
These APIs require your account to be upgraded to the Unified Trading Account, if you plan on using the account-level REST APIs and WebSockets. Once upgraded, the V2 APIs are no longer available to you, unless you revert back to Classic Account mode.
|
|
5190
|
-
|
|
5191
|
-
### WebSocket API (WS API)
|
|
5192
|
-
|
|
5193
|
-
The V3/UTA API introduces order placement via a persisted WebSocket connection. This Bitget Node.js, JavaScript & TypeScript SDK supports Bitget's full V3 API offering, including the WebSocket API.
|
|
5194
|
-
|
|
5195
|
-
There are two approaches to placing orders via the Bitget WebSocket APIs
|
|
5196
|
-
|
|
5197
|
-
#### WebsocketAPIClient (recommended)
|
|
5198
|
-
|
|
5199
|
-
This integration looks & feels like a REST API client, but uses WebSockets, via the WebsocketClient's sendWSAPIRequest method. It returns promises and has end to end types.
|
|
5200
|
-
|
|
5201
|
-
This is the recommended approach to easily start sending orders via an automatically persisted WebSocket connection. A simple example is below, but for a more thorough example, check the example here: [./V3/ws-api-client-trade.ts](./V3/ws-api-client-trade.ts)
|
|
5202
|
-
|
|
5203
|
-
```typescript
|
|
5204
|
-
import { WebsocketAPIClient } from 'bitget-api';
|
|
5205
|
-
// or if you prefer require:
|
|
5206
|
-
// const { WebsocketAPIClient } = require("bitget-api");
|
|
5207
|
-
|
|
5208
|
-
// Make an instance of the WS API Client class with your API keys
|
|
5209
|
-
const wsClient = new WebsocketAPIClient({
|
|
5210
|
-
apiKey: API_KEY,
|
|
5211
|
-
apiSecret: API_SECRET,
|
|
5212
|
-
apiPass: API_PASS,
|
|
5213
|
-
|
|
5214
|
-
// Whether to use the demo trading wss connection
|
|
5215
|
-
// demoTrading: true,
|
|
5216
|
-
});
|
|
5217
|
-
|
|
5218
|
-
async function start() {
|
|
5219
|
-
// Start using it like a REST API. All actions are sent via a persisted WebSocket connection.
|
|
5220
|
-
|
|
5221
|
-
/**
|
|
5222
|
-
* Place Order
|
|
5223
|
-
* https://www.bitget.com/api-doc/uta/websocket/private/Place-Order-Channel#request-parameters
|
|
5224
|
-
*/
|
|
5225
|
-
try {
|
|
5226
|
-
const res = await wsClient.submitNewOrder('spot', {
|
|
5227
|
-
orderType: 'limit',
|
|
5228
|
-
price: '100',
|
|
5229
|
-
qty: '0.1',
|
|
5230
|
-
side: 'buy',
|
|
5231
|
-
symbol: 'BTCUSDT',
|
|
5232
|
-
timeInForce: 'gtc',
|
|
5233
|
-
});
|
|
5234
|
-
|
|
5235
|
-
console.log(new Date(), 'WS API "submitNewOrder()" result: ', res);
|
|
5236
|
-
} catch (e) {
|
|
5237
|
-
console.error(new Date(), 'Exception with WS API "submitNewOrder()": ', e);
|
|
5238
|
-
}
|
|
5323
|
+
export interface GetBrokerSubApiKeyResponseV3 {
|
|
5324
|
+
subUid: string;
|
|
5325
|
+
label: string;
|
|
5326
|
+
apiKey: string;
|
|
5327
|
+
secretKey: string;
|
|
5328
|
+
permType: 'read_and_write' | 'readonly';
|
|
5329
|
+
permList: string[];
|
|
5330
|
+
ipList: string[] | null;
|
|
5239
5331
|
}
|
|
5240
5332
|
|
|
5241
|
-
start().catch((e) => console.error('Exception in example: '.e));
|
|
5242
|
-
```
|
|
5243
|
-
|
|
5244
|
-
#### ws.sendWSAPIRequest(wsKey, command, category, operation)
|
|
5245
|
-
|
|
5246
|
-
This is the "raw" integration within the existing WebSocket client. It uses an automatically persisted & authenticated connection to send events through Bitget's WebSocket API. It automatically tracks and connects outgoing requests with incoming responses, and returns promises that resolve/reject when a matching response is received.
|
|
5247
|
-
|
|
5248
|
-
Refer to [V3/ws-api-trade-raw.ts](./V3/ws-api-trade-raw.ts) to see an example.
|
|
5249
|
-
|
|
5250
|
-
Note: The WebsocketClient is built around this. For a more user friendly experience, it is recommended to use the WebsocketClient for WS API requests. It uses this method but has the convenience of behaving similar to a REST API (while all communication automatically happens over a persisted WebSocket connection).
|
|
5251
|
-
|
|
5252
|
-
## V2
|
|
5253
|
-
|
|
5254
|
-
These examples are for Bitget's V2 APIs and WebSockets. They can be found in the examples/V2 folder.
|
|
5255
|
-
|
|
5256
|
-
Refer to the V2 API documentation for more information on the V2 APIs:
|
|
5257
|
-
https://www.bitget.com/api-doc/common/intro
|
|
5258
|
-
|
|
5259
|
-
================
|
|
5260
|
-
File: src/constants/enum.ts
|
|
5261
5333
|
================
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
================
|
|
5265
|
-
File: src/types/request/v3/broker.ts
|
|
5334
|
+
File: src/types/response/v3/loan.ts
|
|
5266
5335
|
================
|
|
5267
|
-
export interface
|
|
5268
|
-
|
|
5269
|
-
|
|
5336
|
+
export interface LoanTransfersV3 {
|
|
5337
|
+
coin: string;
|
|
5338
|
+
transfered: string;
|
|
5339
|
+
userId: string;
|
|
5270
5340
|
}
|
|
5271
5341
|
⋮----
|
|
5272
|
-
export interface
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
status?: 'normal' | 'freeze';
|
|
5342
|
+
export interface LoanSymbolSettingV3 {
|
|
5343
|
+
symbol: string;
|
|
5344
|
+
leverage: string;
|
|
5276
5345
|
}
|
|
5277
5346
|
⋮----
|
|
5278
|
-
export interface
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5347
|
+
export interface LoanSymbolsV3 {
|
|
5348
|
+
productId: string;
|
|
5349
|
+
spotSymbols: string[];
|
|
5350
|
+
marginLeverage: string;
|
|
5351
|
+
usdtContractLeverage: string;
|
|
5352
|
+
coinContractLeverage: string;
|
|
5353
|
+
usdcContractLeverage: string;
|
|
5354
|
+
usdtContractSymbols: LoanSymbolSettingV3[];
|
|
5355
|
+
coinContractSymbols: LoanSymbolSettingV3[];
|
|
5356
|
+
usdcContractSymbols: LoanSymbolSettingV3[];
|
|
5357
|
+
}
|
|
5358
|
+
⋮----
|
|
5359
|
+
export interface RepaidHistoryItemV3 {
|
|
5360
|
+
repayOrderId: string;
|
|
5361
|
+
businessType: 'normal' | 'liquidation';
|
|
5362
|
+
repayType: 'all' | 'part';
|
|
5363
|
+
repaidTime: string;
|
|
5364
|
+
coin: string;
|
|
5365
|
+
repayAmount: string;
|
|
5366
|
+
repayInterest: string;
|
|
5367
|
+
}
|
|
5368
|
+
⋮----
|
|
5369
|
+
export interface LoanProductInfoV3 {
|
|
5370
|
+
productId: string;
|
|
5371
|
+
leverage: string;
|
|
5372
|
+
supportUsdtContract: 'YES' | 'NO';
|
|
5373
|
+
supportCoinContract: 'YES' | 'NO';
|
|
5374
|
+
supportUsdcContract: 'YES' | 'NO';
|
|
5375
|
+
transferLine: string;
|
|
5376
|
+
spotBuyLine: string;
|
|
5377
|
+
usdtContractOpenLine: string;
|
|
5378
|
+
coinContractOpenLine: string;
|
|
5379
|
+
usdcContractOpenLine: string;
|
|
5380
|
+
liquidationLine: string;
|
|
5381
|
+
stopLiquidationLine: string;
|
|
5382
|
+
}
|
|
5383
|
+
⋮----
|
|
5384
|
+
export interface LoanOrderV3 {
|
|
5385
|
+
orderId: string;
|
|
5386
|
+
orderProductId: string;
|
|
5387
|
+
uid: string;
|
|
5388
|
+
loanTime: string;
|
|
5389
|
+
loanCoin: string;
|
|
5390
|
+
loanAmount: string;
|
|
5391
|
+
unpaidAmount: string;
|
|
5392
|
+
unpaidInterest: string;
|
|
5393
|
+
repaidAmount: string;
|
|
5394
|
+
repaidInterest: string;
|
|
5395
|
+
reserve: string;
|
|
5396
|
+
status: 'not_paid_off' | 'paid_off';
|
|
5397
|
+
}
|
|
5398
|
+
⋮----
|
|
5399
|
+
/** Tiered conversion rate item (when Tiered Discount Rate Model is enabled) */
|
|
5400
|
+
export interface ConvertRatioListItemV3 {
|
|
5401
|
+
ladder: string;
|
|
5402
|
+
convertRatio: string;
|
|
5403
|
+
}
|
|
5404
|
+
⋮----
|
|
5405
|
+
export interface CoinInfoV3 {
|
|
5406
|
+
coin: string;
|
|
5407
|
+
convertRatio: string;
|
|
5408
|
+
maxConvertValue: string;
|
|
5409
|
+
/** Tiered conversion rate (when margin mode is Tiered Discount Rate Model) */
|
|
5410
|
+
convertRatioList?: ConvertRatioListItemV3[];
|
|
5411
|
+
}
|
|
5412
|
+
⋮----
|
|
5413
|
+
/** Tiered conversion rate (when margin mode is Tiered Discount Rate Model) */
|
|
5414
|
+
⋮----
|
|
5415
|
+
export interface BindUidResponseV3 {
|
|
5416
|
+
riskUnitId: string;
|
|
5417
|
+
uid: string;
|
|
5418
|
+
operate: 'bind' | 'unbind';
|
|
5419
|
+
}
|
|
5420
|
+
⋮----
|
|
5421
|
+
export interface UnpaidInfoV3 {
|
|
5422
|
+
coin: string;
|
|
5423
|
+
unpaidQty: string;
|
|
5424
|
+
unpaidInterest: string;
|
|
5282
5425
|
}
|
|
5283
5426
|
⋮----
|
|
5284
|
-
export interface
|
|
5285
|
-
subUid: string;
|
|
5427
|
+
export interface BalanceInfoV3 {
|
|
5286
5428
|
coin: string;
|
|
5287
|
-
|
|
5288
|
-
address: string;
|
|
5429
|
+
price: string;
|
|
5289
5430
|
amount: string;
|
|
5290
|
-
|
|
5291
|
-
tag?: string;
|
|
5292
|
-
clientOid?: string;
|
|
5431
|
+
convertedUsdtAmount: string;
|
|
5293
5432
|
}
|
|
5294
5433
|
⋮----
|
|
5295
|
-
export interface
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5434
|
+
export interface LTVConvertResponseV3 {
|
|
5435
|
+
ltv: string;
|
|
5436
|
+
subAccountUids: string[];
|
|
5437
|
+
unpaidUsdtAmount: string;
|
|
5438
|
+
usdtBalance: string;
|
|
5439
|
+
unpaidInfo: UnpaidInfoV3[];
|
|
5440
|
+
balanceInfo: BalanceInfoV3[];
|
|
5299
5441
|
}
|
|
5300
5442
|
⋮----
|
|
5301
|
-
|
|
5302
|
-
startTime?: string;
|
|
5303
|
-
endTime?: string;
|
|
5304
|
-
limit?: string;
|
|
5305
|
-
cursor?: string;
|
|
5306
|
-
status?: 'pending' | 'fail' | 'success';
|
|
5307
|
-
}
|
|
5443
|
+
/* Unified Account Staking & Lending (Crypto Loans) - /api/v3/loan/* */
|
|
5308
5444
|
⋮----
|
|
5309
|
-
export interface
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5445
|
+
export interface LoanCoinInfoV3 {
|
|
5446
|
+
coin: string;
|
|
5447
|
+
hourRateFlexible: string;
|
|
5448
|
+
rateFlexible: string;
|
|
5449
|
+
hourRate7D: string;
|
|
5450
|
+
rate7D: string;
|
|
5451
|
+
hourRate30D: string;
|
|
5452
|
+
rate30D: string;
|
|
5453
|
+
minBorrowAmount: string;
|
|
5454
|
+
maxBorrowAmount: string;
|
|
5455
|
+
minBorrowLimit: string;
|
|
5456
|
+
maxBorrowLimit: string;
|
|
5321
5457
|
}
|
|
5322
5458
|
⋮----
|
|
5323
|
-
export interface
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5459
|
+
export interface LoanPledgeInfoV3 {
|
|
5460
|
+
coin: string;
|
|
5461
|
+
initRate: string;
|
|
5462
|
+
supRate: string;
|
|
5463
|
+
forceRate: string;
|
|
5464
|
+
minPledgeAmount: string;
|
|
5465
|
+
maxPledgeAmount: string;
|
|
5330
5466
|
}
|
|
5331
5467
|
⋮----
|
|
5332
|
-
export interface
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
apiKey: string;
|
|
5336
|
-
label?: string;
|
|
5337
|
-
ipList?: string[];
|
|
5338
|
-
permType?: 'read_and_write' | 'readonly';
|
|
5339
|
-
permList?: string[];
|
|
5468
|
+
export interface GetLoanCoinsResponseV3 {
|
|
5469
|
+
loanInfos: LoanCoinInfoV3[];
|
|
5470
|
+
pledgeInfos: LoanPledgeInfoV3[];
|
|
5340
5471
|
}
|
|
5341
5472
|
⋮----
|
|
5342
|
-
export interface
|
|
5343
|
-
|
|
5344
|
-
|
|
5473
|
+
export interface GetLoanInterestResponseV3 {
|
|
5474
|
+
hourInterest: string;
|
|
5475
|
+
loanAmount: string;
|
|
5345
5476
|
}
|
|
5346
5477
|
⋮----
|
|
5347
|
-
export interface
|
|
5348
|
-
|
|
5478
|
+
export interface LoanBorrowResponseV3 {
|
|
5479
|
+
orderId: string;
|
|
5349
5480
|
}
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5481
|
+
⋮----
|
|
5482
|
+
export interface LoanBorrowOngoingItemV3 {
|
|
5483
|
+
orderId: string;
|
|
5484
|
+
loanCoin: string;
|
|
5485
|
+
loanAmount: string;
|
|
5486
|
+
interestAmount: string;
|
|
5487
|
+
hourInterestRate: string;
|
|
5488
|
+
pledgeCoin: string;
|
|
5489
|
+
pledgeAmount: string;
|
|
5490
|
+
pledgeRate: string;
|
|
5491
|
+
supRate: string;
|
|
5492
|
+
forceRate: string;
|
|
5493
|
+
borrowTime: string;
|
|
5494
|
+
expireTime: string;
|
|
5363
5495
|
}
|
|
5364
5496
|
⋮----
|
|
5365
|
-
export interface
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
| '4H'
|
|
5376
|
-
| '6H'
|
|
5377
|
-
| '12H'
|
|
5378
|
-
| '1D';
|
|
5379
|
-
startTime?: string;
|
|
5380
|
-
endTime?: string;
|
|
5381
|
-
type?: 'MARKET' | 'MARK' | 'INDEX';
|
|
5382
|
-
limit?: string;
|
|
5497
|
+
export interface LoanBorrowHistoryItemV3 {
|
|
5498
|
+
orderId: string;
|
|
5499
|
+
loanCoin: string;
|
|
5500
|
+
pledgeCoin: string;
|
|
5501
|
+
initPledgeAmount: string;
|
|
5502
|
+
initLoanAmount: string;
|
|
5503
|
+
hourRate: string;
|
|
5504
|
+
daily: string;
|
|
5505
|
+
borrowTime: string;
|
|
5506
|
+
status: string;
|
|
5383
5507
|
}
|
|
5384
5508
|
⋮----
|
|
5385
|
-
export interface
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
| '15m'
|
|
5393
|
-
| '30m'
|
|
5394
|
-
| '1H'
|
|
5395
|
-
| '4H'
|
|
5396
|
-
| '6H'
|
|
5397
|
-
| '12H'
|
|
5398
|
-
| '1D';
|
|
5399
|
-
startTime?: string;
|
|
5400
|
-
endTime?: string;
|
|
5401
|
-
type?: 'MARKET' | 'MARK' | 'INDEX';
|
|
5402
|
-
limit?: string;
|
|
5509
|
+
export interface LoanRepayResponseV3 {
|
|
5510
|
+
loanCoin: string;
|
|
5511
|
+
pledgeCoin: string;
|
|
5512
|
+
repayAmount: string;
|
|
5513
|
+
payInterest: string;
|
|
5514
|
+
repayLoanAmount: string;
|
|
5515
|
+
repayUnlockAmount: string;
|
|
5403
5516
|
}
|
|
5404
5517
|
⋮----
|
|
5405
|
-
export interface
|
|
5406
|
-
|
|
5407
|
-
|
|
5518
|
+
export interface LoanRepayHistoryItemV3 {
|
|
5519
|
+
orderId: string;
|
|
5520
|
+
loanCoin: string;
|
|
5521
|
+
pledgeCoin: string;
|
|
5522
|
+
repayAmount: string;
|
|
5523
|
+
payInterest: string;
|
|
5524
|
+
repayLoanAmount: string;
|
|
5525
|
+
repayUnlockAmount: string;
|
|
5526
|
+
repayTime: string;
|
|
5408
5527
|
}
|
|
5409
5528
|
⋮----
|
|
5410
|
-
export interface
|
|
5411
|
-
|
|
5529
|
+
export interface LoanRevisePledgeResponseV3 {
|
|
5530
|
+
loanCoin: string;
|
|
5531
|
+
pledgeCoin: string;
|
|
5532
|
+
afterPledgeRate: string;
|
|
5412
5533
|
}
|
|
5413
5534
|
⋮----
|
|
5414
|
-
export interface
|
|
5415
|
-
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
|
|
5535
|
+
export interface LoanPledgeRateHistoryItemV3 {
|
|
5536
|
+
loanCoin: string;
|
|
5537
|
+
pledgeCoin: string;
|
|
5538
|
+
orderId: string;
|
|
5539
|
+
reviseTime: string;
|
|
5540
|
+
reviseSide: string;
|
|
5541
|
+
reviseAmount: string;
|
|
5542
|
+
afterPledgeRate: string;
|
|
5543
|
+
beforePledgeRate: string;
|
|
5419
5544
|
}
|
|
5420
5545
|
⋮----
|
|
5421
|
-
export interface
|
|
5546
|
+
export interface LoanDebtInfoV3 {
|
|
5422
5547
|
coin: string;
|
|
5548
|
+
amount: string;
|
|
5549
|
+
amountUsdt: string;
|
|
5423
5550
|
}
|
|
5424
5551
|
⋮----
|
|
5425
|
-
export interface
|
|
5426
|
-
|
|
5427
|
-
|
|
5552
|
+
export interface GetLoanDebtsResponseV3 {
|
|
5553
|
+
pledgeInfos: LoanDebtInfoV3[];
|
|
5554
|
+
loanInfos: LoanDebtInfoV3[];
|
|
5428
5555
|
}
|
|
5429
5556
|
⋮----
|
|
5430
|
-
export interface
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5557
|
+
export interface LoanReduceItemV3 {
|
|
5558
|
+
orderId: string;
|
|
5559
|
+
loanCoin: string;
|
|
5560
|
+
pledgeCoin: string;
|
|
5561
|
+
reduceTime: string;
|
|
5562
|
+
pledgeRate: string;
|
|
5563
|
+
pledgePrice: string;
|
|
5564
|
+
status: string;
|
|
5565
|
+
pledgeAmount: string;
|
|
5566
|
+
reduceFee: string;
|
|
5567
|
+
residueAmount: string;
|
|
5568
|
+
runlockAmount: string;
|
|
5569
|
+
repayLoanAmount: string;
|
|
5434
5570
|
}
|
|
5571
|
+
|
|
5572
|
+
================
|
|
5573
|
+
File: src/types/shared.ts
|
|
5574
|
+
================
|
|
5575
|
+
import { REST_CLIENT_TYPE_ENUM } from '../util/requestUtils.js';
|
|
5435
5576
|
⋮----
|
|
5436
|
-
export
|
|
5437
|
-
category: 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES';
|
|
5438
|
-
symbol: string;
|
|
5439
|
-
}
|
|
5577
|
+
export type numberInString = string;
|
|
5440
5578
|
⋮----
|
|
5441
|
-
export
|
|
5442
|
-
category:
|
|
5443
|
-
| 'SPOT'
|
|
5444
|
-
| 'MARGIN'
|
|
5445
|
-
| 'USDT-FUTURES'
|
|
5446
|
-
| 'COIN-FUTURES'
|
|
5447
|
-
| 'USDC-FUTURES';
|
|
5448
|
-
symbol?: string;
|
|
5449
|
-
}
|
|
5579
|
+
export type OrderSide = 'Buy' | 'Sell';
|
|
5450
5580
|
⋮----
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5581
|
+
/**
|
|
5582
|
+
* @deprecated use SpotKlineInterval or FuturesKlineInterval, depending on which API group you're using
|
|
5583
|
+
*/
|
|
5584
|
+
export type KlineInterval =
|
|
5585
|
+
| '1min'
|
|
5586
|
+
| '5min'
|
|
5587
|
+
| '15min'
|
|
5588
|
+
| '30min'
|
|
5589
|
+
| '1h'
|
|
5590
|
+
| '4h'
|
|
5591
|
+
| '6h'
|
|
5592
|
+
| '12h'
|
|
5593
|
+
| '1M'
|
|
5594
|
+
| '1W'
|
|
5595
|
+
| '1week'
|
|
5596
|
+
| '6Hutc'
|
|
5597
|
+
| '12Hutc'
|
|
5598
|
+
| '1Dutc'
|
|
5599
|
+
| '3Dutc'
|
|
5600
|
+
| '1Wutc'
|
|
5601
|
+
| '1Mutc';
|
|
5456
5602
|
⋮----
|
|
5457
|
-
export
|
|
5458
|
-
|
|
5459
|
-
|
|
5603
|
+
export type RestClientType =
|
|
5604
|
+
(typeof REST_CLIENT_TYPE_ENUM)[keyof typeof REST_CLIENT_TYPE_ENUM];
|
|
5605
|
+
⋮----
|
|
5606
|
+
export interface APIResponse<T> {
|
|
5607
|
+
code: string;
|
|
5608
|
+
requestTime: number;
|
|
5609
|
+
msg: 'success' | string;
|
|
5610
|
+
data: T;
|
|
5460
5611
|
}
|
|
5612
|
+
|
|
5613
|
+
================
|
|
5614
|
+
File: webpack/webpack.config.cjs
|
|
5615
|
+
================
|
|
5616
|
+
function generateConfig(name)
|
|
5461
5617
|
⋮----
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5618
|
+
// Add '.ts' and '.tsx' as resolvable extensions.
|
|
5619
|
+
⋮----
|
|
5620
|
+
// Node.js core modules not available in browsers
|
|
5621
|
+
// The REST client's https.Agent (for keepAlive) is Node.js-only and won't work in browsers
|
|
5622
|
+
⋮----
|
|
5623
|
+
// Code is already transpiled from TypeScript, no additional loaders needed
|
|
5465
5624
|
|
|
5466
5625
|
================
|
|
5467
|
-
File:
|
|
5626
|
+
File: tsconfig.json
|
|
5468
5627
|
================
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5628
|
+
{
|
|
5629
|
+
"compilerOptions": {
|
|
5630
|
+
"allowSyntheticDefaultImports": true,
|
|
5631
|
+
"baseUrl": ".",
|
|
5632
|
+
"noEmitOnError": true,
|
|
5633
|
+
"declaration": true,
|
|
5634
|
+
"esModuleInterop": true,
|
|
5635
|
+
"forceConsistentCasingInFileNames": false,
|
|
5636
|
+
"inlineSourceMap": false,
|
|
5637
|
+
"lib": ["esnext", "DOM"],
|
|
5638
|
+
"listEmittedFiles": false,
|
|
5639
|
+
"listFiles": false,
|
|
5640
|
+
"moduleResolution": "node",
|
|
5641
|
+
"noFallthroughCasesInSwitch": true,
|
|
5642
|
+
"noImplicitAny": true,
|
|
5643
|
+
"noUnusedParameters": true,
|
|
5644
|
+
"pretty": true,
|
|
5645
|
+
"removeComments": false,
|
|
5646
|
+
"resolveJsonModule": true,
|
|
5647
|
+
"skipLibCheck": false,
|
|
5648
|
+
"sourceMap": true,
|
|
5649
|
+
"strict": true,
|
|
5650
|
+
"strictNullChecks": true,
|
|
5651
|
+
"types": ["node", "jest"],
|
|
5652
|
+
"module": "commonjs",
|
|
5653
|
+
"outDir": "dist/cjs",
|
|
5654
|
+
"target": "esnext"
|
|
5655
|
+
},
|
|
5656
|
+
"compileOnSave": true,
|
|
5657
|
+
"exclude": ["node_modules", "dist"],
|
|
5658
|
+
"include": ["src/**/*.*", "test/**/*.*", ".eslintrc.cjs"]
|
|
5477
5659
|
}
|
|
5660
|
+
|
|
5661
|
+
================
|
|
5662
|
+
File: examples/V2 - Classic/Rest/rest-trade-futures.ts
|
|
5663
|
+
================
|
|
5664
|
+
import {
|
|
5665
|
+
FuturesPlaceOrderRequestV2,
|
|
5666
|
+
RestClientV2,
|
|
5667
|
+
WebsocketClientV2,
|
|
5668
|
+
} from '../../../src/index.js';
|
|
5478
5669
|
⋮----
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
subaccountName: string;
|
|
5482
|
-
subaccountEmail: string | null;
|
|
5483
|
-
status: 'normal' | 'freeze';
|
|
5484
|
-
permList: string[];
|
|
5485
|
-
label: string;
|
|
5486
|
-
language: string;
|
|
5487
|
-
cTime: string;
|
|
5488
|
-
uTime: string;
|
|
5489
|
-
}
|
|
5670
|
+
// or
|
|
5671
|
+
// import { FuturesPlaceOrderRequestV2, RestClientV2, WebsocketClientV2 } from '../src';
|
|
5490
5672
|
⋮----
|
|
5491
|
-
|
|
5492
|
-
subList: BrokerSubAccountV3[];
|
|
5493
|
-
}
|
|
5673
|
+
// read from environmental variables
|
|
5494
5674
|
⋮----
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
subaccountName: string;
|
|
5498
|
-
status: 'normal' | 'freeze';
|
|
5499
|
-
permList: string[];
|
|
5500
|
-
label: string;
|
|
5501
|
-
cTime: string;
|
|
5502
|
-
uTime: string;
|
|
5503
|
-
}
|
|
5675
|
+
// If running from CLI in unix, you can pass env vars as such:
|
|
5676
|
+
// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/rest-trade-futures.ts
|
|
5504
5677
|
⋮----
|
|
5505
|
-
|
|
5506
|
-
orderId: string;
|
|
5507
|
-
clientOid: string;
|
|
5508
|
-
}
|
|
5678
|
+
// note the single quotes, preventing special characters such as $ from being incorrectly passed
|
|
5509
5679
|
⋮----
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
address: string;
|
|
5514
|
-
chain: string;
|
|
5515
|
-
tag: string | null;
|
|
5516
|
-
url: string;
|
|
5517
|
-
cTime: string;
|
|
5518
|
-
}
|
|
5680
|
+
// apiKey: 'apiKeyHere',
|
|
5681
|
+
// apiSecret: 'apiSecretHere',
|
|
5682
|
+
// apiPass: 'apiPassHere',
|
|
5519
5683
|
⋮----
|
|
5520
|
-
|
|
5521
|
-
uid: string;
|
|
5522
|
-
txId: string;
|
|
5523
|
-
type: 'deposit' | 'withdrawal';
|
|
5524
|
-
subType: 'onchain' | 'internal' | 'fast';
|
|
5525
|
-
coin: string;
|
|
5526
|
-
amount: string;
|
|
5527
|
-
status: 'pending' | 'fail' | 'success';
|
|
5528
|
-
ts: string;
|
|
5529
|
-
}
|
|
5684
|
+
function logWSEvent(type: string, data: any)
|
|
5530
5685
|
⋮----
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
endId: string;
|
|
5534
|
-
}
|
|
5686
|
+
// simple sleep function
|
|
5687
|
+
function promiseSleep(milliseconds: number)
|
|
5535
5688
|
⋮----
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5689
|
+
/**
|
|
5690
|
+
* This is a simple script wrapped in a immediately invoked function expression (to execute the below workflow immediately).
|
|
5691
|
+
*
|
|
5692
|
+
* It is designed to:
|
|
5693
|
+
* - open a private websocket channel to log account events
|
|
5694
|
+
* - check for any available USDT balance in the futures account
|
|
5695
|
+
* - immediately open a minimum sized long position on BTCUSDT
|
|
5696
|
+
* - check active positions
|
|
5697
|
+
* - immediately send closing orders for any active futures positions
|
|
5698
|
+
* - check positions again
|
|
5699
|
+
*
|
|
5700
|
+
*/
|
|
5547
5701
|
⋮----
|
|
5548
|
-
|
|
5549
|
-
subUid: string;
|
|
5550
|
-
label: string;
|
|
5551
|
-
apiKey: string;
|
|
5552
|
-
secretKey: string;
|
|
5553
|
-
permType: 'read_and_write' | 'readonly';
|
|
5554
|
-
permList: string[];
|
|
5555
|
-
ipList: string[] | null;
|
|
5556
|
-
}
|
|
5702
|
+
// Add event listeners to log websocket events on account
|
|
5557
5703
|
⋮----
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
label: string;
|
|
5561
|
-
apiKey: string;
|
|
5562
|
-
permType: 'read_and_write' | 'readonly';
|
|
5563
|
-
permList: string[];
|
|
5564
|
-
ipList: string[];
|
|
5565
|
-
}
|
|
5704
|
+
// futures private
|
|
5705
|
+
// : account updates
|
|
5566
5706
|
⋮----
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5707
|
+
// : position updates
|
|
5708
|
+
⋮----
|
|
5709
|
+
// : order updates
|
|
5710
|
+
⋮----
|
|
5711
|
+
// wait briefly for ws to be ready (could also use the response or authenticated events, to make sure topics are subscribed to before starting)
|
|
5712
|
+
⋮----
|
|
5713
|
+
// const balances = allBalances.filter((bal) => Number(bal.available) != 0);
|
|
5714
|
+
⋮----
|
|
5715
|
+
// Loop through any active positions and send a closing market order on each position
|
|
5576
5716
|
|
|
5577
5717
|
================
|
|
5578
|
-
File:
|
|
5718
|
+
File: examples/V2 - Classic/Rest/rest-trade-spot.ts
|
|
5579
5719
|
================
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
}
|
|
5585
|
-
⋮----
|
|
5586
|
-
export interface LoanSymbolSettingV3 {
|
|
5587
|
-
symbol: string;
|
|
5588
|
-
leverage: string;
|
|
5589
|
-
}
|
|
5590
|
-
⋮----
|
|
5591
|
-
export interface LoanSymbolsV3 {
|
|
5592
|
-
productId: string;
|
|
5593
|
-
spotSymbols: string[];
|
|
5594
|
-
marginLeverage: string;
|
|
5595
|
-
usdtContractLeverage: string;
|
|
5596
|
-
coinContractLeverage: string;
|
|
5597
|
-
usdcContractLeverage: string;
|
|
5598
|
-
usdtContractSymbols: LoanSymbolSettingV3[];
|
|
5599
|
-
coinContractSymbols: LoanSymbolSettingV3[];
|
|
5600
|
-
usdcContractSymbols: LoanSymbolSettingV3[];
|
|
5601
|
-
}
|
|
5720
|
+
import {
|
|
5721
|
+
RestClientV2,
|
|
5722
|
+
SpotOrderRequestV2,
|
|
5723
|
+
WebsocketClientV2,
|
|
5724
|
+
} from '../../../src/index.js';
|
|
5602
5725
|
⋮----
|
|
5603
|
-
|
|
5604
|
-
repayOrderId: string;
|
|
5605
|
-
businessType: 'normal' | 'liquidation';
|
|
5606
|
-
repayType: 'all' | 'part';
|
|
5607
|
-
repaidTime: string;
|
|
5608
|
-
coin: string;
|
|
5609
|
-
repayAmount: string;
|
|
5610
|
-
repayInterest: string;
|
|
5611
|
-
}
|
|
5726
|
+
// import { RestClientV2, WebsocketClient } from '../src/index';
|
|
5612
5727
|
⋮----
|
|
5613
|
-
|
|
5614
|
-
productId: string;
|
|
5615
|
-
leverage: string;
|
|
5616
|
-
supportUsdtContract: 'YES' | 'NO';
|
|
5617
|
-
supportCoinContract: 'YES' | 'NO';
|
|
5618
|
-
supportUsdcContract: 'YES' | 'NO';
|
|
5619
|
-
transferLine: string;
|
|
5620
|
-
spotBuyLine: string;
|
|
5621
|
-
usdtContractOpenLine: string;
|
|
5622
|
-
coinContractOpenLine: string;
|
|
5623
|
-
usdcContractOpenLine: string;
|
|
5624
|
-
liquidationLine: string;
|
|
5625
|
-
stopLiquidationLine: string;
|
|
5626
|
-
}
|
|
5728
|
+
// read from environmental variables
|
|
5627
5729
|
⋮----
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
orderProductId: string;
|
|
5631
|
-
uid: string;
|
|
5632
|
-
loanTime: string;
|
|
5633
|
-
loanCoin: string;
|
|
5634
|
-
loanAmount: string;
|
|
5635
|
-
unpaidAmount: string;
|
|
5636
|
-
unpaidInterest: string;
|
|
5637
|
-
repaidAmount: string;
|
|
5638
|
-
repaidInterest: string;
|
|
5639
|
-
reserve: string;
|
|
5640
|
-
status: 'not_paid_off' | 'paid_off';
|
|
5641
|
-
}
|
|
5730
|
+
// If running from CLI in unix, you can pass env vars as such:
|
|
5731
|
+
// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/rest-trade-spot.ts
|
|
5642
5732
|
⋮----
|
|
5643
|
-
|
|
5644
|
-
coin: string;
|
|
5645
|
-
convertRatio: string;
|
|
5646
|
-
maxConvertValue: string;
|
|
5647
|
-
}
|
|
5733
|
+
// note the single quotes, preventing special characters such as $ from being incorrectly passed
|
|
5648
5734
|
⋮----
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
operate: 'bind' | 'unbind';
|
|
5653
|
-
}
|
|
5735
|
+
// apiKey: 'apiKeyHere',
|
|
5736
|
+
// apiSecret: 'apiSecretHere',
|
|
5737
|
+
// apiPass: 'apiPassHere',
|
|
5654
5738
|
⋮----
|
|
5655
|
-
|
|
5656
|
-
coin: string;
|
|
5657
|
-
unpaidQty: string;
|
|
5658
|
-
unpaidInterest: string;
|
|
5659
|
-
}
|
|
5739
|
+
function logWSEvent(type: string, data: any)
|
|
5660
5740
|
⋮----
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
price: string;
|
|
5664
|
-
amount: string;
|
|
5665
|
-
convertedUsdtAmount: string;
|
|
5666
|
-
}
|
|
5741
|
+
// simple sleep function
|
|
5742
|
+
function promiseSleep(milliseconds: number)
|
|
5667
5743
|
⋮----
|
|
5668
|
-
|
|
5669
|
-
ltv: string;
|
|
5670
|
-
subAccountUids: string[];
|
|
5671
|
-
unpaidUsdtAmount: string;
|
|
5672
|
-
usdtBalance: string;
|
|
5673
|
-
unpaidInfo: UnpaidInfoV3[];
|
|
5674
|
-
balanceInfo: BalanceInfoV3[];
|
|
5675
|
-
}
|
|
5676
|
-
|
|
5677
|
-
================
|
|
5678
|
-
File: src/types/shared.ts
|
|
5679
|
-
================
|
|
5680
|
-
import { REST_CLIENT_TYPE_ENUM } from '../util/requestUtils.js';
|
|
5744
|
+
/** This is a simple script wrapped in a immediately invoked function expression, designed to check for any available BTC balance and immediately sell the full amount for USDT */
|
|
5681
5745
|
⋮----
|
|
5682
|
-
|
|
5746
|
+
// Add event listeners to log websocket events on account
|
|
5683
5747
|
⋮----
|
|
5684
|
-
|
|
5748
|
+
// Subscribe to private account topics
|
|
5749
|
+
// spot private
|
|
5750
|
+
// : account updates
|
|
5685
5751
|
⋮----
|
|
5686
|
-
|
|
5687
|
-
* @deprecated use SpotKlineInterval or FuturesKlineInterval, depending on which API group you're using
|
|
5688
|
-
*/
|
|
5689
|
-
export type KlineInterval =
|
|
5690
|
-
| '1min'
|
|
5691
|
-
| '5min'
|
|
5692
|
-
| '15min'
|
|
5693
|
-
| '30min'
|
|
5694
|
-
| '1h'
|
|
5695
|
-
| '4h'
|
|
5696
|
-
| '6h'
|
|
5697
|
-
| '12h'
|
|
5698
|
-
| '1M'
|
|
5699
|
-
| '1W'
|
|
5700
|
-
| '1week'
|
|
5701
|
-
| '6Hutc'
|
|
5702
|
-
| '12Hutc'
|
|
5703
|
-
| '1Dutc'
|
|
5704
|
-
| '3Dutc'
|
|
5705
|
-
| '1Wutc'
|
|
5706
|
-
| '1Mutc';
|
|
5752
|
+
// : order updates (note: symbol is required)
|
|
5707
5753
|
⋮----
|
|
5708
|
-
|
|
5709
|
-
(typeof REST_CLIENT_TYPE_ENUM)[keyof typeof REST_CLIENT_TYPE_ENUM];
|
|
5754
|
+
// wait briefly for ws to be ready (could also use the response or authenticated events, to make sure topics are subscribed to before starting)
|
|
5710
5755
|
⋮----
|
|
5711
|
-
|
|
5712
|
-
code: string;
|
|
5713
|
-
requestTime: number;
|
|
5714
|
-
msg: 'success' | string;
|
|
5715
|
-
data: T;
|
|
5716
|
-
}
|
|
5756
|
+
// console.log('balance: ', JSON.stringify(balances, null, 2));
|
|
5717
5757
|
|
|
5718
5758
|
================
|
|
5719
|
-
File:
|
|
5759
|
+
File: examples/V2 - Classic/Websocket/ws-demo-trading.ts
|
|
5720
5760
|
================
|
|
5721
|
-
|
|
5761
|
+
import { DefaultLogger, WebsocketClientV2 } from '../../../src/index.js';
|
|
5722
5762
|
⋮----
|
|
5723
|
-
//
|
|
5763
|
+
// or
|
|
5764
|
+
// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api';
|
|
5724
5765
|
⋮----
|
|
5725
|
-
//
|
|
5726
|
-
//
|
|
5766
|
+
// If running from CLI in unix, you can pass env vars as such:
|
|
5767
|
+
// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts
|
|
5727
5768
|
⋮----
|
|
5728
|
-
//
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5769
|
+
// restOptions: {
|
|
5770
|
+
// optionally provide rest options, e.g. to pass through a proxy
|
|
5771
|
+
// },
|
|
5772
|
+
⋮----
|
|
5773
|
+
// Set demoTrading to true, to route all connections to the demo trading wss URLs:
|
|
5774
|
+
⋮----
|
|
5775
|
+
// If using private topics, make sure to include API keys
|
|
5776
|
+
⋮----
|
|
5777
|
+
// console.log('WS raw message received ', JSON.stringify(data, null, 2));
|
|
5778
|
+
⋮----
|
|
5779
|
+
/**
|
|
5780
|
+
* Public events
|
|
5781
|
+
*/
|
|
5734
5782
|
|
|
5735
5783
|
================
|
|
5736
|
-
File:
|
|
5784
|
+
File: examples/V2 - Classic/Websocket/ws-private.ts
|
|
5737
5785
|
================
|
|
5738
|
-
|
|
5739
|
-
* For a detailed explanation regarding each configuration property, visit:
|
|
5740
|
-
* https://jestjs.io/docs/configuration
|
|
5741
|
-
*/
|
|
5786
|
+
import { DefaultLogger, WebsocketClientV2 } from '../../../src/index.js';
|
|
5742
5787
|
⋮----
|
|
5743
|
-
|
|
5788
|
+
// or
|
|
5789
|
+
// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api';
|
|
5744
5790
|
⋮----
|
|
5745
|
-
//
|
|
5746
|
-
//
|
|
5791
|
+
// If running from CLI in unix, you can pass env vars as such:
|
|
5792
|
+
// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts
|
|
5747
5793
|
⋮----
|
|
5748
|
-
//
|
|
5749
|
-
// bail: 0,
|
|
5750
|
-
bail: false, // enable to stop test when an error occur,
|
|
5794
|
+
// note the single quotes, preventing special characters such as $ from being incorrectly passed
|
|
5751
5795
|
⋮----
|
|
5752
|
-
//
|
|
5753
|
-
//
|
|
5796
|
+
// restOptions: {
|
|
5797
|
+
// optionally provide rest options, e.g. to pass through a proxy
|
|
5798
|
+
// },
|
|
5754
5799
|
⋮----
|
|
5755
|
-
//
|
|
5800
|
+
// console.log('WS raw message received ', JSON.stringify(data, null, 2));
|
|
5756
5801
|
⋮----
|
|
5757
|
-
//
|
|
5802
|
+
// auth happens async after the ws connection opens
|
|
5758
5803
|
⋮----
|
|
5759
|
-
//
|
|
5804
|
+
// wsClient.subscribePublicSpotTickers(['BTCUSDT', 'LTCUSDT']);
|
|
5760
5805
|
⋮----
|
|
5761
|
-
|
|
5806
|
+
/**
|
|
5807
|
+
* Private account updates
|
|
5808
|
+
*/
|
|
5762
5809
|
⋮----
|
|
5763
|
-
//
|
|
5764
|
-
//
|
|
5765
|
-
// "/node_modules/"
|
|
5766
|
-
// ],
|
|
5810
|
+
// spot private
|
|
5811
|
+
// : account updates
|
|
5767
5812
|
⋮----
|
|
5768
|
-
//
|
|
5813
|
+
// : order updates (note: symbol is required)
|
|
5814
|
+
// wsClient.subscribeTopic('SPOT', 'orders', 'BTCUSDT');
|
|
5769
5815
|
⋮----
|
|
5770
|
-
//
|
|
5771
|
-
//
|
|
5772
|
-
// "json",
|
|
5773
|
-
// "text",
|
|
5774
|
-
// "lcov",
|
|
5775
|
-
// "clover"
|
|
5776
|
-
// ],
|
|
5816
|
+
// futures private
|
|
5817
|
+
// : account updates
|
|
5777
5818
|
⋮----
|
|
5778
|
-
//
|
|
5779
|
-
//
|
|
5819
|
+
// : position updates
|
|
5820
|
+
// wsClient.subscribeTopic('USDT-FUTURES', 'positions');
|
|
5780
5821
|
⋮----
|
|
5781
|
-
//
|
|
5782
|
-
//
|
|
5822
|
+
// : order updates
|
|
5823
|
+
// wsClient.subscribeTopic('USDT-FUTURES', 'orders');
|
|
5783
5824
|
⋮----
|
|
5784
|
-
//
|
|
5785
|
-
//
|
|
5825
|
+
// : plan order updates
|
|
5826
|
+
// wsClient.subscribeTopic('USDT-FUTURES', 'orders-algo');
|
|
5786
5827
|
⋮----
|
|
5787
|
-
//
|
|
5788
|
-
//
|
|
5789
|
-
//
|
|
5828
|
+
// wsClient
|
|
5829
|
+
// .getWsStore()
|
|
5830
|
+
// .getKeys()
|
|
5831
|
+
// .forEach((wsKey) => {
|
|
5832
|
+
// const state = wsClient.getWsStore().get(wsKey);
|
|
5833
|
+
// console.log(`${wsKey} state: `, state.subscribedTopics.values());
|
|
5834
|
+
// });
|
|
5835
|
+
⋮----
|
|
5836
|
+
// setTimeout(() => {
|
|
5837
|
+
// wsClient.unsubscribeTopic('USDT-FUTURES', 'account');
|
|
5838
|
+
// }, 1000 * 2);
|
|
5839
|
+
⋮----
|
|
5840
|
+
// setTimeout(() => {
|
|
5841
|
+
// wsClient
|
|
5842
|
+
// .getWsStore()
|
|
5843
|
+
// .getKeys()
|
|
5844
|
+
// .forEach((wsKey) => {
|
|
5845
|
+
// const state = wsClient.getWsStore().get(wsKey);
|
|
5846
|
+
// console.log(`${wsKey} state: `, state.subscribedTopics.values());
|
|
5847
|
+
// });
|
|
5848
|
+
// }, 1000 * 5);
|
|
5849
|
+
|
|
5850
|
+
================
|
|
5851
|
+
File: examples/V2 - Classic/Websocket/ws-public.ts
|
|
5852
|
+
================
|
|
5853
|
+
import {
|
|
5854
|
+
DefaultLogger,
|
|
5855
|
+
WebsocketClientV2,
|
|
5856
|
+
WS_KEY_MAP,
|
|
5857
|
+
} from '../../../src/index.js';
|
|
5858
|
+
⋮----
|
|
5859
|
+
// or
|
|
5860
|
+
// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api';
|
|
5861
|
+
⋮----
|
|
5862
|
+
// restOptions: {
|
|
5863
|
+
// optionally provide rest options, e.g. to pass through a proxy
|
|
5790
5864
|
// },
|
|
5791
5865
|
⋮----
|
|
5792
|
-
//
|
|
5793
|
-
// forceCoverageMatch: [],
|
|
5866
|
+
// console.log('WS raw message received ', JSON.stringify(data, null, 2));
|
|
5794
5867
|
⋮----
|
|
5795
|
-
|
|
5796
|
-
|
|
5868
|
+
/**
|
|
5869
|
+
* Public events
|
|
5870
|
+
*/
|
|
5797
5871
|
⋮----
|
|
5798
|
-
//
|
|
5799
|
-
// globalTeardown: undefined,
|
|
5872
|
+
// Spot public
|
|
5800
5873
|
⋮----
|
|
5801
|
-
//
|
|
5802
|
-
// globals: {},
|
|
5874
|
+
// tickers
|
|
5803
5875
|
⋮----
|
|
5804
|
-
//
|
|
5805
|
-
//
|
|
5876
|
+
// candles
|
|
5877
|
+
// wsClient.subscribeTopic('SPOT', 'candle1m', symbol);
|
|
5806
5878
|
⋮----
|
|
5807
|
-
//
|
|
5808
|
-
//
|
|
5809
|
-
// "node_modules"
|
|
5810
|
-
// ],
|
|
5879
|
+
// orderbook updates
|
|
5880
|
+
// wsClient.subscribeTopic('SPOT', 'books', symbol);
|
|
5811
5881
|
⋮----
|
|
5812
|
-
//
|
|
5882
|
+
// trades
|
|
5883
|
+
// wsClient.subscribeTopic('SPOT', 'trade', symbol);
|
|
5884
|
+
⋮----
|
|
5885
|
+
// Futures public
|
|
5886
|
+
⋮----
|
|
5887
|
+
// tickers
|
|
5888
|
+
// wsClient.subscribeTopic('USDT-FUTURES', 'ticker', symbol);
|
|
5889
|
+
⋮----
|
|
5890
|
+
// candles
|
|
5891
|
+
// wsClient.subscribeTopic('USDT-FUTURES', 'candle1m', symbol);
|
|
5892
|
+
⋮----
|
|
5893
|
+
// orderbook updates
|
|
5894
|
+
// wsClient.subscribeTopic('USDT-FUTURES', 'books', symbol);
|
|
5895
|
+
⋮----
|
|
5896
|
+
// trades
|
|
5897
|
+
// wsClient.subscribeTopic('USDT-FUTURES', 'trade', symbol);
|
|
5898
|
+
⋮----
|
|
5899
|
+
// Topics are tracked per websocket type
|
|
5900
|
+
// Get a list of subscribed topics (e.g. all public topics) (after a 5 second delay)
|
|
5901
|
+
|
|
5902
|
+
================
|
|
5903
|
+
File: examples/V3 - UTA/Rest/rest-trade-UTA-futures.ts
|
|
5904
|
+
================
|
|
5905
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
5906
|
+
import {
|
|
5907
|
+
PlaceOrderRequestV3,
|
|
5908
|
+
RestClientV3,
|
|
5909
|
+
WebsocketClientV3,
|
|
5910
|
+
} from '../../../src/index.js';
|
|
5813
5911
|
⋮----
|
|
5814
|
-
//
|
|
5912
|
+
// or
|
|
5913
|
+
// import { PlaceOrderRequestV3, RestClientV3, WebsocketClientV3 } from '../src';
|
|
5815
5914
|
⋮----
|
|
5816
|
-
//
|
|
5817
|
-
// moduleNameMapper: {},
|
|
5915
|
+
// read from environmental variables
|
|
5818
5916
|
⋮----
|
|
5819
|
-
//
|
|
5820
|
-
//
|
|
5917
|
+
// If running from CLI in unix, you can pass env vars as such:
|
|
5918
|
+
// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/V3/rest-trade-futures.ts
|
|
5821
5919
|
⋮----
|
|
5822
|
-
//
|
|
5823
|
-
// notify: false,
|
|
5920
|
+
// note the single quotes, preventing special characters such as $ from being incorrectly passed
|
|
5824
5921
|
⋮----
|
|
5825
|
-
//
|
|
5826
|
-
//
|
|
5922
|
+
// apiKey: 'apiKeyHere',
|
|
5923
|
+
// apiSecret: 'apiSecretHere',
|
|
5924
|
+
// apiPass: 'apiPassHere',
|
|
5827
5925
|
⋮----
|
|
5828
|
-
|
|
5829
|
-
// preset: undefined,
|
|
5926
|
+
function logWSEvent(type: string, data: any)
|
|
5830
5927
|
⋮----
|
|
5831
|
-
//
|
|
5832
|
-
|
|
5928
|
+
// simple sleep function
|
|
5929
|
+
function promiseSleep(milliseconds: number)
|
|
5833
5930
|
⋮----
|
|
5834
|
-
|
|
5835
|
-
|
|
5931
|
+
/**
|
|
5932
|
+
* This is a simple script wrapped in a immediately invoked function expression (to execute the below workflow immediately).
|
|
5933
|
+
*
|
|
5934
|
+
* It is designed to:
|
|
5935
|
+
* - open a private websocket channel to log account events
|
|
5936
|
+
* - check for any available USDT balance in the account
|
|
5937
|
+
* - immediately open a minimum sized long position on BTCUSDT
|
|
5938
|
+
* - check active positions
|
|
5939
|
+
* - immediately send closing orders for any active futures positions
|
|
5940
|
+
* - check positions again
|
|
5941
|
+
*
|
|
5942
|
+
*/
|
|
5836
5943
|
⋮----
|
|
5837
|
-
//
|
|
5838
|
-
// resetMocks: false,
|
|
5944
|
+
// Add event listeners to log websocket events on account
|
|
5839
5945
|
⋮----
|
|
5840
|
-
//
|
|
5841
|
-
// resetModules: false,
|
|
5946
|
+
// Subscribe to private topics for UTA account
|
|
5842
5947
|
⋮----
|
|
5843
|
-
//
|
|
5844
|
-
// resolver: undefined,
|
|
5948
|
+
// Subscribe to position updates
|
|
5845
5949
|
⋮----
|
|
5846
|
-
//
|
|
5847
|
-
// restoreMocks: false,
|
|
5950
|
+
// Subscribe to order updates
|
|
5848
5951
|
⋮----
|
|
5849
|
-
//
|
|
5850
|
-
// rootDir: undefined,
|
|
5952
|
+
// wait briefly for ws to be ready (could also use the response or authenticated events, to make sure topics are subscribed to before starting)
|
|
5851
5953
|
⋮----
|
|
5852
|
-
//
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5954
|
+
// Loop through any active positions and send a closing market order on each position
|
|
5955
|
+
|
|
5956
|
+
================
|
|
5957
|
+
File: examples/V3 - UTA/Rest/rest-trade-UTA-spot.ts
|
|
5958
|
+
================
|
|
5959
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
5960
|
+
import {
|
|
5961
|
+
PlaceOrderRequestV3,
|
|
5962
|
+
RestClientV3,
|
|
5963
|
+
WebsocketClientV3,
|
|
5964
|
+
} from '../../../src/index.js';
|
|
5856
5965
|
⋮----
|
|
5857
|
-
//
|
|
5858
|
-
// runner: "jest-runner",
|
|
5966
|
+
// import { RestClientV3, WebsocketClientV3 } from '../src/index';
|
|
5859
5967
|
⋮----
|
|
5860
|
-
//
|
|
5861
|
-
// setupFiles: [],
|
|
5968
|
+
// read from environmental variables
|
|
5862
5969
|
⋮----
|
|
5863
|
-
//
|
|
5864
|
-
//
|
|
5970
|
+
// If running from CLI in unix, you can pass env vars as such:
|
|
5971
|
+
// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/V3/rest-trade-spot.ts
|
|
5865
5972
|
⋮----
|
|
5866
|
-
//
|
|
5867
|
-
// slowTestThreshold: 5,
|
|
5973
|
+
// note the single quotes, preventing special characters such as $ from being incorrectly passed
|
|
5868
5974
|
⋮----
|
|
5869
|
-
//
|
|
5870
|
-
//
|
|
5975
|
+
// apiKey: 'apiKeyHere',
|
|
5976
|
+
// apiSecret: 'apiSecretHere',
|
|
5977
|
+
// apiPass: 'apiPassHere',
|
|
5871
5978
|
⋮----
|
|
5872
|
-
|
|
5873
|
-
// testEnvironment: "jest-environment-node",
|
|
5979
|
+
function logWSEvent(type: string, data: any)
|
|
5874
5980
|
⋮----
|
|
5875
|
-
//
|
|
5876
|
-
|
|
5981
|
+
// simple sleep function
|
|
5982
|
+
function promiseSleep(milliseconds: number)
|
|
5877
5983
|
⋮----
|
|
5878
|
-
|
|
5879
|
-
// testLocationInResults: false,
|
|
5984
|
+
/** This is a simple script wrapped in a immediately invoked function expression, designed to check for any available BTC balance and immediately sell the full amount for USDT */
|
|
5880
5985
|
⋮----
|
|
5881
|
-
//
|
|
5986
|
+
// Add event listeners to log websocket events on account
|
|
5882
5987
|
⋮----
|
|
5883
|
-
//
|
|
5988
|
+
// Subscribe to private account topics
|
|
5989
|
+
// Account updates for UTA (unified trading account)
|
|
5884
5990
|
⋮----
|
|
5885
|
-
//
|
|
5886
|
-
// testPathIgnorePatterns: [
|
|
5887
|
-
// "/node_modules/"
|
|
5888
|
-
// ],
|
|
5991
|
+
// Order updates for spot
|
|
5889
5992
|
⋮----
|
|
5890
|
-
//
|
|
5891
|
-
|
|
5993
|
+
// wait briefly for ws to be ready (could also use the response or authenticated events, to make sure topics are subscribed to before starting)
|
|
5994
|
+
|
|
5995
|
+
================
|
|
5996
|
+
File: examples/V3 - UTA/Websocket/ws-private.ts
|
|
5997
|
+
================
|
|
5998
|
+
import {
|
|
5999
|
+
DefaultLogger,
|
|
6000
|
+
WebsocketClientV3,
|
|
6001
|
+
WS_KEY_MAP,
|
|
6002
|
+
} from '../../../src/index.js';
|
|
5892
6003
|
⋮----
|
|
5893
|
-
//
|
|
5894
|
-
//
|
|
6004
|
+
// or
|
|
6005
|
+
// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api';
|
|
5895
6006
|
⋮----
|
|
5896
|
-
//
|
|
5897
|
-
//
|
|
6007
|
+
// If running from CLI in unix, you can pass env vars as such:
|
|
6008
|
+
// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts
|
|
5898
6009
|
⋮----
|
|
5899
|
-
//
|
|
5900
|
-
// transform: undefined,
|
|
6010
|
+
// console.log('WS raw message received ', JSON.stringify(data, null, 2));
|
|
5901
6011
|
⋮----
|
|
5902
|
-
//
|
|
5903
|
-
// transformIgnorePatterns: [
|
|
5904
|
-
// "/node_modules/",
|
|
5905
|
-
// "\\.pnp\\.[^\\/]+$"
|
|
5906
|
-
// ],
|
|
6012
|
+
// You can subscribe to one topic at a time
|
|
5907
6013
|
⋮----
|
|
5908
|
-
|
|
6014
|
+
instType: 'UTA', // Note: all account events go on the UTA instType
|
|
5909
6015
|
⋮----
|
|
5910
|
-
//
|
|
5911
|
-
// unmockedModulePathPatterns: undefined,
|
|
6016
|
+
WS_KEY_MAP.v3Private, // This parameter points to private or public
|
|
5912
6017
|
⋮----
|
|
5913
|
-
//
|
|
5914
|
-
// verbose: undefined,
|
|
5915
|
-
verbose: true, // report individual test
|
|
6018
|
+
// Note: all account events go on the UTA instType
|
|
5916
6019
|
⋮----
|
|
5917
|
-
//
|
|
5918
|
-
// watchPathIgnorePatterns: [],
|
|
6020
|
+
// Or multiple at once:
|
|
5919
6021
|
⋮----
|
|
5920
|
-
//
|
|
5921
|
-
//
|
|
5922
|
-
|
|
5923
|
-
================
|
|
5924
|
-
File: tea.yaml
|
|
5925
|
-
================
|
|
5926
|
-
# https://tea.xyz/what-is-this-file
|
|
5927
|
-
---
|
|
5928
|
-
version: 1.0.0
|
|
5929
|
-
codeOwners:
|
|
5930
|
-
- '0xeb1a7BF44a801e33a339705A266Afc0Cba3D6D54'
|
|
5931
|
-
quorum: 1
|
|
5932
|
-
|
|
5933
|
-
================
|
|
5934
|
-
File: tsconfig.json
|
|
5935
|
-
================
|
|
5936
|
-
{
|
|
5937
|
-
"compilerOptions": {
|
|
5938
|
-
"allowSyntheticDefaultImports": true,
|
|
5939
|
-
"baseUrl": ".",
|
|
5940
|
-
"noEmitOnError": true,
|
|
5941
|
-
"declaration": true,
|
|
5942
|
-
"esModuleInterop": true,
|
|
5943
|
-
"forceConsistentCasingInFileNames": false,
|
|
5944
|
-
"inlineSourceMap": false,
|
|
5945
|
-
"lib": ["esnext", "DOM"],
|
|
5946
|
-
"listEmittedFiles": false,
|
|
5947
|
-
"listFiles": false,
|
|
5948
|
-
"moduleResolution": "node",
|
|
5949
|
-
"noFallthroughCasesInSwitch": true,
|
|
5950
|
-
"noImplicitAny": true,
|
|
5951
|
-
"noUnusedParameters": true,
|
|
5952
|
-
"pretty": true,
|
|
5953
|
-
"removeComments": false,
|
|
5954
|
-
"resolveJsonModule": true,
|
|
5955
|
-
"skipLibCheck": false,
|
|
5956
|
-
"sourceMap": true,
|
|
5957
|
-
"strict": true,
|
|
5958
|
-
"strictNullChecks": true,
|
|
5959
|
-
"types": ["node", "jest"],
|
|
5960
|
-
"module": "commonjs",
|
|
5961
|
-
"outDir": "dist/cjs",
|
|
5962
|
-
"target": "esnext"
|
|
5963
|
-
},
|
|
5964
|
-
"compileOnSave": true,
|
|
5965
|
-
"exclude": ["node_modules", "dist"],
|
|
5966
|
-
"include": ["src/**/*.*", "test/**/*.*", ".eslintrc.cjs"]
|
|
5967
|
-
}
|
|
6022
|
+
// Topics are tracked per websocket type
|
|
6023
|
+
// The below example will pull a list of subscribed topics on that connection (e.g. all private topics), after a 5 second delay:
|
|
5968
6024
|
|
|
5969
6025
|
================
|
|
5970
|
-
File: examples/V3 - UTA/
|
|
6026
|
+
File: examples/V3 - UTA/Websocket/ws-public.ts
|
|
5971
6027
|
================
|
|
5972
|
-
import {
|
|
6028
|
+
import {
|
|
6029
|
+
DefaultLogger,
|
|
6030
|
+
WebsocketClientV3,
|
|
6031
|
+
WS_KEY_MAP,
|
|
6032
|
+
} from '../../../src/index.js';
|
|
5973
6033
|
⋮----
|
|
5974
6034
|
// or
|
|
5975
|
-
// import { DefaultLogger, WS_KEY_MAP,
|
|
6035
|
+
// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api';
|
|
5976
6036
|
⋮----
|
|
5977
|
-
//
|
|
5978
|
-
// wsClient: TWSClient,
|
|
5979
|
-
// ): void {
|
|
5980
|
-
// wsClient.on('update', (data) => {
|
|
5981
|
-
// console.log('raw message received ', JSON.stringify(data));
|
|
5982
|
-
// });
|
|
5983
|
-
// wsClient.on('open', (data) => {
|
|
5984
|
-
// console.log('ws connected', data.wsKey);
|
|
5985
|
-
// });
|
|
5986
|
-
// wsClient.on('reconnect', ({ wsKey }) => {
|
|
5987
|
-
// console.log('ws automatically reconnecting.... ', wsKey);
|
|
5988
|
-
// });
|
|
5989
|
-
// wsClient.on('reconnected', (data) => {
|
|
5990
|
-
// console.log('ws has reconnected ', data?.wsKey);
|
|
5991
|
-
// });
|
|
5992
|
-
// wsClient.on('authenticated', (data) => {
|
|
5993
|
-
// console.log('ws has authenticated ', data?.wsKey);
|
|
5994
|
-
// });
|
|
5995
|
-
// }
|
|
6037
|
+
// console.log('WS raw message received ', JSON.stringify(data, null, 2));
|
|
5996
6038
|
⋮----
|
|
5997
|
-
|
|
5998
|
-
|
|
6039
|
+
/**
|
|
6040
|
+
* Public events
|
|
6041
|
+
*/
|
|
5999
6042
|
⋮----
|
|
6000
|
-
//
|
|
6001
|
-
// demoTrading: true,
|
|
6043
|
+
// You can subscribe to one topic at a time
|
|
6002
6044
|
⋮----
|
|
6003
|
-
//
|
|
6004
|
-
|
|
6005
|
-
//
|
|
6045
|
+
WS_KEY_MAP.v3Public, // This parameter points to private or public
|
|
6046
|
+
⋮----
|
|
6047
|
+
// Or multiple at once:
|
|
6048
|
+
⋮----
|
|
6049
|
+
// Topics are tracked per websocket type
|
|
6050
|
+
// The below example will pull a list of subscribed topics on that connection (e.g. all public topics), after a 5 second delay:
|
|
6051
|
+
|
|
6052
|
+
================
|
|
6053
|
+
File: examples/V3 - UTA/WS-API/ws-api-trade-raw.ts
|
|
6054
|
+
================
|
|
6055
|
+
import {
|
|
6056
|
+
DefaultLogger,
|
|
6057
|
+
WebsocketClientV3,
|
|
6058
|
+
WS_KEY_MAP,
|
|
6059
|
+
} from '../../../src/index.js';
|
|
6006
6060
|
⋮----
|
|
6007
|
-
|
|
6061
|
+
// or
|
|
6062
|
+
// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV3 } from 'bitget-api';
|
|
6008
6063
|
⋮----
|
|
6009
|
-
//
|
|
6010
|
-
//
|
|
6064
|
+
// If running from CLI in unix, you can pass env vars as such:
|
|
6065
|
+
// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts
|
|
6011
6066
|
⋮----
|
|
6012
|
-
//
|
|
6013
|
-
// This happens automatically but you can do this early before making any API calls, to prevent delays from a cold start.
|
|
6067
|
+
// console.log('WS raw message received ', JSON.stringify(data, null, 2));
|
|
6014
6068
|
⋮----
|
|
6015
6069
|
/**
|
|
6016
|
-
* Bitget's WebSocket API be used
|
|
6070
|
+
* Bitget's WebSocket API can be used via the sendWSAPIRequest() method.
|
|
6017
6071
|
*
|
|
6018
|
-
*
|
|
6019
|
-
* - route via the active WS API connection
|
|
6020
|
-
* - return a Promise, which automatically resolves/rejects when a matching response is received
|
|
6072
|
+
* Use the `WS_KEY_MAP.v3Private` connection key for any requests.
|
|
6021
6073
|
*
|
|
6022
6074
|
* Note: this requires V3/UTA API keys!
|
|
6075
|
+
* Note: for a better user experience, it is recommended to use the WebsocketAPIClient.
|
|
6023
6076
|
*/
|
|
6024
6077
|
⋮----
|
|
6078
|
+
// Use the V3 private wss connection URL
|
|
6079
|
+
⋮----
|
|
6025
6080
|
/**
|
|
6026
6081
|
* Place Order
|
|
6027
6082
|
* https://www.bitget.com/api-doc/uta/websocket/private/Place-Order-Channel#request-parameters
|
|
@@ -7026,6 +7081,174 @@ dist
|
|
|
7026
7081
|
repomix.sh
|
|
7027
7082
|
coverage
|
|
7028
7083
|
|
|
7084
|
+
================
|
|
7085
|
+
File: examples/V3 - UTA/WS-API/ws-api-client-trade.ts
|
|
7086
|
+
================
|
|
7087
|
+
import { DefaultLogger, WebsocketAPIClient } from '../../../src/index.js';
|
|
7088
|
+
⋮----
|
|
7089
|
+
// or
|
|
7090
|
+
// import { DefaultLogger, WS_KEY_MAP, WebsocketAPIClient } from 'bitget-api';
|
|
7091
|
+
⋮----
|
|
7092
|
+
// function attachEventHandlers<TWSClient extends WebsocketClientV3>(
|
|
7093
|
+
// wsClient: TWSClient,
|
|
7094
|
+
// ): void {
|
|
7095
|
+
// wsClient.on('update', (data) => {
|
|
7096
|
+
// console.log('raw message received ', JSON.stringify(data));
|
|
7097
|
+
// });
|
|
7098
|
+
// wsClient.on('open', (data) => {
|
|
7099
|
+
// console.log('ws connected', data.wsKey);
|
|
7100
|
+
// });
|
|
7101
|
+
// wsClient.on('reconnect', ({ wsKey }) => {
|
|
7102
|
+
// console.log('ws automatically reconnecting.... ', wsKey);
|
|
7103
|
+
// });
|
|
7104
|
+
// wsClient.on('reconnected', (data) => {
|
|
7105
|
+
// console.log('ws has reconnected ', data?.wsKey);
|
|
7106
|
+
// });
|
|
7107
|
+
// wsClient.on('authenticated', (data) => {
|
|
7108
|
+
// console.log('ws has authenticated ', data?.wsKey);
|
|
7109
|
+
// });
|
|
7110
|
+
// }
|
|
7111
|
+
⋮----
|
|
7112
|
+
// If running from CLI in unix, you can pass env vars as such:
|
|
7113
|
+
// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts
|
|
7114
|
+
⋮----
|
|
7115
|
+
// Whether to use the demo trading wss connection
|
|
7116
|
+
// demoTrading: true,
|
|
7117
|
+
⋮----
|
|
7118
|
+
// If you want your own event handlers instead of the default ones with logs,
|
|
7119
|
+
// disable this setting and see the `attachEventHandlers` example below:
|
|
7120
|
+
// attachEventListeners: false
|
|
7121
|
+
⋮----
|
|
7122
|
+
logger, // Optional: inject a custom logger
|
|
7123
|
+
⋮----
|
|
7124
|
+
// Optional, see above "attachEventListeners". Attach basic event handlers, so nothing is left unhandled
|
|
7125
|
+
// attachEventHandlers(wsClient.getWSClient());
|
|
7126
|
+
⋮----
|
|
7127
|
+
// Optional: prepare the WebSocket API connection in advance.
|
|
7128
|
+
// This happens automatically but you can do this early before making any API calls, to prevent delays from a cold start.
|
|
7129
|
+
⋮----
|
|
7130
|
+
/**
|
|
7131
|
+
* Bitget's WebSocket API be used like a REST API, through this SDK's WebsocketAPIClient. The WebsocketAPIClient is a utility class wrapped around WebsocketClientV3's sendWSAPIRequest() capabilities.
|
|
7132
|
+
*
|
|
7133
|
+
* Each request sent via the WebsocketAPIClient will automatically:
|
|
7134
|
+
* - route via the active WS API connection
|
|
7135
|
+
* - return a Promise, which automatically resolves/rejects when a matching response is received
|
|
7136
|
+
*
|
|
7137
|
+
* Note: this requires V3/UTA API keys!
|
|
7138
|
+
*/
|
|
7139
|
+
⋮----
|
|
7140
|
+
/**
|
|
7141
|
+
* Place Order
|
|
7142
|
+
* https://www.bitget.com/api-doc/uta/websocket/private/Place-Order-Channel#request-parameters
|
|
7143
|
+
*/
|
|
7144
|
+
⋮----
|
|
7145
|
+
/**
|
|
7146
|
+
const res = {
|
|
7147
|
+
"event": "trade",
|
|
7148
|
+
"id": "1750034396082",
|
|
7149
|
+
"category": "spot",
|
|
7150
|
+
"topic": "place-order",
|
|
7151
|
+
"args": [
|
|
7152
|
+
{
|
|
7153
|
+
"symbol": "BTCUSDT",
|
|
7154
|
+
"orderId": "xxxxxxxx",
|
|
7155
|
+
"clientOid": "xxxxxxxx",
|
|
7156
|
+
"cTime": "1750034397008"
|
|
7157
|
+
}
|
|
7158
|
+
],
|
|
7159
|
+
"code": "0",
|
|
7160
|
+
"msg": "success",
|
|
7161
|
+
"ts": "1750034397076"
|
|
7162
|
+
};
|
|
7163
|
+
*/
|
|
7164
|
+
⋮----
|
|
7165
|
+
/**
|
|
7166
|
+
* Batch Place Order Channel
|
|
7167
|
+
* https://www.bitget.com/api-doc/uta/websocket/private/Batch-Place-Order-Channel
|
|
7168
|
+
*/
|
|
7169
|
+
⋮----
|
|
7170
|
+
/**
|
|
7171
|
+
* Note: batch place will never reject the request, even if all orders were rejected. Check the "code" and "msg" properties for individual orders in the response, to detect batch place errors.
|
|
7172
|
+
*/
|
|
7173
|
+
⋮----
|
|
7174
|
+
/**
|
|
7175
|
+
const res = {
|
|
7176
|
+
"event": "trade",
|
|
7177
|
+
"id": "1750035029506",
|
|
7178
|
+
"category": "spot",
|
|
7179
|
+
"topic": "batch-place",
|
|
7180
|
+
"args": [
|
|
7181
|
+
{
|
|
7182
|
+
"code": "0",
|
|
7183
|
+
"msg": "Success",
|
|
7184
|
+
"symbol": "BTCUSDT",
|
|
7185
|
+
"orderId": "xxxxxxxx",
|
|
7186
|
+
"clientOid": "xxxxxxxx"
|
|
7187
|
+
},
|
|
7188
|
+
{
|
|
7189
|
+
"code": "0",
|
|
7190
|
+
"msg": "Success",
|
|
7191
|
+
"symbol": "BTCUSDT",
|
|
7192
|
+
"orderId": "xxxxxxxx",
|
|
7193
|
+
"clientOid": "xxxxxxxx"
|
|
7194
|
+
}
|
|
7195
|
+
],
|
|
7196
|
+
"code": "0",
|
|
7197
|
+
"msg": "Success",
|
|
7198
|
+
"ts": "1750035029925"
|
|
7199
|
+
}
|
|
7200
|
+
*/
|
|
7201
|
+
⋮----
|
|
7202
|
+
/**
|
|
7203
|
+
* Cancel Order
|
|
7204
|
+
* https://www.bitget.com/api-doc/uta/websocket/private/Cancel-Order-Channel
|
|
7205
|
+
*/
|
|
7206
|
+
⋮----
|
|
7207
|
+
/**
|
|
7208
|
+
const res = {
|
|
7209
|
+
"event": "trade",
|
|
7210
|
+
"id": "1750034870205",
|
|
7211
|
+
"topic": "cancel-order",
|
|
7212
|
+
"args": [
|
|
7213
|
+
{
|
|
7214
|
+
"orderId": "xxxxxxxx",
|
|
7215
|
+
"clientOid": "xxxxxxxx"
|
|
7216
|
+
}
|
|
7217
|
+
],
|
|
7218
|
+
"code": "0",
|
|
7219
|
+
"msg": "Success",
|
|
7220
|
+
"ts": "1750034870597"
|
|
7221
|
+
}
|
|
7222
|
+
*/
|
|
7223
|
+
⋮----
|
|
7224
|
+
/**
|
|
7225
|
+
* Batch Cancel Order
|
|
7226
|
+
* https://www.bitget.com/api-doc/uta/websocket/private/Batch-Cancel-Order-Channel
|
|
7227
|
+
*/
|
|
7228
|
+
⋮----
|
|
7229
|
+
/**
|
|
7230
|
+
const res = {
|
|
7231
|
+
"event": "trade",
|
|
7232
|
+
"id": "bb553cc0-c1fa-454e-956d-c96c8d715760",
|
|
7233
|
+
"topic": "batch-cancel",
|
|
7234
|
+
"args": [
|
|
7235
|
+
{
|
|
7236
|
+
"code": "0",
|
|
7237
|
+
"msg": "Success",
|
|
7238
|
+
"orderId": "xxxxxxxxxxxxx"
|
|
7239
|
+
},
|
|
7240
|
+
{
|
|
7241
|
+
"code": "25204",
|
|
7242
|
+
"msg": "Order does not exist",
|
|
7243
|
+
"orderId": "xxxxxxxxxxxxx"
|
|
7244
|
+
}
|
|
7245
|
+
],
|
|
7246
|
+
"code": "0",
|
|
7247
|
+
"msg": "Success",
|
|
7248
|
+
"ts": "1751980011084"
|
|
7249
|
+
}
|
|
7250
|
+
*/
|
|
7251
|
+
|
|
7029
7252
|
================
|
|
7030
7253
|
File: src/types/request/v2/futures.ts
|
|
7031
7254
|
================
|
|
@@ -7659,8 +7882,12 @@ export interface TransferRequestV3 {
|
|
|
7659
7882
|
amount: string;
|
|
7660
7883
|
coin: string;
|
|
7661
7884
|
symbol?: string;
|
|
7885
|
+
/** Enable automatic margin borrowing when balance insufficient. yes | no */
|
|
7886
|
+
allowBorrow?: 'yes' | 'no';
|
|
7662
7887
|
}
|
|
7663
7888
|
⋮----
|
|
7889
|
+
/** Enable automatic margin borrowing when balance insufficient. yes | no */
|
|
7890
|
+
⋮----
|
|
7664
7891
|
export interface GetTransferableCoinsRequestV3 {
|
|
7665
7892
|
fromType:
|
|
7666
7893
|
| 'spot'
|
|
@@ -7715,8 +7942,12 @@ export interface SubAccountTransferRequestV3 {
|
|
|
7715
7942
|
fromUserId: string;
|
|
7716
7943
|
toUserId: string;
|
|
7717
7944
|
clientOid: string;
|
|
7945
|
+
/** Enable automatic margin borrowing when balance insufficient. yes | no */
|
|
7946
|
+
allowBorrow?: 'yes' | 'no';
|
|
7718
7947
|
}
|
|
7719
7948
|
⋮----
|
|
7949
|
+
/** Enable automatic margin borrowing when balance insufficient. yes | no */
|
|
7950
|
+
⋮----
|
|
7720
7951
|
export interface GetSubUnifiedAssetsRequestV3 {
|
|
7721
7952
|
subUid?: string;
|
|
7722
7953
|
cursor?: string;
|
|
@@ -8631,7 +8862,8 @@ export interface InstrumentV3 {
|
|
|
8631
8862
|
deliveryTime?: string;
|
|
8632
8863
|
deliveryStartTime?: string;
|
|
8633
8864
|
deliveryPeriod?: string;
|
|
8634
|
-
|
|
8865
|
+
/** Launch time - Unix millisecond timestamp. Null for some margin pairs. */
|
|
8866
|
+
launchTime?: string | null;
|
|
8635
8867
|
fundInterval?: string;
|
|
8636
8868
|
minLeverage?: string;
|
|
8637
8869
|
maxLeverage?: string;
|
|
@@ -8648,8 +8880,37 @@ export interface InstrumentV3 {
|
|
|
8648
8880
|
⋮----
|
|
8649
8881
|
// Futures specific fields
|
|
8650
8882
|
⋮----
|
|
8883
|
+
/** Launch time - Unix millisecond timestamp. Null for some margin pairs. */
|
|
8884
|
+
⋮----
|
|
8651
8885
|
// Margin specific fields
|
|
8652
8886
|
⋮----
|
|
8887
|
+
export interface MarketFeeGroupLabelV3 {
|
|
8888
|
+
weight: string;
|
|
8889
|
+
label: string;
|
|
8890
|
+
symbols: string[];
|
|
8891
|
+
}
|
|
8892
|
+
⋮----
|
|
8893
|
+
export interface MarketFeeGroupTierV3 {
|
|
8894
|
+
level: string;
|
|
8895
|
+
makerFeeRate: string;
|
|
8896
|
+
}
|
|
8897
|
+
⋮----
|
|
8898
|
+
export interface MarketFeeGroupV3 {
|
|
8899
|
+
category: string;
|
|
8900
|
+
group: string;
|
|
8901
|
+
labelList: MarketFeeGroupLabelV3[];
|
|
8902
|
+
tierList: MarketFeeGroupTierV3[];
|
|
8903
|
+
}
|
|
8904
|
+
⋮----
|
|
8905
|
+
export interface MarketScoreWeightV3 {
|
|
8906
|
+
category: string;
|
|
8907
|
+
label: string;
|
|
8908
|
+
symbol: string;
|
|
8909
|
+
requiredSpread: string;
|
|
8910
|
+
minMakerVolume: string;
|
|
8911
|
+
weight: string;
|
|
8912
|
+
}
|
|
8913
|
+
⋮----
|
|
8653
8914
|
export interface OrderBookV3 {
|
|
8654
8915
|
a: string[][]; // asks - [price, size]
|
|
8655
8916
|
b: string[][]; // bids - [price, size]
|
|
@@ -9258,6 +9519,9 @@ File: README.md
|
|
|
9258
9519
|
|
|
9259
9520
|
[1]: https://www.npmjs.com/package/bitget-api
|
|
9260
9521
|
|
|
9522
|
+
> [!TIP]
|
|
9523
|
+
> Upcoming change: As part of the [Siebly.io](https://siebly.io/?ref=ghbitget) brand, this SDK will soon be hosted under the [Siebly.io GitHub organisation](https://github.com/sieblyio). The migration is seamless and requires no user changes.
|
|
9524
|
+
|
|
9261
9525
|
Updated & performant JavaScript & Node.js SDK for the Bitget V2 REST APIs and WebSockets:
|
|
9262
9526
|
|
|
9263
9527
|
- Professional, robust & performant Bitget SDK with extensive production use in live trading environments.
|
|
@@ -12402,12 +12666,22 @@ import {
|
|
|
12402
12666
|
import {
|
|
12403
12667
|
BindUidRequestV3,
|
|
12404
12668
|
GetEnsureCoinsRequestV3,
|
|
12669
|
+
GetLoanBorrowHistoryRequestV3,
|
|
12670
|
+
GetLoanBorrowOngoingRequestV3,
|
|
12671
|
+
GetLoanCoinsRequestV3,
|
|
12672
|
+
GetLoanInterestRequestV3,
|
|
12405
12673
|
GetLoanOrderRequestV3,
|
|
12674
|
+
GetLoanPledgeRateHistoryRequestV3,
|
|
12675
|
+
GetLoanReducesRequestV3,
|
|
12676
|
+
GetLoanRepayHistoryRequestV3,
|
|
12406
12677
|
GetLTVConvertRequestV3,
|
|
12407
12678
|
GetProductInfosRequestV3,
|
|
12408
12679
|
GetRepaidHistoryRequestV3,
|
|
12409
12680
|
GetSymbolsRequestV3,
|
|
12410
12681
|
GetTransferedRequestV3,
|
|
12682
|
+
LoanBorrowRequestV3,
|
|
12683
|
+
LoanRepayRequestV3,
|
|
12684
|
+
LoanRevisePledgeRequestV3,
|
|
12411
12685
|
} from './types/request/v3/loan.js';
|
|
12412
12686
|
import {
|
|
12413
12687
|
GetCandlesRequestV3,
|
|
@@ -12418,6 +12692,8 @@ import {
|
|
|
12418
12692
|
GetIndexComponentsRequestV3,
|
|
12419
12693
|
GetInstrumentsRequestV3,
|
|
12420
12694
|
GetMarginLoansRequestV3,
|
|
12695
|
+
GetMarketFeeGroupRequestV3,
|
|
12696
|
+
GetMarketScoreWeightsRequestV3,
|
|
12421
12697
|
GetOpenInterestRequestV3,
|
|
12422
12698
|
GetOrderBookRequestV3,
|
|
12423
12699
|
GetPositionTierRequestV3,
|
|
@@ -12490,8 +12766,19 @@ import {
|
|
|
12490
12766
|
import {
|
|
12491
12767
|
BindUidResponseV3,
|
|
12492
12768
|
CoinInfoV3,
|
|
12769
|
+
GetLoanCoinsResponseV3,
|
|
12770
|
+
GetLoanDebtsResponseV3,
|
|
12771
|
+
GetLoanInterestResponseV3,
|
|
12772
|
+
LoanBorrowHistoryItemV3,
|
|
12773
|
+
LoanBorrowOngoingItemV3,
|
|
12774
|
+
LoanBorrowResponseV3,
|
|
12493
12775
|
LoanOrderV3,
|
|
12776
|
+
LoanPledgeRateHistoryItemV3,
|
|
12494
12777
|
LoanProductInfoV3,
|
|
12778
|
+
LoanReduceItemV3,
|
|
12779
|
+
LoanRepayHistoryItemV3,
|
|
12780
|
+
LoanRepayResponseV3,
|
|
12781
|
+
LoanRevisePledgeResponseV3,
|
|
12495
12782
|
LoanSymbolsV3,
|
|
12496
12783
|
LoanTransfersV3,
|
|
12497
12784
|
LTVConvertResponseV3,
|
|
@@ -12506,6 +12793,8 @@ import {
|
|
|
12506
12793
|
IndexPriceComponentsV3,
|
|
12507
12794
|
InstrumentV3,
|
|
12508
12795
|
MarginLoanV3,
|
|
12796
|
+
MarketFeeGroupV3,
|
|
12797
|
+
MarketScoreWeightV3,
|
|
12509
12798
|
OpenInterestV3,
|
|
12510
12799
|
OrderBookV3,
|
|
12511
12800
|
PositionTierV3,
|
|
@@ -12595,6 +12884,20 @@ getInstruments(
|
|
|
12595
12884
|
params: GetInstrumentsRequestV3,
|
|
12596
12885
|
): Promise<APIResponse<InstrumentV3[]>>
|
|
12597
12886
|
⋮----
|
|
12887
|
+
/**
|
|
12888
|
+
* Get Market Maker Fee Group - Query fee rate tiers and grouping
|
|
12889
|
+
*/
|
|
12890
|
+
getMarketFeeGroup(
|
|
12891
|
+
params: GetMarketFeeGroupRequestV3,
|
|
12892
|
+
): Promise<APIResponse<MarketFeeGroupV3[]>>
|
|
12893
|
+
⋮----
|
|
12894
|
+
/**
|
|
12895
|
+
* Get Market Maker Score Weight - Query score weights per symbol
|
|
12896
|
+
*/
|
|
12897
|
+
getMarketScoreWeights(
|
|
12898
|
+
params?: GetMarketScoreWeightsRequestV3,
|
|
12899
|
+
): Promise<APIResponse<MarketScoreWeightV3[]>>
|
|
12900
|
+
⋮----
|
|
12598
12901
|
/**
|
|
12599
12902
|
* Get Tickers
|
|
12600
12903
|
*/
|
|
@@ -13256,6 +13559,87 @@ bindLoanUid(
|
|
|
13256
13559
|
params: BindUidRequestV3,
|
|
13257
13560
|
): Promise<APIResponse<BindUidResponseV3>>
|
|
13258
13561
|
⋮----
|
|
13562
|
+
/**
|
|
13563
|
+
*
|
|
13564
|
+
* =====Unified Account Staking & Lending (Crypto Loans)===== /api/v3/loan/*
|
|
13565
|
+
*
|
|
13566
|
+
*/
|
|
13567
|
+
⋮----
|
|
13568
|
+
/**
|
|
13569
|
+
* Get Loan Coins - Query supported collateral currencies and borrowable coins
|
|
13570
|
+
*/
|
|
13571
|
+
getLoanCoins(
|
|
13572
|
+
params?: GetLoanCoinsRequestV3,
|
|
13573
|
+
): Promise<APIResponse<GetLoanCoinsResponseV3>>
|
|
13574
|
+
⋮----
|
|
13575
|
+
/**
|
|
13576
|
+
* Get Loan Interest - Query estimated interest and borrowable amount
|
|
13577
|
+
*/
|
|
13578
|
+
getLoanInterest(
|
|
13579
|
+
params: GetLoanInterestRequestV3,
|
|
13580
|
+
): Promise<APIResponse<GetLoanInterestResponseV3>>
|
|
13581
|
+
⋮----
|
|
13582
|
+
/**
|
|
13583
|
+
* Borrow - Borrow coins
|
|
13584
|
+
*/
|
|
13585
|
+
loanBorrow(
|
|
13586
|
+
params: LoanBorrowRequestV3,
|
|
13587
|
+
): Promise<APIResponse<LoanBorrowResponseV3>>
|
|
13588
|
+
⋮----
|
|
13589
|
+
/**
|
|
13590
|
+
* Get Borrow Ongoing - Query current borrowings
|
|
13591
|
+
*/
|
|
13592
|
+
getLoanBorrowOngoing(
|
|
13593
|
+
params?: GetLoanBorrowOngoingRequestV3,
|
|
13594
|
+
): Promise<APIResponse<LoanBorrowOngoingItemV3[]>>
|
|
13595
|
+
⋮----
|
|
13596
|
+
/**
|
|
13597
|
+
* Get Borrow History - Query borrowing history
|
|
13598
|
+
*/
|
|
13599
|
+
getLoanBorrowHistory(
|
|
13600
|
+
params: GetLoanBorrowHistoryRequestV3,
|
|
13601
|
+
): Promise<APIResponse<LoanBorrowHistoryItemV3[]>>
|
|
13602
|
+
⋮----
|
|
13603
|
+
/**
|
|
13604
|
+
* Repay - Repay coins
|
|
13605
|
+
*/
|
|
13606
|
+
loanRepay(
|
|
13607
|
+
params: LoanRepayRequestV3,
|
|
13608
|
+
): Promise<APIResponse<LoanRepayResponseV3>>
|
|
13609
|
+
⋮----
|
|
13610
|
+
/**
|
|
13611
|
+
* Get Repay History - Query repayment history
|
|
13612
|
+
*/
|
|
13613
|
+
getLoanRepayHistory(
|
|
13614
|
+
params: GetLoanRepayHistoryRequestV3,
|
|
13615
|
+
): Promise<APIResponse<LoanRepayHistoryItemV3[]>>
|
|
13616
|
+
⋮----
|
|
13617
|
+
/**
|
|
13618
|
+
* Revise Pledge - Adjust collateral ratio
|
|
13619
|
+
*/
|
|
13620
|
+
loanRevisePledge(
|
|
13621
|
+
params: LoanRevisePledgeRequestV3,
|
|
13622
|
+
): Promise<APIResponse<LoanRevisePledgeResponseV3>>
|
|
13623
|
+
⋮----
|
|
13624
|
+
/**
|
|
13625
|
+
* Get Pledge Rate History - Query collateral ratio history
|
|
13626
|
+
*/
|
|
13627
|
+
getLoanPledgeRateHistory(
|
|
13628
|
+
params: GetLoanPledgeRateHistoryRequestV3,
|
|
13629
|
+
): Promise<APIResponse<LoanPledgeRateHistoryItemV3[]>>
|
|
13630
|
+
⋮----
|
|
13631
|
+
/**
|
|
13632
|
+
* Get Loan Debts - Query assets and liabilities
|
|
13633
|
+
*/
|
|
13634
|
+
getLoanDebts(): Promise<APIResponse<GetLoanDebtsResponseV3>>
|
|
13635
|
+
⋮----
|
|
13636
|
+
/**
|
|
13637
|
+
* Get Loan Reduces - Query liquidation records
|
|
13638
|
+
*/
|
|
13639
|
+
getLoanReduces(
|
|
13640
|
+
params: GetLoanReducesRequestV3,
|
|
13641
|
+
): Promise<APIResponse<LoanReduceItemV3[]>>
|
|
13642
|
+
⋮----
|
|
13259
13643
|
/**
|
|
13260
13644
|
*
|
|
13261
13645
|
* =====Strategy======= endpoints
|
|
@@ -13429,7 +13813,7 @@ File: package.json
|
|
|
13429
13813
|
================
|
|
13430
13814
|
{
|
|
13431
13815
|
"name": "bitget-api",
|
|
13432
|
-
"version": "3.1.
|
|
13816
|
+
"version": "3.1.5",
|
|
13433
13817
|
"description": "Complete Node.js & JavaScript SDK for Bitget V1-V3 REST APIs & WebSockets, with TypeScript & end-to-end tests.",
|
|
13434
13818
|
"scripts": {
|
|
13435
13819
|
"test": "jest",
|
|
@@ -13460,7 +13844,7 @@ File: package.json
|
|
|
13460
13844
|
"llms.txt"
|
|
13461
13845
|
],
|
|
13462
13846
|
"type": "module",
|
|
13463
|
-
"author": "Tiago Siebler (https://
|
|
13847
|
+
"author": "Tiago Siebler (https://siebly.io)",
|
|
13464
13848
|
"contributors": [],
|
|
13465
13849
|
"dependencies": {
|
|
13466
13850
|
"axios": "^1.13.2",
|