@yuants/vendor-gate 0.5.4 → 0.6.0
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/api/public-api.js +13 -1
- package/dist/api/public-api.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/services/interest-rate-service.js +35 -0
- package/dist/services/interest-rate-service.js.map +1 -0
- package/dist/services/ohlc-service.js +114 -0
- package/dist/services/ohlc-service.js.map +1 -0
- package/lib/api/public-api.d.ts +52 -0
- package/lib/api/public-api.d.ts.map +1 -1
- package/lib/api/public-api.js +16 -2
- package/lib/api/public-api.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/services/interest-rate-service.d.ts +2 -0
- package/lib/services/interest-rate-service.d.ts.map +1 -0
- package/lib/services/interest-rate-service.js +37 -0
- package/lib/services/interest-rate-service.js.map +1 -0
- package/lib/services/ohlc-service.d.ts +2 -0
- package/lib/services/ohlc-service.d.ts.map +1 -0
- package/lib/services/ohlc-service.js +116 -0
- package/lib/services/ohlc-service.js.map +1 -0
- package/package.json +3 -2
- package/temp/package-deps.json +10 -7
package/dist/api/public-api.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { rateLimiter } from './rate-limiter';
|
|
2
1
|
import { requestPublic } from './http-client';
|
|
2
|
+
import { rateLimiter } from './rate-limiter';
|
|
3
3
|
/**
|
|
4
4
|
* 查询所有的合约信息
|
|
5
5
|
*
|
|
@@ -16,6 +16,18 @@ export const getFuturesContracts = (settle, params) => requestPublic('GET', `/fu
|
|
|
16
16
|
* https://www.gate.io/docs/developers/apiv4/zh_CN/#%E5%90%88%E7%BA%A6%E5%B8%82%E5%9C%BA%E5%8E%86%E5%8F%B2%E8%B5%84%E9%87%91%E8%B4%B9%E7%8E%87
|
|
17
17
|
*/
|
|
18
18
|
export const getFutureFundingRate = (settle, params) => requestPublic('GET', `/futures/${settle}/funding_rate`, params);
|
|
19
|
+
/**
|
|
20
|
+
* 合约市场 K 线图
|
|
21
|
+
*
|
|
22
|
+
* https://www.gate.com/docs/developers/apiv4/zh_CN/#%E5%90%88%E7%BA%A6%E5%B8%82%E5%9C%BA-k-%E7%BA%BF%E5%9B%BE
|
|
23
|
+
*/
|
|
24
|
+
export const getFuturesCandlesticks = (settle, params) => requestPublic('GET', `/futures/${settle}/candlesticks`, params);
|
|
25
|
+
/**
|
|
26
|
+
* 市场 K 线图
|
|
27
|
+
*
|
|
28
|
+
* https://www.gate.com/docs/developers/apiv4/zh_CN/#%E5%B8%82%E5%9C%BA-k-%E7%BA%BF%E5%9B%BE
|
|
29
|
+
*/
|
|
30
|
+
export const getSpotCandlesticks = (params) => requestPublic('GET', `/spot/candlesticks`, params);
|
|
19
31
|
/**
|
|
20
32
|
* 查询合约市场深度信息
|
|
21
33
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,MAAc,EACd,MAA4C,EA8C5C,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,YAAY,MAAM,YAAY,EAAE,MAAM,CAAC,CAAC;AAElE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,MAAc,EACd,MAAyF,EAMzF,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,YAAY,MAAM,eAAe,EAAE,MAAM,CAAC,CAAC;AAErE;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,MAAc,EACd,MAMC,EAgBD,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,YAAY,MAAM,eAAe,EAAE,MAAM,CAAC,CAAC;AAErE;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAMnC,EAQC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,oBAAoB,EAAE,MAAM,CAAC,CAAC;AAExD;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,MAAc,EACd,MAKC,EAaA,EAAE,CACH,WAAW,CAAC,QAAQ,CAAC,sBAAsB,MAAM,EAAE,EAAE,GAAG,EAAE,KAAM,EAAE,GAAG,EAAE,CACrE,aAAa,CAAC,KAAK,EAAE,YAAY,MAAM,aAAa,EAAE,MAAM,CAAC,CAC9D,CAAC;AAEJ;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,MAAc,EACd,MAA8B,EAyB9B,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,YAAY,MAAM,UAAU,EAAE,MAAM,CAAC,CAAC;AAEhE;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAG9B,EAoBC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAqBlC,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC","sourcesContent":["import { requestPublic } from './http-client';\nimport { rateLimiter } from './rate-limiter';\n\n/**\n * 查询所有的合约信息\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E6%89%80%E6%9C%89%E7%9A%84%E5%90%88%E7%BA%A6%E4%BF%A1%E6%81%AF\n */\nexport const getFuturesContracts = (\n settle: string,\n params?: { limit?: number; offset?: number },\n): Promise<\n {\n name: string;\n type: string;\n quanto_multiplier: string;\n ref_discount_rate: string;\n order_price_deviate: string;\n maintenance_rate: string;\n mark_type: string;\n last_price: string;\n mark_price: string;\n index_price: string;\n funding_rate_indicative: string;\n mark_price_round: string;\n funding_offset: number;\n in_delisting: boolean;\n risk_limit_base: string;\n interest_rate: string;\n order_price_round: string;\n order_size_min: number;\n ref_rebate_rate: string;\n funding_interval: number;\n risk_limit_step: string;\n leverage_min: string;\n leverage_max: string;\n risk_limit_max: string;\n maker_fee_rate: string;\n taker_fee_rate: string;\n funding_rate: string;\n order_size_max: number;\n funding_next_apply: number;\n short_users: number;\n config_change_time: number;\n trade_size: number;\n position_size: number;\n long_users: number;\n funding_impact_value: string;\n orders_limit: number;\n trade_id: number;\n orderbook_id: number;\n enable_bonus: boolean;\n enable_credit: boolean;\n create_time: number;\n funding_cap_ratio: string;\n }[]\n> => requestPublic('GET', `/futures/${settle}/contracts`, params);\n\n/**\n * 合约市场历史资金费率\n *\n * - Note: 该接口返回的数据是按照时间倒序排列的\n * - Note: limit 参数最大值为 1000\n * - Note: t 字段为秒级时间戳 (Unix Second),r 字段为资金费率 (0-1 单位)\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E5%90%88%E7%BA%A6%E5%B8%82%E5%9C%BA%E5%8E%86%E5%8F%B2%E8%B5%84%E9%87%91%E8%B4%B9%E7%8E%87\n */\nexport const getFutureFundingRate = (\n settle: string,\n params: { contract: string; limit?: number; from?: number; to?: number; offset?: number },\n): Promise<\n {\n t: number;\n r: string;\n }[]\n> => requestPublic('GET', `/futures/${settle}/funding_rate`, params);\n\n/**\n * 合约市场 K 线图\n *\n * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E5%90%88%E7%BA%A6%E5%B8%82%E5%9C%BA-k-%E7%BA%BF%E5%9B%BE\n */\nexport const getFuturesCandlesticks = (\n settle: string,\n params: {\n contract: string;\n interval: string;\n from?: number;\n to?: number;\n limit?: number;\n },\n): Promise<\n Array<{\n /** Unix second */\n t: number;\n /** Open */\n o: string;\n /** High */\n h: string;\n /** Low */\n l: string;\n /** Close */\n c: string;\n /** Volume */\n v: string;\n }>\n> => requestPublic('GET', `/futures/${settle}/candlesticks`, params);\n\n/**\n * 市场 K 线图\n *\n * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E5%B8%82%E5%9C%BA-k-%E7%BA%BF%E5%9B%BE\n */\nexport const getSpotCandlesticks = (params: {\n currency_pair: string;\n interval: string;\n from?: number;\n to?: number;\n limit?: number;\n}): Promise<\n Array<\n /**\n * [t, v, c, h, l, o]\n * - t: Unix second\n */\n [string, string, string, string, string, string]\n >\n> => requestPublic('GET', `/spot/candlesticks`, params);\n\n/**\n * 查询合约市场深度信息\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E5%90%88%E7%BA%A6%E5%B8%82%E5%9C%BA%E6%B7%B1%E5%BA%A6%E4%BF%A1%E6%81%AF\n */\nexport const getFuturesOrderBook = async (\n settle: string,\n params: {\n contract: string;\n interval?: string;\n limit?: number;\n with_id?: boolean;\n },\n): Promise<{\n id: number;\n current: number;\n update: number;\n asks: {\n p: string;\n s: string;\n }[];\n bids: {\n p: string;\n s: string;\n }[];\n}> =>\n rateLimiter.schedule(`futures-order-book:${settle}`, 200, 10_000, () =>\n requestPublic('GET', `/futures/${settle}/order_book`, params),\n );\n\n/**\n * 获取所有合约交易行情统计\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E6%89%80%E6%9C%89%E5%90%88%E7%BA%A6%E4%BA%A4%E6%98%93%E8%A1%8C%E6%83%85%E7%BB%9F%E8%AE%A1\n */\nexport const getFuturesTickers = (\n settle: string,\n params?: { contract?: string },\n): Promise<\n {\n contract: string;\n last: string;\n change_percentage: string;\n total_size: string;\n low_24h: string;\n high_24h: string;\n volume_24h: string;\n volume_24h_btc: string;\n volume_24h_usd: string;\n volume_24h_base: string;\n volume_24h_quote: string;\n volume_24h_settle: string;\n mark_price: string;\n funding_rate: string;\n funding_rate_indicative: string;\n index_price: string;\n quanto_base_rate: string;\n basis_rate: string;\n basis_value: string;\n lowest_ask: string;\n highest_bid: string;\n }[]\n> => requestPublic('GET', `/futures/${settle}/tickers`, params);\n\n/**\n * 获取交易对 ticker 信息\n *\n * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E4%BA%A4%E6%98%93%E5%AF%B9-ticker-%E4%BF%A1%E6%81%AF\n */\nexport const getSpotTickers = (params: {\n currency_pair?: string;\n timezone?: string;\n}): Promise<\n Array<{\n currency_pair: string;\n last: string;\n lowest_ask: string;\n lowest_size: string;\n highest_bid: string;\n highest_size: string;\n change_percentage: string;\n change_utc0: string;\n change_utc8: string;\n base_volume: string;\n quote_volume: string;\n high_24h: string;\n low_24h: string;\n etf_net_value: string;\n etf_pre_net_value: string;\n etf_pre_timestamp: string;\n etf_leverage: string;\n }>\n> => requestPublic('GET', `/spot/tickers`, params);\n\n/**\n * 查询支持的所有现货交易对\n * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E6%94%AF%E6%8C%81%E7%9A%84%E6%89%80%E6%9C%89%E4%BA%A4%E6%98%93%E5%AF%B9\n */\nexport const getSpotCurrencyPairs = (): Promise<\n Array<{\n id: string;\n base: string;\n base_name: string;\n quote: string;\n quote_name: string;\n fee: string;\n min_base_amount: string;\n min_quote_amount: string;\n max_base_amount: string;\n max_quote_amount: string;\n amount_precision: Number;\n precision: Number;\n trade_status: string;\n sell_start: Number;\n buy_start: number;\n delisting_time: number;\n trade_url: string;\n st_tag: boolean;\n }>\n> => requestPublic('GET', `/spot/currency_pairs`);\n"]}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,kCAAkC,CAAC;AAC1C,OAAO,4BAA4B,CAAC;AACpC,OAAO,0BAA0B,CAAC;AAClC,OAAO,mBAAmB,CAAC;AAC3B,OAAO,qBAAqB,CAAC","sourcesContent":["import './services/exchange';\nimport './services/markets/interest-rate';\nimport './services/markets/product';\nimport './services/markets/quote';\nimport './services/quotes';\nimport './services/transfer';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,kCAAkC,CAAC;AAC1C,OAAO,4BAA4B,CAAC;AACpC,OAAO,0BAA0B,CAAC;AAClC,OAAO,mBAAmB,CAAC;AAC3B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,yBAAyB,CAAC;AACjC,OAAO,kCAAkC,CAAC","sourcesContent":["import './services/exchange';\nimport './services/markets/interest-rate';\nimport './services/markets/product';\nimport './services/markets/quote';\nimport './services/quotes';\nimport './services/transfer';\nimport './services/ohlc-service';\nimport './services/interest-rate-service';\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { provideInterestRateService } from '@yuants/exchange';
|
|
2
|
+
import { Terminal } from '@yuants/protocol';
|
|
3
|
+
import { decodePath, formatTime } from '@yuants/utils';
|
|
4
|
+
import { getFutureFundingRate } from '../api/public-api';
|
|
5
|
+
const terminal = Terminal.fromNodeEnv();
|
|
6
|
+
const WINDOW_SEC = 365 * 86400;
|
|
7
|
+
const fetchFundingRateBackward = async (req) => {
|
|
8
|
+
const [, instType, contract] = decodePath(req.product_id);
|
|
9
|
+
if (instType !== 'FUTURE' || !contract)
|
|
10
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
11
|
+
const endedAtMs = req.time;
|
|
12
|
+
const to = Math.floor(endedAtMs / 1000);
|
|
13
|
+
const from = Math.max(0, to - WINDOW_SEC);
|
|
14
|
+
const rows = await getFutureFundingRate('usdt', { contract, from, to, limit: 1000 });
|
|
15
|
+
return (rows !== null && rows !== void 0 ? rows : [])
|
|
16
|
+
.map((entry) => {
|
|
17
|
+
const ms = entry.t * 1000;
|
|
18
|
+
const rate = Number(entry.r);
|
|
19
|
+
return {
|
|
20
|
+
series_id: req.series_id,
|
|
21
|
+
product_id: req.product_id,
|
|
22
|
+
datasource_id: 'GATE',
|
|
23
|
+
created_at: formatTime(ms),
|
|
24
|
+
long_rate: `${-rate}`,
|
|
25
|
+
short_rate: `${rate}`,
|
|
26
|
+
settlement_price: '',
|
|
27
|
+
};
|
|
28
|
+
})
|
|
29
|
+
.filter((x) => Date.parse(x.created_at) < endedAtMs);
|
|
30
|
+
};
|
|
31
|
+
provideInterestRateService(terminal, {
|
|
32
|
+
product_id_prefix: 'GATE/FUTURE/',
|
|
33
|
+
direction: 'backward',
|
|
34
|
+
}, fetchFundingRateBackward);
|
|
35
|
+
//# sourceMappingURL=interest-rate-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interest-rate-service.js","sourceRoot":"","sources":["../../src/services/interest-rate-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,UAAU,GAAG,GAAG,GAAG,KAAK,CAAC;AAE/B,MAAM,wBAAwB,GAAG,KAAK,EAAE,GAIvC,EAA4B,EAAE;IAC7B,MAAM,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC1D,IAAI,QAAQ,KAAK,QAAQ,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA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yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime } from '@yuants/utils';\nimport { getFutureFundingRate } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst WINDOW_SEC = 365 * 86400;\n\nconst fetchFundingRateBackward = async (req: {\n product_id: string;\n time: number;\n series_id: string;\n}): Promise<IInterestRate[]> => {\n const [, instType, contract] = decodePath(req.product_id);\n if (instType !== 'FUTURE' || !contract) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const endedAtMs = req.time;\n const to = Math.floor(endedAtMs / 1000);\n const from = Math.max(0, to - WINDOW_SEC);\n\n const rows = await getFutureFundingRate('usdt', { contract, from, to, limit: 1000 });\n\n return (rows ?? [])\n .map((entry): IInterestRate => {\n const ms = entry.t * 1000;\n const rate = Number(entry.r);\n return {\n series_id: req.series_id,\n product_id: req.product_id,\n datasource_id: 'GATE',\n created_at: formatTime(ms),\n long_rate: `${-rate}`,\n short_rate: `${rate}`,\n settlement_price: '',\n };\n })\n .filter((x) => Date.parse(x.created_at) < endedAtMs);\n};\n\nprovideInterestRateService(\n terminal,\n {\n product_id_prefix: 'GATE/FUTURE/',\n direction: 'backward',\n },\n fetchFundingRateBackward,\n);\n"]}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { provideOHLCService } from '@yuants/exchange';
|
|
2
|
+
import { Terminal } from '@yuants/protocol';
|
|
3
|
+
import { convertDurationToOffset, decodePath, formatTime } from '@yuants/utils';
|
|
4
|
+
import { getFuturesCandlesticks, getSpotCandlesticks } from '../api/public-api';
|
|
5
|
+
const terminal = Terminal.fromNodeEnv();
|
|
6
|
+
const DURATION_TO_GATE_INTERVAL = {
|
|
7
|
+
PT1M: '1m',
|
|
8
|
+
PT5M: '5m',
|
|
9
|
+
PT15M: '15m',
|
|
10
|
+
PT30M: '30m',
|
|
11
|
+
PT1H: '1h',
|
|
12
|
+
PT4H: '4h',
|
|
13
|
+
PT8H: '8h',
|
|
14
|
+
P1D: '1d',
|
|
15
|
+
P1W: '1w',
|
|
16
|
+
};
|
|
17
|
+
const normalizeCandle = (raw) => {
|
|
18
|
+
if (Array.isArray(raw)) {
|
|
19
|
+
const t = Number(raw[0]);
|
|
20
|
+
const tMs = t < 1e12 ? t * 1000 : t;
|
|
21
|
+
const volume = raw[1];
|
|
22
|
+
const close = raw[2];
|
|
23
|
+
const high = raw[3];
|
|
24
|
+
const low = raw[4];
|
|
25
|
+
const open = raw[5];
|
|
26
|
+
return { tMs, o: open, h: high, l: low, c: close, v: volume };
|
|
27
|
+
}
|
|
28
|
+
const t = Number(raw.t);
|
|
29
|
+
const tMs = t < 1e12 ? t * 1000 : t;
|
|
30
|
+
return { tMs, o: raw.o, h: raw.h, l: raw.l, c: raw.c, v: raw.v };
|
|
31
|
+
};
|
|
32
|
+
const fetchFuturesOHLCBackward = async (req) => {
|
|
33
|
+
const [, instType, contract] = decodePath(req.product_id);
|
|
34
|
+
if (instType !== 'FUTURE' || !contract)
|
|
35
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
36
|
+
const interval = DURATION_TO_GATE_INTERVAL[req.duration];
|
|
37
|
+
if (!interval)
|
|
38
|
+
throw new Error(`Unsupported duration: ${req.duration}`);
|
|
39
|
+
const offset = convertDurationToOffset(req.duration);
|
|
40
|
+
const endedAtMs = req.time;
|
|
41
|
+
const to = Math.floor(endedAtMs / 1000);
|
|
42
|
+
const rows = await getFuturesCandlesticks('usdt', {
|
|
43
|
+
contract,
|
|
44
|
+
interval,
|
|
45
|
+
to,
|
|
46
|
+
limit: 1000,
|
|
47
|
+
});
|
|
48
|
+
return (rows !== null && rows !== void 0 ? rows : [])
|
|
49
|
+
.map((raw) => {
|
|
50
|
+
const k = normalizeCandle(raw);
|
|
51
|
+
return {
|
|
52
|
+
series_id: req.series_id,
|
|
53
|
+
datasource_id: 'GATE',
|
|
54
|
+
product_id: req.product_id,
|
|
55
|
+
duration: req.duration,
|
|
56
|
+
created_at: formatTime(k.tMs),
|
|
57
|
+
closed_at: formatTime(k.tMs + offset),
|
|
58
|
+
open: k.o,
|
|
59
|
+
high: k.h,
|
|
60
|
+
low: k.l,
|
|
61
|
+
close: k.c,
|
|
62
|
+
volume: k.v,
|
|
63
|
+
open_interest: '0',
|
|
64
|
+
};
|
|
65
|
+
})
|
|
66
|
+
.filter((x) => Date.parse(x.created_at) < endedAtMs);
|
|
67
|
+
};
|
|
68
|
+
const fetchSpotOHLCBackward = async (req) => {
|
|
69
|
+
const [, instType, currency_pair] = decodePath(req.product_id);
|
|
70
|
+
if (instType !== 'SPOT' || !currency_pair)
|
|
71
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
72
|
+
const interval = DURATION_TO_GATE_INTERVAL[req.duration];
|
|
73
|
+
if (!interval)
|
|
74
|
+
throw new Error(`Unsupported duration: ${req.duration}`);
|
|
75
|
+
const offset = convertDurationToOffset(req.duration);
|
|
76
|
+
const endedAtMs = req.time;
|
|
77
|
+
const to = Math.floor(endedAtMs / 1000);
|
|
78
|
+
const rows = await getSpotCandlesticks({
|
|
79
|
+
currency_pair,
|
|
80
|
+
interval,
|
|
81
|
+
to,
|
|
82
|
+
limit: 1000,
|
|
83
|
+
});
|
|
84
|
+
return (rows !== null && rows !== void 0 ? rows : [])
|
|
85
|
+
.map((raw) => {
|
|
86
|
+
const k = normalizeCandle(raw);
|
|
87
|
+
return {
|
|
88
|
+
series_id: req.series_id,
|
|
89
|
+
datasource_id: 'GATE',
|
|
90
|
+
product_id: req.product_id,
|
|
91
|
+
duration: req.duration,
|
|
92
|
+
created_at: formatTime(k.tMs),
|
|
93
|
+
closed_at: formatTime(k.tMs + offset),
|
|
94
|
+
open: k.o,
|
|
95
|
+
high: k.h,
|
|
96
|
+
low: k.l,
|
|
97
|
+
close: k.c,
|
|
98
|
+
volume: k.v,
|
|
99
|
+
open_interest: '0',
|
|
100
|
+
};
|
|
101
|
+
})
|
|
102
|
+
.filter((x) => Date.parse(x.created_at) < endedAtMs);
|
|
103
|
+
};
|
|
104
|
+
provideOHLCService(terminal, {
|
|
105
|
+
product_id_prefix: 'GATE/FUTURE/',
|
|
106
|
+
duration_list: Object.keys(DURATION_TO_GATE_INTERVAL),
|
|
107
|
+
direction: 'backward',
|
|
108
|
+
}, fetchFuturesOHLCBackward);
|
|
109
|
+
provideOHLCService(terminal, {
|
|
110
|
+
product_id_prefix: 'GATE/SPOT/',
|
|
111
|
+
duration_list: Object.keys(DURATION_TO_GATE_INTERVAL),
|
|
112
|
+
direction: 'backward',
|
|
113
|
+
}, fetchSpotOHLCBackward);
|
|
114
|
+
//# sourceMappingURL=ohlc-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ohlc-service.js","sourceRoot":"","sources":["../../src/services/ohlc-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAEhF,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,yBAAyB,GAA2B;IACxD,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;CACV,CAAC;AAEF,MAAM,eAAe,GAAG,CACtB,GAEoD,EACoB,EAAE;IAC1E,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACtB,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACzB,MAA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C,CAAC,CAAC,GAAG,GAAG,MAAM,CAAC;YACrC,IAAI,EAAE,CAAC,CAAC,CAAC;YACT,IAAI,EAAE,CAAC,CAAC,CAAC;YACT,GAAG,EAAE,CAAC,CAAC,CAAC;YACR,KAAK,EAAE,CAAC,CAAC,CAAC;YACV,MAAM,EAAE,CAAC,CAAC,CAAC;YACX,aAAa,EAAE,GAAG;SACnB,CAAC;IACJ,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF,kBAAkB,CAChB,QAAQ,EACR;IACE,iBAAiB,EAAE,cAAc;IACjC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC;IACrD,SAAS,EAAE,UAAU;CACtB,EACD,wBAAwB,CACzB,CAAC;AAEF,kBAAkB,CAChB,QAAQ,EACR;IACE,iBAAiB,EAAE,YAAY;IAC/B,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC;IACrD,SAAS,EAAE,UAAU;CACtB,EACD,qBAAqB,CACtB,CAAC","sourcesContent":["import { IOHLC } from '@yuants/data-ohlc';\nimport { provideOHLCService } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { convertDurationToOffset, decodePath, formatTime } from '@yuants/utils';\nimport { getFuturesCandlesticks, getSpotCandlesticks } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst DURATION_TO_GATE_INTERVAL: Record<string, string> = {\n PT1M: '1m',\n PT5M: '5m',\n PT15M: '15m',\n PT30M: '30m',\n PT1H: '1h',\n PT4H: '4h',\n PT8H: '8h',\n P1D: '1d',\n P1W: '1w',\n};\n\nconst normalizeCandle = (\n raw:\n | { t: number; o: string; h: string; l: string; c: string; v: string }\n | [string, string, string, string, string, string],\n): { tMs: number; o: string; h: string; l: string; c: string; v: string } => {\n if (Array.isArray(raw)) {\n const t = Number(raw[0]);\n const tMs = t < 1e12 ? t * 1000 : t;\n const volume = raw[1];\n const close = raw[2];\n const high = raw[3];\n const low = raw[4];\n const open = raw[5];\n return { tMs, o: open, h: high, l: low, c: close, v: volume };\n }\n const t = Number(raw.t);\n const tMs = t < 1e12 ? t * 1000 : t;\n return { tMs, o: raw.o, h: raw.h, l: raw.l, c: raw.c, v: raw.v };\n};\n\nconst fetchFuturesOHLCBackward = async (req: {\n product_id: string;\n duration: string;\n time: number;\n series_id: string;\n}): Promise<IOHLC[]> => {\n const [, instType, contract] = decodePath(req.product_id);\n if (instType !== 'FUTURE' || !contract) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const interval = DURATION_TO_GATE_INTERVAL[req.duration];\n if (!interval) throw new Error(`Unsupported duration: ${req.duration}`);\n\n const offset = convertDurationToOffset(req.duration);\n const endedAtMs = req.time;\n const to = Math.floor(endedAtMs / 1000);\n\n const rows = await getFuturesCandlesticks('usdt', {\n contract,\n interval,\n to,\n limit: 1000,\n });\n\n return (rows ?? [])\n .map((raw): IOHLC => {\n const k = normalizeCandle(raw);\n return {\n series_id: req.series_id,\n datasource_id: 'GATE',\n product_id: req.product_id,\n duration: req.duration,\n created_at: formatTime(k.tMs),\n closed_at: formatTime(k.tMs + offset),\n open: k.o,\n high: k.h,\n low: k.l,\n close: k.c,\n volume: k.v,\n open_interest: '0',\n };\n })\n .filter((x) => Date.parse(x.created_at) < endedAtMs);\n};\n\nconst fetchSpotOHLCBackward = async (req: {\n product_id: string;\n duration: string;\n time: number;\n series_id: string;\n}): Promise<IOHLC[]> => {\n const [, instType, currency_pair] = decodePath(req.product_id);\n if (instType !== 'SPOT' || !currency_pair) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const interval = DURATION_TO_GATE_INTERVAL[req.duration];\n if (!interval) throw new Error(`Unsupported duration: ${req.duration}`);\n\n const offset = convertDurationToOffset(req.duration);\n const endedAtMs = req.time;\n const to = Math.floor(endedAtMs / 1000);\n\n const rows = await getSpotCandlesticks({\n currency_pair,\n interval,\n to,\n limit: 1000,\n });\n\n return (rows ?? [])\n .map((raw): IOHLC => {\n const k = normalizeCandle(raw);\n return {\n series_id: req.series_id,\n datasource_id: 'GATE',\n product_id: req.product_id,\n duration: req.duration,\n created_at: formatTime(k.tMs),\n closed_at: formatTime(k.tMs + offset),\n open: k.o,\n high: k.h,\n low: k.l,\n close: k.c,\n volume: k.v,\n open_interest: '0',\n };\n })\n .filter((x) => Date.parse(x.created_at) < endedAtMs);\n};\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'GATE/FUTURE/',\n duration_list: Object.keys(DURATION_TO_GATE_INTERVAL),\n direction: 'backward',\n },\n fetchFuturesOHLCBackward,\n);\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'GATE/SPOT/',\n duration_list: Object.keys(DURATION_TO_GATE_INTERVAL),\n direction: 'backward',\n },\n fetchSpotOHLCBackward,\n);\n"]}
|
package/lib/api/public-api.d.ts
CHANGED
|
@@ -62,10 +62,62 @@ export declare const getFuturesContracts: (settle: string, params?: {
|
|
|
62
62
|
export declare const getFutureFundingRate: (settle: string, params: {
|
|
63
63
|
contract: string;
|
|
64
64
|
limit?: number;
|
|
65
|
+
from?: number;
|
|
66
|
+
to?: number;
|
|
67
|
+
offset?: number;
|
|
65
68
|
}) => Promise<{
|
|
66
69
|
t: number;
|
|
67
70
|
r: string;
|
|
68
71
|
}[]>;
|
|
72
|
+
/**
|
|
73
|
+
* 合约市场 K 线图
|
|
74
|
+
*
|
|
75
|
+
* https://www.gate.com/docs/developers/apiv4/zh_CN/#%E5%90%88%E7%BA%A6%E5%B8%82%E5%9C%BA-k-%E7%BA%BF%E5%9B%BE
|
|
76
|
+
*/
|
|
77
|
+
export declare const getFuturesCandlesticks: (settle: string, params: {
|
|
78
|
+
contract: string;
|
|
79
|
+
interval: string;
|
|
80
|
+
from?: number;
|
|
81
|
+
to?: number;
|
|
82
|
+
limit?: number;
|
|
83
|
+
}) => Promise<Array<{
|
|
84
|
+
/** Unix second */
|
|
85
|
+
t: number;
|
|
86
|
+
/** Open */
|
|
87
|
+
o: string;
|
|
88
|
+
/** High */
|
|
89
|
+
h: string;
|
|
90
|
+
/** Low */
|
|
91
|
+
l: string;
|
|
92
|
+
/** Close */
|
|
93
|
+
c: string;
|
|
94
|
+
/** Volume */
|
|
95
|
+
v: string;
|
|
96
|
+
}>>;
|
|
97
|
+
/**
|
|
98
|
+
* 市场 K 线图
|
|
99
|
+
*
|
|
100
|
+
* https://www.gate.com/docs/developers/apiv4/zh_CN/#%E5%B8%82%E5%9C%BA-k-%E7%BA%BF%E5%9B%BE
|
|
101
|
+
*/
|
|
102
|
+
export declare const getSpotCandlesticks: (params: {
|
|
103
|
+
currency_pair: string;
|
|
104
|
+
interval: string;
|
|
105
|
+
from?: number;
|
|
106
|
+
to?: number;
|
|
107
|
+
limit?: number;
|
|
108
|
+
}) => Promise<Array<
|
|
109
|
+
/**
|
|
110
|
+
* [t, v, c, h, l, o]
|
|
111
|
+
* - t: Unix second
|
|
112
|
+
*/
|
|
113
|
+
[
|
|
114
|
+
string,
|
|
115
|
+
string,
|
|
116
|
+
string,
|
|
117
|
+
string,
|
|
118
|
+
string,
|
|
119
|
+
string
|
|
120
|
+
]>>;
|
|
69
121
|
/**
|
|
70
122
|
* 查询合约市场深度信息
|
|
71
123
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-api.d.ts","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,WACtB,MAAM,WACL;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAC3C,QACD;IACE,MAAM,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,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AAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC,CAC6C,CAAC"}
|
package/lib/api/public-api.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSpotCurrencyPairs = exports.getSpotTickers = exports.getFuturesTickers = exports.getFuturesOrderBook = exports.getFutureFundingRate = exports.getFuturesContracts = void 0;
|
|
4
|
-
const rate_limiter_1 = require("./rate-limiter");
|
|
3
|
+
exports.getSpotCurrencyPairs = exports.getSpotTickers = exports.getFuturesTickers = exports.getFuturesOrderBook = exports.getSpotCandlesticks = exports.getFuturesCandlesticks = exports.getFutureFundingRate = exports.getFuturesContracts = void 0;
|
|
5
4
|
const http_client_1 = require("./http-client");
|
|
5
|
+
const rate_limiter_1 = require("./rate-limiter");
|
|
6
6
|
/**
|
|
7
7
|
* 查询所有的合约信息
|
|
8
8
|
*
|
|
@@ -21,6 +21,20 @@ exports.getFuturesContracts = getFuturesContracts;
|
|
|
21
21
|
*/
|
|
22
22
|
const getFutureFundingRate = (settle, params) => (0, http_client_1.requestPublic)('GET', `/futures/${settle}/funding_rate`, params);
|
|
23
23
|
exports.getFutureFundingRate = getFutureFundingRate;
|
|
24
|
+
/**
|
|
25
|
+
* 合约市场 K 线图
|
|
26
|
+
*
|
|
27
|
+
* https://www.gate.com/docs/developers/apiv4/zh_CN/#%E5%90%88%E7%BA%A6%E5%B8%82%E5%9C%BA-k-%E7%BA%BF%E5%9B%BE
|
|
28
|
+
*/
|
|
29
|
+
const getFuturesCandlesticks = (settle, params) => (0, http_client_1.requestPublic)('GET', `/futures/${settle}/candlesticks`, params);
|
|
30
|
+
exports.getFuturesCandlesticks = getFuturesCandlesticks;
|
|
31
|
+
/**
|
|
32
|
+
* 市场 K 线图
|
|
33
|
+
*
|
|
34
|
+
* https://www.gate.com/docs/developers/apiv4/zh_CN/#%E5%B8%82%E5%9C%BA-k-%E7%BA%BF%E5%9B%BE
|
|
35
|
+
*/
|
|
36
|
+
const getSpotCandlesticks = (params) => (0, http_client_1.requestPublic)('GET', `/spot/candlesticks`, params);
|
|
37
|
+
exports.getSpotCandlesticks = getSpotCandlesticks;
|
|
24
38
|
/**
|
|
25
39
|
* 查询合约市场深度信息
|
|
26
40
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;
|
|
1
|
+
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../../src/api/public-api.ts"],"names":[],"mappings":";;;AAAA,+CAA8C;AAC9C,iDAA6C;AAE7C;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,CACjC,MAAc,EACd,MAA4C,EA8C5C,EAAE,CAAC,IAAA,2BAAa,EAAC,KAAK,EAAE,YAAY,MAAM,YAAY,EAAE,MAAM,CAAC,CAAC;AAhDrD,QAAA,mBAAmB,uBAgDkC;AAElE;;;;;;;;GAQG;AACI,MAAM,oBAAoB,GAAG,CAClC,MAAc,EACd,MAAyF,EAMzF,EAAE,CAAC,IAAA,2BAAa,EAAC,KAAK,EAAE,YAAY,MAAM,eAAe,EAAE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ateLimiter } from './rate-limiter';\n\n/**\n * 查询所有的合约信息\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E6%89%80%E6%9C%89%E7%9A%84%E5%90%88%E7%BA%A6%E4%BF%A1%E6%81%AF\n */\nexport const getFuturesContracts = (\n settle: string,\n params?: { limit?: number; offset?: number },\n): Promise<\n {\n name: string;\n type: string;\n quanto_multiplier: string;\n ref_discount_rate: string;\n order_price_deviate: string;\n maintenance_rate: string;\n mark_type: string;\n last_price: string;\n mark_price: string;\n index_price: string;\n funding_rate_indicative: string;\n mark_price_round: string;\n funding_offset: number;\n in_delisting: boolean;\n risk_limit_base: string;\n interest_rate: string;\n order_price_round: string;\n order_size_min: number;\n ref_rebate_rate: string;\n funding_interval: number;\n risk_limit_step: string;\n leverage_min: string;\n leverage_max: string;\n risk_limit_max: string;\n maker_fee_rate: string;\n taker_fee_rate: string;\n funding_rate: string;\n order_size_max: number;\n funding_next_apply: number;\n short_users: number;\n config_change_time: number;\n trade_size: number;\n position_size: number;\n long_users: number;\n funding_impact_value: string;\n orders_limit: number;\n trade_id: number;\n orderbook_id: number;\n enable_bonus: boolean;\n enable_credit: boolean;\n create_time: number;\n funding_cap_ratio: string;\n }[]\n> => requestPublic('GET', `/futures/${settle}/contracts`, params);\n\n/**\n * 合约市场历史资金费率\n *\n * - Note: 该接口返回的数据是按照时间倒序排列的\n * - Note: limit 参数最大值为 1000\n * - Note: t 字段为秒级时间戳 (Unix Second),r 字段为资金费率 (0-1 单位)\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E5%90%88%E7%BA%A6%E5%B8%82%E5%9C%BA%E5%8E%86%E5%8F%B2%E8%B5%84%E9%87%91%E8%B4%B9%E7%8E%87\n */\nexport const getFutureFundingRate = (\n settle: string,\n params: { contract: string; limit?: number; from?: number; to?: number; offset?: number },\n): Promise<\n {\n t: number;\n r: string;\n }[]\n> => requestPublic('GET', `/futures/${settle}/funding_rate`, params);\n\n/**\n * 合约市场 K 线图\n *\n * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E5%90%88%E7%BA%A6%E5%B8%82%E5%9C%BA-k-%E7%BA%BF%E5%9B%BE\n */\nexport const getFuturesCandlesticks = (\n settle: string,\n params: {\n contract: string;\n interval: string;\n from?: number;\n to?: number;\n limit?: number;\n },\n): Promise<\n Array<{\n /** Unix second */\n t: number;\n /** Open */\n o: string;\n /** High */\n h: string;\n /** Low */\n l: string;\n /** Close */\n c: string;\n /** Volume */\n v: string;\n }>\n> => requestPublic('GET', `/futures/${settle}/candlesticks`, params);\n\n/**\n * 市场 K 线图\n *\n * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E5%B8%82%E5%9C%BA-k-%E7%BA%BF%E5%9B%BE\n */\nexport const getSpotCandlesticks = (params: {\n currency_pair: string;\n interval: string;\n from?: number;\n to?: number;\n limit?: number;\n}): Promise<\n Array<\n /**\n * [t, v, c, h, l, o]\n * - t: Unix second\n */\n [string, string, string, string, string, string]\n >\n> => requestPublic('GET', `/spot/candlesticks`, params);\n\n/**\n * 查询合约市场深度信息\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E5%90%88%E7%BA%A6%E5%B8%82%E5%9C%BA%E6%B7%B1%E5%BA%A6%E4%BF%A1%E6%81%AF\n */\nexport const getFuturesOrderBook = async (\n settle: string,\n params: {\n contract: string;\n interval?: string;\n limit?: number;\n with_id?: boolean;\n },\n): Promise<{\n id: number;\n current: number;\n update: number;\n asks: {\n p: string;\n s: string;\n }[];\n bids: {\n p: string;\n s: string;\n }[];\n}> =>\n rateLimiter.schedule(`futures-order-book:${settle}`, 200, 10_000, () =>\n requestPublic('GET', `/futures/${settle}/order_book`, params),\n );\n\n/**\n * 获取所有合约交易行情统计\n *\n * https://www.gate.io/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E6%89%80%E6%9C%89%E5%90%88%E7%BA%A6%E4%BA%A4%E6%98%93%E8%A1%8C%E6%83%85%E7%BB%9F%E8%AE%A1\n */\nexport const getFuturesTickers = (\n settle: string,\n params?: { contract?: string },\n): Promise<\n {\n contract: string;\n last: string;\n change_percentage: string;\n total_size: string;\n low_24h: string;\n high_24h: string;\n volume_24h: string;\n volume_24h_btc: string;\n volume_24h_usd: string;\n volume_24h_base: string;\n volume_24h_quote: string;\n volume_24h_settle: string;\n mark_price: string;\n funding_rate: string;\n funding_rate_indicative: string;\n index_price: string;\n quanto_base_rate: string;\n basis_rate: string;\n basis_value: string;\n lowest_ask: string;\n highest_bid: string;\n }[]\n> => requestPublic('GET', `/futures/${settle}/tickers`, params);\n\n/**\n * 获取交易对 ticker 信息\n *\n * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E8%8E%B7%E5%8F%96%E4%BA%A4%E6%98%93%E5%AF%B9-ticker-%E4%BF%A1%E6%81%AF\n */\nexport const getSpotTickers = (params: {\n currency_pair?: string;\n timezone?: string;\n}): Promise<\n Array<{\n currency_pair: string;\n last: string;\n lowest_ask: string;\n lowest_size: string;\n highest_bid: string;\n highest_size: string;\n change_percentage: string;\n change_utc0: string;\n change_utc8: string;\n base_volume: string;\n quote_volume: string;\n high_24h: string;\n low_24h: string;\n etf_net_value: string;\n etf_pre_net_value: string;\n etf_pre_timestamp: string;\n etf_leverage: string;\n }>\n> => requestPublic('GET', `/spot/tickers`, params);\n\n/**\n * 查询支持的所有现货交易对\n * https://www.gate.com/docs/developers/apiv4/zh_CN/#%E6%9F%A5%E8%AF%A2%E6%94%AF%E6%8C%81%E7%9A%84%E6%89%80%E6%9C%89%E4%BA%A4%E6%98%93%E5%AF%B9\n */\nexport const getSpotCurrencyPairs = (): Promise<\n Array<{\n id: string;\n base: string;\n base_name: string;\n quote: string;\n quote_name: string;\n fee: string;\n min_base_amount: string;\n min_quote_amount: string;\n max_base_amount: string;\n max_quote_amount: string;\n amount_precision: Number;\n precision: Number;\n trade_status: string;\n sell_start: Number;\n buy_start: number;\n delisting_time: number;\n trade_url: string;\n st_tag: boolean;\n }>\n> => requestPublic('GET', `/spot/currency_pairs`);\n"]}
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,kCAAkC,CAAC;AAC1C,OAAO,4BAA4B,CAAC;AACpC,OAAO,0BAA0B,CAAC;AAClC,OAAO,mBAAmB,CAAC;AAC3B,OAAO,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,kCAAkC,CAAC;AAC1C,OAAO,4BAA4B,CAAC;AACpC,OAAO,0BAA0B,CAAC;AAClC,OAAO,mBAAmB,CAAC;AAC3B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,yBAAyB,CAAC;AACjC,OAAO,kCAAkC,CAAC"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,4CAA0C;AAC1C,sCAAoC;AACpC,oCAAkC;AAClC,6BAA2B;AAC3B,+BAA6B","sourcesContent":["import './services/exchange';\nimport './services/markets/interest-rate';\nimport './services/markets/product';\nimport './services/markets/quote';\nimport './services/quotes';\nimport './services/transfer';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,4CAA0C;AAC1C,sCAAoC;AACpC,oCAAkC;AAClC,6BAA2B;AAC3B,+BAA6B;AAC7B,mCAAiC;AACjC,4CAA0C","sourcesContent":["import './services/exchange';\nimport './services/markets/interest-rate';\nimport './services/markets/product';\nimport './services/markets/quote';\nimport './services/quotes';\nimport './services/transfer';\nimport './services/ohlc-service';\nimport './services/interest-rate-service';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interest-rate-service.d.ts","sourceRoot":"","sources":["../../src/services/interest-rate-service.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const exchange_1 = require("@yuants/exchange");
|
|
4
|
+
const protocol_1 = require("@yuants/protocol");
|
|
5
|
+
const utils_1 = require("@yuants/utils");
|
|
6
|
+
const public_api_1 = require("../api/public-api");
|
|
7
|
+
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
8
|
+
const WINDOW_SEC = 365 * 86400;
|
|
9
|
+
const fetchFundingRateBackward = async (req) => {
|
|
10
|
+
const [, instType, contract] = (0, utils_1.decodePath)(req.product_id);
|
|
11
|
+
if (instType !== 'FUTURE' || !contract)
|
|
12
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
13
|
+
const endedAtMs = req.time;
|
|
14
|
+
const to = Math.floor(endedAtMs / 1000);
|
|
15
|
+
const from = Math.max(0, to - WINDOW_SEC);
|
|
16
|
+
const rows = await (0, public_api_1.getFutureFundingRate)('usdt', { contract, from, to, limit: 1000 });
|
|
17
|
+
return (rows !== null && rows !== void 0 ? rows : [])
|
|
18
|
+
.map((entry) => {
|
|
19
|
+
const ms = entry.t * 1000;
|
|
20
|
+
const rate = Number(entry.r);
|
|
21
|
+
return {
|
|
22
|
+
series_id: req.series_id,
|
|
23
|
+
product_id: req.product_id,
|
|
24
|
+
datasource_id: 'GATE',
|
|
25
|
+
created_at: (0, utils_1.formatTime)(ms),
|
|
26
|
+
long_rate: `${-rate}`,
|
|
27
|
+
short_rate: `${rate}`,
|
|
28
|
+
settlement_price: '',
|
|
29
|
+
};
|
|
30
|
+
})
|
|
31
|
+
.filter((x) => Date.parse(x.created_at) < endedAtMs);
|
|
32
|
+
};
|
|
33
|
+
(0, exchange_1.provideInterestRateService)(terminal, {
|
|
34
|
+
product_id_prefix: 'GATE/FUTURE/',
|
|
35
|
+
direction: 'backward',
|
|
36
|
+
}, fetchFundingRateBackward);
|
|
37
|
+
//# sourceMappingURL=interest-rate-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interest-rate-service.js","sourceRoot":"","sources":["../../src/services/interest-rate-service.ts"],"names":[],"mappings":";;AACA,+CAA8D;AAC9D,+CAA4C;AAC5C,yCAAuD;AACvD,kDAAyD;AAEzD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,UAAU,GAAG,GAAG,GAAG,KAAK,CAAC;AAE/B,MAAM,wBAAwB,GAAG,KAAK,EAAE,GAIvC,EAA4B,EAAE;IAC7B,MAAM,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,IAAA,kBAAU,EAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC1D,IAAI,QAAQ,KAAK,QAAQ,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;IAErG,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC;IAC3B,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,UAAU,CAAC,CAAC;IAE1C,MAAM,IAAI,GAAG,MAAM,IAAA,iCAAoB,EAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAErF,OAAO,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC;SAChB,GAAG,CAAC,CAAC,KAAK,EAAiB,EAAE;QAC5B,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC;QAC1B,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7B,OAAO;YACL,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,aAAa,EAAE,MAAM;YACrB,UAAU,EAAE,IAAA,kBAAU,EAAC,EAAE,CAAC;YAC1B,SAAS,EAAE,GAAG,CAAC,IAAI,EAAE;YACrB,UAAU,EAAE,GAAG,IAAI,EAAE;YACrB,gBAAgB,EAAE,EAAE;SACrB,CAAC;IACJ,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF,IAAA,qCAA0B,EACxB,QAAQ,EACR;IACE,iBAAiB,EAAE,cAAc;IACjC,SAAS,EAAE,UAAU;CACtB,EACD,wBAAwB,CACzB,CAAC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { provideInterestRateService } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { decodePath, formatTime } from '@yuants/utils';\nimport { getFutureFundingRate } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst WINDOW_SEC = 365 * 86400;\n\nconst fetchFundingRateBackward = async (req: {\n product_id: string;\n time: number;\n series_id: string;\n}): Promise<IInterestRate[]> => {\n const [, instType, contract] = decodePath(req.product_id);\n if (instType !== 'FUTURE' || !contract) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const endedAtMs = req.time;\n const to = Math.floor(endedAtMs / 1000);\n const from = Math.max(0, to - WINDOW_SEC);\n\n const rows = await getFutureFundingRate('usdt', { contract, from, to, limit: 1000 });\n\n return (rows ?? [])\n .map((entry): IInterestRate => {\n const ms = entry.t * 1000;\n const rate = Number(entry.r);\n return {\n series_id: req.series_id,\n product_id: req.product_id,\n datasource_id: 'GATE',\n created_at: formatTime(ms),\n long_rate: `${-rate}`,\n short_rate: `${rate}`,\n settlement_price: '',\n };\n })\n .filter((x) => Date.parse(x.created_at) < endedAtMs);\n};\n\nprovideInterestRateService(\n terminal,\n {\n product_id_prefix: 'GATE/FUTURE/',\n direction: 'backward',\n },\n fetchFundingRateBackward,\n);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ohlc-service.d.ts","sourceRoot":"","sources":["../../src/services/ohlc-service.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const exchange_1 = require("@yuants/exchange");
|
|
4
|
+
const protocol_1 = require("@yuants/protocol");
|
|
5
|
+
const utils_1 = require("@yuants/utils");
|
|
6
|
+
const public_api_1 = require("../api/public-api");
|
|
7
|
+
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
8
|
+
const DURATION_TO_GATE_INTERVAL = {
|
|
9
|
+
PT1M: '1m',
|
|
10
|
+
PT5M: '5m',
|
|
11
|
+
PT15M: '15m',
|
|
12
|
+
PT30M: '30m',
|
|
13
|
+
PT1H: '1h',
|
|
14
|
+
PT4H: '4h',
|
|
15
|
+
PT8H: '8h',
|
|
16
|
+
P1D: '1d',
|
|
17
|
+
P1W: '1w',
|
|
18
|
+
};
|
|
19
|
+
const normalizeCandle = (raw) => {
|
|
20
|
+
if (Array.isArray(raw)) {
|
|
21
|
+
const t = Number(raw[0]);
|
|
22
|
+
const tMs = t < 1e12 ? t * 1000 : t;
|
|
23
|
+
const volume = raw[1];
|
|
24
|
+
const close = raw[2];
|
|
25
|
+
const high = raw[3];
|
|
26
|
+
const low = raw[4];
|
|
27
|
+
const open = raw[5];
|
|
28
|
+
return { tMs, o: open, h: high, l: low, c: close, v: volume };
|
|
29
|
+
}
|
|
30
|
+
const t = Number(raw.t);
|
|
31
|
+
const tMs = t < 1e12 ? t * 1000 : t;
|
|
32
|
+
return { tMs, o: raw.o, h: raw.h, l: raw.l, c: raw.c, v: raw.v };
|
|
33
|
+
};
|
|
34
|
+
const fetchFuturesOHLCBackward = async (req) => {
|
|
35
|
+
const [, instType, contract] = (0, utils_1.decodePath)(req.product_id);
|
|
36
|
+
if (instType !== 'FUTURE' || !contract)
|
|
37
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
38
|
+
const interval = DURATION_TO_GATE_INTERVAL[req.duration];
|
|
39
|
+
if (!interval)
|
|
40
|
+
throw new Error(`Unsupported duration: ${req.duration}`);
|
|
41
|
+
const offset = (0, utils_1.convertDurationToOffset)(req.duration);
|
|
42
|
+
const endedAtMs = req.time;
|
|
43
|
+
const to = Math.floor(endedAtMs / 1000);
|
|
44
|
+
const rows = await (0, public_api_1.getFuturesCandlesticks)('usdt', {
|
|
45
|
+
contract,
|
|
46
|
+
interval,
|
|
47
|
+
to,
|
|
48
|
+
limit: 1000,
|
|
49
|
+
});
|
|
50
|
+
return (rows !== null && rows !== void 0 ? rows : [])
|
|
51
|
+
.map((raw) => {
|
|
52
|
+
const k = normalizeCandle(raw);
|
|
53
|
+
return {
|
|
54
|
+
series_id: req.series_id,
|
|
55
|
+
datasource_id: 'GATE',
|
|
56
|
+
product_id: req.product_id,
|
|
57
|
+
duration: req.duration,
|
|
58
|
+
created_at: (0, utils_1.formatTime)(k.tMs),
|
|
59
|
+
closed_at: (0, utils_1.formatTime)(k.tMs + offset),
|
|
60
|
+
open: k.o,
|
|
61
|
+
high: k.h,
|
|
62
|
+
low: k.l,
|
|
63
|
+
close: k.c,
|
|
64
|
+
volume: k.v,
|
|
65
|
+
open_interest: '0',
|
|
66
|
+
};
|
|
67
|
+
})
|
|
68
|
+
.filter((x) => Date.parse(x.created_at) < endedAtMs);
|
|
69
|
+
};
|
|
70
|
+
const fetchSpotOHLCBackward = async (req) => {
|
|
71
|
+
const [, instType, currency_pair] = (0, utils_1.decodePath)(req.product_id);
|
|
72
|
+
if (instType !== 'SPOT' || !currency_pair)
|
|
73
|
+
throw new Error(`Unsupported product_id: ${req.product_id}`);
|
|
74
|
+
const interval = DURATION_TO_GATE_INTERVAL[req.duration];
|
|
75
|
+
if (!interval)
|
|
76
|
+
throw new Error(`Unsupported duration: ${req.duration}`);
|
|
77
|
+
const offset = (0, utils_1.convertDurationToOffset)(req.duration);
|
|
78
|
+
const endedAtMs = req.time;
|
|
79
|
+
const to = Math.floor(endedAtMs / 1000);
|
|
80
|
+
const rows = await (0, public_api_1.getSpotCandlesticks)({
|
|
81
|
+
currency_pair,
|
|
82
|
+
interval,
|
|
83
|
+
to,
|
|
84
|
+
limit: 1000,
|
|
85
|
+
});
|
|
86
|
+
return (rows !== null && rows !== void 0 ? rows : [])
|
|
87
|
+
.map((raw) => {
|
|
88
|
+
const k = normalizeCandle(raw);
|
|
89
|
+
return {
|
|
90
|
+
series_id: req.series_id,
|
|
91
|
+
datasource_id: 'GATE',
|
|
92
|
+
product_id: req.product_id,
|
|
93
|
+
duration: req.duration,
|
|
94
|
+
created_at: (0, utils_1.formatTime)(k.tMs),
|
|
95
|
+
closed_at: (0, utils_1.formatTime)(k.tMs + offset),
|
|
96
|
+
open: k.o,
|
|
97
|
+
high: k.h,
|
|
98
|
+
low: k.l,
|
|
99
|
+
close: k.c,
|
|
100
|
+
volume: k.v,
|
|
101
|
+
open_interest: '0',
|
|
102
|
+
};
|
|
103
|
+
})
|
|
104
|
+
.filter((x) => Date.parse(x.created_at) < endedAtMs);
|
|
105
|
+
};
|
|
106
|
+
(0, exchange_1.provideOHLCService)(terminal, {
|
|
107
|
+
product_id_prefix: 'GATE/FUTURE/',
|
|
108
|
+
duration_list: Object.keys(DURATION_TO_GATE_INTERVAL),
|
|
109
|
+
direction: 'backward',
|
|
110
|
+
}, fetchFuturesOHLCBackward);
|
|
111
|
+
(0, exchange_1.provideOHLCService)(terminal, {
|
|
112
|
+
product_id_prefix: 'GATE/SPOT/',
|
|
113
|
+
duration_list: Object.keys(DURATION_TO_GATE_INTERVAL),
|
|
114
|
+
direction: 'backward',
|
|
115
|
+
}, fetchSpotOHLCBackward);
|
|
116
|
+
//# sourceMappingURL=ohlc-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ohlc-service.js","sourceRoot":"","sources":["../../src/services/ohlc-service.ts"],"names":[],"mappings":";;AACA,+CAAsD;AACtD,+CAA4C;AAC5C,yCAAgF;AAChF,kDAAgF;AAEhF,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,yBAAyB,GAA2B;IACxD,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;CACV,CAAC;AAEF,MAAM,eAAe,GAAG,CACtB,GAEoD,EACoB,EAAE;IAC1E,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACtB,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACzB,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACrB,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACpB,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACnB,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACpB,OAAO,EAAE,GAAG,EAA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K,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF,IAAA,6BAAkB,EAChB,QAAQ,EACR;IACE,iBAAiB,EAAE,cAAc;IACjC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC;IACrD,SAAS,EAAE,UAAU;CACtB,EACD,wBAAwB,CACzB,CAAC;AAEF,IAAA,6BAAkB,EAChB,QAAQ,EACR;IACE,iBAAiB,EAAE,YAAY;IAC/B,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC;IACrD,SAAS,EAAE,UAAU;CACtB,EACD,qBAAqB,CACtB,CAAC","sourcesContent":["import { IOHLC } from '@yuants/data-ohlc';\nimport { provideOHLCService } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { convertDurationToOffset, decodePath, formatTime } from '@yuants/utils';\nimport { getFuturesCandlesticks, getSpotCandlesticks } from '../api/public-api';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst DURATION_TO_GATE_INTERVAL: Record<string, string> = {\n PT1M: '1m',\n PT5M: '5m',\n PT15M: '15m',\n PT30M: '30m',\n PT1H: '1h',\n PT4H: '4h',\n PT8H: '8h',\n P1D: '1d',\n P1W: '1w',\n};\n\nconst normalizeCandle = (\n raw:\n | { t: number; o: string; h: string; l: string; c: string; v: string }\n | [string, string, string, string, string, string],\n): { tMs: number; o: string; h: string; l: string; c: string; v: string } => {\n if (Array.isArray(raw)) {\n const t = Number(raw[0]);\n const tMs = t < 1e12 ? t * 1000 : t;\n const volume = raw[1];\n const close = raw[2];\n const high = raw[3];\n const low = raw[4];\n const open = raw[5];\n return { tMs, o: open, h: high, l: low, c: close, v: volume };\n }\n const t = Number(raw.t);\n const tMs = t < 1e12 ? t * 1000 : t;\n return { tMs, o: raw.o, h: raw.h, l: raw.l, c: raw.c, v: raw.v };\n};\n\nconst fetchFuturesOHLCBackward = async (req: {\n product_id: string;\n duration: string;\n time: number;\n series_id: string;\n}): Promise<IOHLC[]> => {\n const [, instType, contract] = decodePath(req.product_id);\n if (instType !== 'FUTURE' || !contract) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const interval = DURATION_TO_GATE_INTERVAL[req.duration];\n if (!interval) throw new Error(`Unsupported duration: ${req.duration}`);\n\n const offset = convertDurationToOffset(req.duration);\n const endedAtMs = req.time;\n const to = Math.floor(endedAtMs / 1000);\n\n const rows = await getFuturesCandlesticks('usdt', {\n contract,\n interval,\n to,\n limit: 1000,\n });\n\n return (rows ?? [])\n .map((raw): IOHLC => {\n const k = normalizeCandle(raw);\n return {\n series_id: req.series_id,\n datasource_id: 'GATE',\n product_id: req.product_id,\n duration: req.duration,\n created_at: formatTime(k.tMs),\n closed_at: formatTime(k.tMs + offset),\n open: k.o,\n high: k.h,\n low: k.l,\n close: k.c,\n volume: k.v,\n open_interest: '0',\n };\n })\n .filter((x) => Date.parse(x.created_at) < endedAtMs);\n};\n\nconst fetchSpotOHLCBackward = async (req: {\n product_id: string;\n duration: string;\n time: number;\n series_id: string;\n}): Promise<IOHLC[]> => {\n const [, instType, currency_pair] = decodePath(req.product_id);\n if (instType !== 'SPOT' || !currency_pair) throw new Error(`Unsupported product_id: ${req.product_id}`);\n\n const interval = DURATION_TO_GATE_INTERVAL[req.duration];\n if (!interval) throw new Error(`Unsupported duration: ${req.duration}`);\n\n const offset = convertDurationToOffset(req.duration);\n const endedAtMs = req.time;\n const to = Math.floor(endedAtMs / 1000);\n\n const rows = await getSpotCandlesticks({\n currency_pair,\n interval,\n to,\n limit: 1000,\n });\n\n return (rows ?? [])\n .map((raw): IOHLC => {\n const k = normalizeCandle(raw);\n return {\n series_id: req.series_id,\n datasource_id: 'GATE',\n product_id: req.product_id,\n duration: req.duration,\n created_at: formatTime(k.tMs),\n closed_at: formatTime(k.tMs + offset),\n open: k.o,\n high: k.h,\n low: k.l,\n close: k.c,\n volume: k.v,\n open_interest: '0',\n };\n })\n .filter((x) => Date.parse(x.created_at) < endedAtMs);\n};\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'GATE/FUTURE/',\n duration_list: Object.keys(DURATION_TO_GATE_INTERVAL),\n direction: 'backward',\n },\n fetchFuturesOHLCBackward,\n);\n\nprovideOHLCService(\n terminal,\n {\n product_id_prefix: 'GATE/SPOT/',\n duration_list: Object.keys(DURATION_TO_GATE_INTERVAL),\n direction: 'backward',\n },\n fetchSpotOHLCBackward,\n);\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuants/vendor-gate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib",
|
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
"@yuants/transfer": "0.2.40",
|
|
14
14
|
"@yuants/data-account": "0.11.0",
|
|
15
15
|
"@yuants/data-order": "0.7.1",
|
|
16
|
+
"@yuants/data-ohlc": "0.4.23",
|
|
16
17
|
"@yuants/sql": "0.9.31",
|
|
17
18
|
"@yuants/data-product": "0.5.1",
|
|
18
19
|
"@yuants/utils": "0.15.0",
|
|
19
20
|
"@yuants/data-series": "0.3.53",
|
|
20
21
|
"@yuants/data-interest-rate": "0.1.49",
|
|
21
|
-
"@yuants/exchange": "0.8.
|
|
22
|
+
"@yuants/exchange": "0.8.1",
|
|
22
23
|
"@yuants/data-quote": "0.4.0",
|
|
23
24
|
"rxjs": "~7.5.6"
|
|
24
25
|
},
|
package/temp/package-deps.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"apps/vendor-gate/AGENTS.md": "59be8d734f8a91ae5f7377e7c688f1fccb8641b7",
|
|
3
|
-
"apps/vendor-gate/CHANGELOG.json": "
|
|
4
|
-
"apps/vendor-gate/CHANGELOG.md": "
|
|
3
|
+
"apps/vendor-gate/CHANGELOG.json": "01aa1c737bba1f76f25bb2dfa2fe59bcabc401a4",
|
|
4
|
+
"apps/vendor-gate/CHANGELOG.md": "e4ae0a1526b403e7362bd66827d4c1de77267f2f",
|
|
5
5
|
"apps/vendor-gate/README.md": "ea5ee3a61cd87d9104d729902dfaccac9b9913e0",
|
|
6
6
|
"apps/vendor-gate/SESSION_NOTES.md": "eefeaa9e02b039bde7180b6a479fc3fa0e72321c",
|
|
7
7
|
"apps/vendor-gate/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
|
|
@@ -9,37 +9,40 @@
|
|
|
9
9
|
"apps/vendor-gate/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
|
|
10
10
|
"apps/vendor-gate/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
|
|
11
11
|
"apps/vendor-gate/etc/vendor-gate.api.md": "970682cd589432de553cc5cee2a0abe73814a515",
|
|
12
|
-
"apps/vendor-gate/package.json": "
|
|
12
|
+
"apps/vendor-gate/package.json": "331ad65f8f32b5d07487797b8c71f8113fcf6d7d",
|
|
13
13
|
"apps/vendor-gate/src/api/http-client.ts": "97e0e70454c6072f388f90442ec4afabe6feb93b",
|
|
14
14
|
"apps/vendor-gate/src/api/private-api.ts": "7a3e2f74881651ee940d23d34025deab07abe3f0",
|
|
15
|
-
"apps/vendor-gate/src/api/public-api.ts": "
|
|
15
|
+
"apps/vendor-gate/src/api/public-api.ts": "02743d258c70cd0fbfc7fcc80a0603dd45f3a75e",
|
|
16
16
|
"apps/vendor-gate/src/api/rate-limiter.ts": "047c51029ffcaf98190cfd04d96816bbced5fa7c",
|
|
17
|
-
"apps/vendor-gate/src/index.ts": "
|
|
17
|
+
"apps/vendor-gate/src/index.ts": "2cb0c1c564616f5c114e624cd988eca8f4a6f124",
|
|
18
18
|
"apps/vendor-gate/src/services/accounts/profile.ts": "1420e22dfce97f741106abccd3bb769db34dfb5c",
|
|
19
19
|
"apps/vendor-gate/src/services/accounts/unified.ts": "2955a652857c54404f2c14142ef31d2ad67a05e0",
|
|
20
20
|
"apps/vendor-gate/src/services/default-credential.ts": "b9ffa157b818148450bfaaf4851597e91901190c",
|
|
21
21
|
"apps/vendor-gate/src/services/exchange.ts": "3a8fbaecaf7ea0c5a03f3a61f21fb8d2d4588394",
|
|
22
|
+
"apps/vendor-gate/src/services/interest-rate-service.ts": "2711ce1172fc1ea337871e3397d4b46214061f29",
|
|
22
23
|
"apps/vendor-gate/src/services/markets/interest-rate.ts": "e669eb1d664448f309bb062907b273157d1c111e",
|
|
23
24
|
"apps/vendor-gate/src/services/markets/product.ts": "1e62a06379a7833936ca1385bf639b5be5d5e07e",
|
|
24
25
|
"apps/vendor-gate/src/services/markets/quote.ts": "a213aa6505f0619e456403c764ee14d9d7cf3931",
|
|
26
|
+
"apps/vendor-gate/src/services/ohlc-service.ts": "9e5b037cfdae4b573ce8a3e464c8d5d60eb7d0f3",
|
|
25
27
|
"apps/vendor-gate/src/services/orders/cancelOrder.ts": "7dfdd30eaac89742f1050bf0fb47d8053ccecb28",
|
|
26
28
|
"apps/vendor-gate/src/services/orders/listOrders.ts": "cc59845c6ab9acb6b0513866aff56031a68328c2",
|
|
27
29
|
"apps/vendor-gate/src/services/orders/submitOrder.ts": "321398ad18bb4012d2a40e4f704bc827ccfaff93",
|
|
28
30
|
"apps/vendor-gate/src/services/quotes.ts": "7fa15e4e61197737cce040bbf4faadb968abbfbe",
|
|
29
31
|
"apps/vendor-gate/src/services/transfer.ts": "a1a7df99d74d5301b4f36ee9c168079874e73a40",
|
|
30
32
|
"apps/vendor-gate/tsconfig.json": "81da8f78196974b5d15da0edb6b2d9f48641063c",
|
|
31
|
-
"apps/vendor-gate/.rush/temp/shrinkwrap-deps.json": "
|
|
33
|
+
"apps/vendor-gate/.rush/temp/shrinkwrap-deps.json": "95f71ca2cec03122dda0b5c63c809ffede0bb891",
|
|
32
34
|
"libraries/cache/temp/package-deps.json": "e1f94620bc6245add32a4f9d379ed2901129d818",
|
|
33
35
|
"libraries/protocol/temp/package-deps.json": "c94931cb0eab7180d90a06d740c1a97c0ac0c6b6",
|
|
34
36
|
"libraries/transfer/temp/package-deps.json": "7b0db8291734d10d4f1d9c2c25d9e3918cabc79e",
|
|
35
37
|
"libraries/data-account/temp/package-deps.json": "d49586cd2fc2d6d025e585e5a5dd04d37c41263c",
|
|
36
38
|
"libraries/data-order/temp/package-deps.json": "8aa3e27ff80629d417bfe920e85d8525fbb52f42",
|
|
39
|
+
"libraries/data-ohlc/temp/package-deps.json": "8415ee90c49d7e84faaa2565cc1122fdacf73dab",
|
|
37
40
|
"libraries/sql/temp/package-deps.json": "041074e0102f9a01820c0fddcf82b9eaee226c79",
|
|
38
41
|
"libraries/data-product/temp/package-deps.json": "899bba8ace3f04b2035488ff9059e40732ef1d97",
|
|
39
42
|
"libraries/utils/temp/package-deps.json": "7f1eab07acae68df931b001594a522f050ace396",
|
|
40
43
|
"libraries/data-series/temp/package-deps.json": "a94e2f373c448a6205ee6c47e41d9283a76ee352",
|
|
41
44
|
"libraries/data-interest-rate/temp/package-deps.json": "5a1011b097b18b96c2d8c932d874f69472621efd",
|
|
42
|
-
"libraries/exchange/temp/package-deps.json": "
|
|
45
|
+
"libraries/exchange/temp/package-deps.json": "0f0549ddf97292ceadb8c3cbcc8799e31e7a0901",
|
|
43
46
|
"libraries/data-quote/temp/package-deps.json": "c2f009f818a503342bef588da21c9abd52beea00",
|
|
44
47
|
"libraries/extension/temp/package-deps.json": "3e0a81b0c863c2daf342dfaf284b8fd7d18c8562",
|
|
45
48
|
"tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"
|