@clonegod/ttd-core 3.0.8 → 3.0.10

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.
@@ -31,7 +31,7 @@ class EnvArgs {
31
31
  this.quote_pool_fee_rate = parseInt(process.env.QUOTE_POOL_FEE_RATE || '0');
32
32
  this.trade_group_id = process.env.TRADE_GROUP_ID || '';
33
33
  this.trade_pair = process.env.TRADE_PAIR || '';
34
- this.token_price_cache_seconds = parseInt(process.env.TOKEN_PRICE_CACHE_SECONDS || '600');
34
+ this.token_price_cache_seconds = parseInt(process.env.TOKEN_PRICE_CACHE_SECONDS || '1200');
35
35
  }
36
36
  print() {
37
37
  console.log('>>> EnvArgs', this);
@@ -17,18 +17,20 @@ const axios_1 = __importDefault(require("axios"));
17
17
  const index_1 = require("../../index");
18
18
  function fetchPriceFromDefiLlama(network, addresses) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
+ var _a;
20
21
  const result = new Map();
21
22
  const currentTime = (0, index_1.getCurDateTime)();
22
23
  const timeout = 10000;
23
- const maxRetries = 3;
24
+ const maxRetries = 1;
24
25
  const retrysleepMs = 1000;
25
26
  const addressString = addresses.map(address => `${network.toLowerCase()}:${address}`).join(',');
26
27
  const url = `https://coins.llama.fi/prices/current/${addressString}`;
27
28
  console.log(url);
28
29
  (0, index_1.log_debug)(`[fetchPriceFromDefiLlama] Requesting prices for ${addresses.length} tokens`);
29
- let retryCount = 0;
30
- while (retryCount <= maxRetries) {
30
+ let attempt = 0;
31
+ while (attempt <= maxRetries) {
31
32
  try {
33
+ attempt++;
32
34
  const response = yield axios_1.default.get(url, { timeout });
33
35
  let tokenPrices = response.data['coins'];
34
36
  if (tokenPrices) {
@@ -51,10 +53,14 @@ function fetchPriceFromDefiLlama(network, addresses) {
51
53
  break;
52
54
  }
53
55
  catch (error) {
54
- retryCount++;
55
- (0, index_1.log_warn)(`[fetchPriceFromDefiLlama] Request failed (attempt ${retryCount}/${maxRetries}): ${error instanceof Error ? error.message : String(error)}`);
56
- if (retryCount <= maxRetries) {
57
- const currentRetrysleep = retrysleepMs * retryCount;
56
+ const status = axios_1.default.isAxiosError(error) ? (_a = error.response) === null || _a === void 0 ? void 0 : _a.status : undefined;
57
+ (0, index_1.log_warn)(`[fetchPriceFromDefiLlama] Request failed (attempt ${attempt}/${maxRetries + 1}): ${error instanceof Error ? error.message : String(error)}`);
58
+ if (status === 429) {
59
+ (0, index_1.log_warn)(`[fetchPriceFromDefiLlama] Rate limited (429). Skip retries and fallback to next channel immediately.`);
60
+ break;
61
+ }
62
+ if (attempt <= maxRetries) {
63
+ const currentRetrysleep = retrysleepMs * attempt;
58
64
  (0, index_1.log_debug)(`[fetchPriceFromDefiLlama] Retrying in ${currentRetrysleep}ms...`);
59
65
  yield (0, index_1.sleep)(currentRetrysleep);
60
66
  }
@@ -17,18 +17,20 @@ const axios_1 = __importDefault(require("axios"));
17
17
  const index_1 = require("../../index");
18
18
  function fetchPriceFromGeckoTerminal(network, addresses) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
+ var _a;
20
21
  const result = new Map();
21
22
  const currentTime = (0, index_1.getCurDateTime)();
22
23
  const timeout = 10000;
23
- const maxRetries = 3;
24
+ const maxRetries = 1;
24
25
  const retrysleepMs = 1000;
25
26
  const addressString = addresses.join(',');
26
27
  const url = `https://api.geckoterminal.com/api/v2/simple/networks/${network.toLowerCase()}/token_price/${addressString}`;
27
28
  console.log(url);
28
29
  (0, index_1.log_debug)(`[fetchPriceFromGeckoTerminal] Requesting prices for ${addresses.length} tokens`);
29
- let retryCount = 0;
30
- while (retryCount <= maxRetries) {
30
+ let attempt = 0;
31
+ while (attempt <= maxRetries) {
31
32
  try {
33
+ attempt++;
32
34
  const response = yield axios_1.default.get(url, { timeout });
33
35
  if (response.data && response.data.data && response.data.data.attributes && response.data.data.attributes.token_prices) {
34
36
  const tokenPrices = response.data.data.attributes.token_prices;
@@ -57,10 +59,14 @@ function fetchPriceFromGeckoTerminal(network, addresses) {
57
59
  break;
58
60
  }
59
61
  catch (error) {
60
- retryCount++;
61
- (0, index_1.log_warn)(`[fetchPriceFromGeckoTerminal] Request failed (attempt ${retryCount}/${maxRetries}): ${error instanceof Error ? error.message : String(error)}`);
62
- if (retryCount <= maxRetries) {
63
- const currentRetrysleep = retrysleepMs * retryCount;
62
+ const status = axios_1.default.isAxiosError(error) ? (_a = error.response) === null || _a === void 0 ? void 0 : _a.status : undefined;
63
+ (0, index_1.log_warn)(`[fetchPriceFromGeckoTerminal] Request failed (attempt ${attempt}/${maxRetries + 1}): ${error instanceof Error ? error.message : String(error)}`);
64
+ if (status === 429) {
65
+ (0, index_1.log_warn)(`[fetchPriceFromGeckoTerminal] Rate limited (429). Skip retries and fallback to next channel immediately.`);
66
+ break;
67
+ }
68
+ if (attempt <= maxRetries) {
69
+ const currentRetrysleep = retrysleepMs * attempt;
64
70
  (0, index_1.log_debug)(`[fetchPriceFromGeckoTerminal] Retrying in ${currentRetrysleep}ms...`);
65
71
  yield (0, index_1.sleep)(currentRetrysleep);
66
72
  }
@@ -101,16 +101,18 @@ function get_solana_token_price_info(addresses) {
101
101
  }
102
102
  function fetchPriceFromJupiter(addresses) {
103
103
  return __awaiter(this, void 0, void 0, function* () {
104
+ var _a;
104
105
  const result = new Map();
105
106
  const currentTime = (0, index_1.getCurDateTime)();
106
107
  const timeout = 6000;
107
- const maxRetries = 2;
108
- const retrysleepMs = 500;
108
+ const maxRetries = 1;
109
+ const retrysleepMs = 1000;
109
110
  const url = (process.env.JUPITER_PRICE_API || 'https://api.jup.ag/price/v3') + `?ids=${addresses.join(',')}`;
110
111
  (0, index_1.log_debug)(`[fetchPriceFromJupiter] Requesting Jupiter API for ${addresses.length} tokens`);
111
- let retryCount = 0;
112
- while (retryCount <= maxRetries) {
112
+ let attempt = 0;
113
+ while (attempt <= maxRetries) {
113
114
  try {
115
+ attempt++;
114
116
  const response = yield axios_1.default.get(url, {
115
117
  headers: {
116
118
  'x-api-key': process.env.JUPITER_API_KEY
@@ -138,10 +140,14 @@ function fetchPriceFromJupiter(addresses) {
138
140
  break;
139
141
  }
140
142
  catch (error) {
141
- retryCount++;
142
- (0, index_1.log_warn)(`[fetchPriceFromJupiter] Request failed (attempt ${retryCount}/${maxRetries}): ${error instanceof Error ? error.message : String(error)}, url: ${url}`);
143
- if (retryCount <= maxRetries) {
144
- const currentRetrysleep = retrysleepMs * retryCount;
143
+ const status = axios_1.default.isAxiosError(error) ? (_a = error.response) === null || _a === void 0 ? void 0 : _a.status : undefined;
144
+ (0, index_1.log_warn)(`[fetchPriceFromJupiter] Request failed (attempt ${attempt}/${maxRetries + 1}): ${error instanceof Error ? error.message : String(error)}, url: ${url}`);
145
+ if (status === 429) {
146
+ (0, index_1.log_warn)(`[fetchPriceFromJupiter] Rate limited (429). Skip retries and fallback to next channel immediately.`);
147
+ break;
148
+ }
149
+ if (attempt <= maxRetries) {
150
+ const currentRetrysleep = retrysleepMs * attempt;
145
151
  (0, index_1.log_debug)(`[fetchPriceFromJupiter] Retrying in ${currentRetrysleep}ms...`);
146
152
  yield (0, index_1.sleep)(currentRetrysleep);
147
153
  }
@@ -33,7 +33,7 @@ const fetchPriceFromCache = (token_address_list) => __awaiter(void 0, void 0, vo
33
33
  (0, __1.log_warn)('global_app_config is not set, skip get token price from cache');
34
34
  return result;
35
35
  }
36
- let token_price_timeout_seconds = 600;
36
+ let token_price_timeout_seconds = global_app_config.env_args.token_price_cache_seconds;
37
37
  let all_token_list = yield global_app_config.arb_cache.get_token_list();
38
38
  let token_list = all_token_list.filter(e => token_address_list.includes(e.address) && !(0, __1.isEmpty)(e.market_price) && !(0, __1.isEmpty)(e.update_time));
39
39
  let not_found_token_list = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-core",
3
- "version": "3.0.8",
3
+ "version": "3.0.10",
4
4
  "description": "Common types and utilities for trading systems - use `npm run push` to publish",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/types/index.d.ts CHANGED
@@ -346,6 +346,12 @@ export interface Ladder {
346
346
  // 询价生成的价格,所对应的slot (account, vaultA, vaultB)
347
347
  slot: string
348
348
 
349
+ // 区块号
350
+ blockNumber?: string
351
+
352
+ // ��格来源: "rpc:v1" | "{provider_id}:v2" | "{provider_id}:v3"
353
+ source?: string
354
+
349
355
  // unique_orderbook_id 价格更新时间
350
356
  price_id: string
351
357
  price_time: string