Skip to content

Commit e6b950f

Browse files
cursoragentJJ-Cro
andcommitted
feat(1.6.5): sync Gate API through v4.106.160 and fix TestNet hosts
TestNet REST `futuresTestnet` now uses https://api-testnet.gateapi.io/api/v4. `baseUrlKey: 'testnet'` is the same host for spot and futures. `futuresTestnet` stays as an alias. WebSocket TestNet: - spot: wss://ws-testnet.gate.com/v4/ws/spot - options: wss://ws-testnet.gate.com/v4/ws/options - USDT perpetual, BTC perpetual, and delivery hosts still match current Gate docs Changelog: - v4.106.160: updateFuturesPriceTriggeredOrder uses PUT /futures/{settle}/price_orders/amend/{order_id}; order_id stays in the body - v4.106.159: stock trade_status is pre_market | open | post_market - v4.106.158: OTC fiat and stablecoin order lists use data.lists - v4.106.148: stock trade_mode, order status, and finish_as enums - v4.106.147: futures account_book type dividend - Futures place-order requests accept tpsl_tp_bbo_type and tpsl_sl_bbo_type Skipped: - stock time_in_force GTC: docs only list day - stock client_order_id: already on CreateStockOrderReq - tpsl bbo fields on FuturesOrder responses: already present Co-authored-by: Jerko J <JJ-Cro@users.noreply.github.com>
1 parent 9dc4d70 commit e6b950f

15 files changed

Lines changed: 162 additions & 39 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ client
228228
});
229229
```
230230

231+
TestNet REST for spot and futures is `baseUrlKey: 'testnet'` (`https://api-testnet.gateapi.io/api/v4`). `baseUrlKey: 'futuresTestnet'` is that same host, kept so older configs keep working. WebSocket TestNet is `useTestnet: true` on `WebsocketClient`.
232+
231233
See [RestClient](./src/RestClient.ts) for further information, or the [examples](./examples/) for lots of usage examples.
232234

233235
## WebSockets

‎docs/GATE_SDK_QUICKSTART_GUIDE.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,11 +1738,12 @@ Gate TestNet is a separate environment with separate credentials. Use it for all
17381738
| REST API | `https://api-testnet.gateapi.io/api/v4` |
17391739
| Spot WebSocket | `wss://ws-testnet.gate.com/v4/ws/spot` |
17401740
| USDT perpetual WebSocket | `wss://ws-testnet.gate.com/v4/ws/futures/usdt` |
1741+
| Options WebSocket | `wss://ws-testnet.gate.com/v4/ws/options` |
17411742

1742-
Set the REST API host with `baseUrl` and the WebSocket host with `wsUrl`. Prefer explicit hosts for TestNet examples:
1743+
Set the REST API host with `baseUrl` or `baseUrlKey`, and the WebSocket host with `wsUrl` or `useTestnet: true`. Prefer explicit hosts for TestNet examples:
17431744

1744-
- Spot WebSocket TestNet is not wired through `useTestnet: true` in this SDK. The Spot testnet map entry is a stub (`NoTestnetForSpotWebsockets!`), so set `wsUrl` to the Spot TestNet host above.
1745-
- For Futures-only REST TestNet, the SDK also accepts `baseUrlKey: 'futuresTestnet'`, which resolves to `https://fx-api-testnet.gateio.ws/api/v4`. The Global TestNet REST host in the table is the host used by the Spot and Futures order examples in this guide.
1745+
- `baseUrlKey: 'testnet'` uses `https://api-testnet.gateapi.io/api/v4` for spot and futures. `baseUrlKey: 'futuresTestnet'` is the same host, kept so older configs keep working.
1746+
- `useTestnet: true` selects the TestNet WebSocket host for that connection, including Spot and Options. BTC perpetual and delivery TestNet hosts stay on the URLs in the current Gate docs (`wss://fx-ws-testnet.gateio.ws/...`). Announcements still have no TestNet host.
17461747

17471748
```javascript
17481749
import { RestClient, WebsocketClient } from 'gateio-api';

‎examples/Rest/futures/testnet.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ const gateRestClient = new RestClient({
1919
*/
2020

2121
/*
22-
* Futures TestNet trading:
23-
* 'https://fx-api-testnet.gateio.ws/api/v4'
22+
* Futures TestNet trading (alias of `testnet`, spot and futures):
23+
* 'https://api-testnet.gateapi.io/api/v4'
24+
* Older host https://fx-api-testnet.gateio.ws/api/v4 now returns 502.
25+
* baseUrlKey: 'testnet' is the same host.
2426
*/
2527
baseUrlKey: 'futuresTestnet',
2628

‎package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gateio-api",
3-
"version": "1.6.4",
3+
"version": "1.6.5",
44
"description": "Complete & Robust Node.js SDK for Gate.com's REST APIs, WebSockets & WebSocket APIs, with TypeScript declarations.",
55
"scripts": {
66
"clean": "rm -rf dist/*",

‎src/RestClient.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3548,16 +3548,22 @@ export class RestClient extends BaseRestClient {
35483548
/**
35493549
* Update a single price-triggered order
35503550
*
3551+
* v4.106.160: `PUT /futures/{settle}/price_orders/amend/{order_id}`.
3552+
* `order_id` is required in the path and is still sent in the JSON body.
3553+
*
35513554
* @param params Parameters for updating a price-triggered order
35523555
* @returns Promise<TriggerOrderResponse>
35533556
*/
35543557
updateFuturesPriceTriggeredOrder(
35553558
params: UpdateFuturesPriceTriggeredOrderReq,
35563559
): Promise<TriggerOrderResponse> {
3557-
const { settle, ...body } = params;
3558-
return this.putPrivate(`/futures/${settle}/price_orders/amend`, {
3559-
body: body,
3560-
});
3560+
const { settle, order_id, ...rest } = params;
3561+
return this.putPrivate(
3562+
`/futures/${settle}/price_orders/amend/${order_id}`,
3563+
{
3564+
body: { order_id, ...rest },
3565+
},
3566+
);
35613567
}
35623568

35633569
/**

‎src/lib/requestUtils.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ export interface RestClientOptions {
2424
**/
2525
baseUrl?: string;
2626

27-
// manually override with one of the known base URLs in the library
27+
/**
28+
* Built-in Gate API v4 host.
29+
* `testnet` and `futuresTestnet` both use https://api-testnet.gateapi.io/api/v4
30+
* (spot and futures). `futuresTestnet` is kept as an alias of `testnet`.
31+
*/
2832
baseUrlKey?: GateBaseUrlKey;
2933

3034
/** Default: true. whether to try and post-process request exceptions (and throw them). */
@@ -79,10 +83,15 @@ export function serializeParams<T extends Record<string, any> | undefined = {}>(
7983
return queryString ? prefixWith + queryString : queryString;
8084
}
8185

86+
/** Global TestNet REST host. Gate docs: spot and futures. */
87+
const GATE_TESTNET_REST_URL = 'https://api-testnet.gateapi.io/api/v4';
88+
8289
const GATE_BASE_URLS: Record<GateBaseUrlKey, string> = {
8390
live: 'https://api.gateio.ws/api/v4',
8491
futuresLiveAlternative: 'https://fx-api.gateio.ws/api/v4',
85-
futuresTestnet: 'https://fx-api-testnet.gateio.ws/api/v4',
92+
testnet: GATE_TESTNET_REST_URL,
93+
// Alias of `testnet`. Previously https://fx-api-testnet.gateio.ws/api/v4 (HTTP 502).
94+
futuresTestnet: GATE_TESTNET_REST_URL,
8695
};
8796

8897
export function getRestBaseUrl(restClientOptions: RestClientOptions): string {

‎src/lib/websocket/websocket-util.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export const WS_BASE_URL_MAP: Record<
101101
> = {
102102
spotV4: {
103103
livenet: 'wss://api.gateio.ws/ws/v4/',
104-
testnet: 'NoTestnetForSpotWebsockets!',
104+
// https://www.gate.com/docs/developers/apiv4/ws/en/
105+
testnet: 'wss://ws-testnet.gate.com/v4/ws/spot',
105106
},
106107
perpFuturesUSDTV4: {
107108
livenet: 'wss://fx-ws.gateio.ws/v4/ws/usdt',
@@ -121,7 +122,8 @@ export const WS_BASE_URL_MAP: Record<
121122
},
122123
optionsV4: {
123124
livenet: 'wss://op-ws.gateio.live/v4/ws',
124-
testnet: 'wss://op-ws-testnet.gateio.live/v4/ws',
125+
// https://www.gate.com/docs/developers/options/ws/en/
126+
testnet: 'wss://ws-testnet.gate.com/v4/ws/options',
125127
},
126128
announcementsV4: {
127129
livenet: 'wss://api.gateio.ws/ws/v4/ann',

‎src/types/request/futures.ts‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,27 @@ export interface GetRiskLimitTableReq {
7373
table_id: string;
7474
}
7575

76+
/** Change types for `GET /futures/{settle}/account_book`. */
77+
export type FuturesAccountBookType =
78+
| 'dnw'
79+
| 'pnl'
80+
| 'fee'
81+
| 'refr'
82+
| 'fund'
83+
| 'point_dnw'
84+
| 'point_fee'
85+
| 'point_refr'
86+
| 'bonus_offset'
87+
| 'dividend'; // v4.106.147: dividend payout
88+
7689
export interface GetFuturesAccountBookReq {
7790
settle: FuturesSettle;
7891
contract?: string;
7992
limit?: number;
8093
offset?: number;
8194
from?: number;
8295
to?: number;
83-
type?:
84-
| 'dnw'
85-
| 'pnl'
86-
| 'fee'
87-
| 'refr'
88-
| 'fund'
89-
| 'point_dnw'
90-
| 'point_fee'
91-
| 'point_refr'
92-
| 'bonus_offset';
96+
type?: FuturesAccountBookType;
9397
}
9498

9599
export interface GetFuturesADLRiskStatesReq {
@@ -136,6 +140,10 @@ export interface SubmitFuturesOrderReq {
136140
action_mode?: 'ACK' | 'RESULT' | 'FULL';
137141
tpsl_tp_trigger_price?: string;
138142
tpsl_sl_trigger_price?: string;
143+
/** BBO price type for the take-profit leg */
144+
tpsl_tp_bbo_type?: string;
145+
/** BBO price type for the stop-loss leg */
146+
tpsl_sl_bbo_type?: string;
139147
pos_margin_mode?: 'isolated' | 'cross';
140148
}
141149

‎src/types/response/futures.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* ==========================================================================================================================
44
*/
55

6+
import type { FuturesAccountBookType } from '../request/futures.js';
7+
68
export interface FuturesOrderBook {
79
id?: number;
810
current: number;
@@ -169,7 +171,8 @@ export interface FuturesAccountBookRecord {
169171
time: number;
170172
change: string;
171173
balance: string;
172-
type: string;
174+
/** v4.106.147: includes `dividend` (dividend payout) */
175+
type: FuturesAccountBookType;
173176
text: string;
174177
contract?: string;
175178
trade_id: string;

0 commit comments

Comments
 (0)