@clonegod/ttd-core 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/analyze/index.d.ts +3 -0
- package/dist/analyze/index.js +49 -0
- package/dist/app_config/app_config.d.ts +15 -0
- package/dist/app_config/app_config.js +50 -0
- package/dist/app_config/env_args.d.ts +16 -0
- package/dist/app_config/env_args.js +28 -0
- package/dist/app_config/index.d.ts +2 -0
- package/dist/app_config/index.js +18 -0
- package/dist/cache/arb_cache.d.ts +80 -0
- package/dist/cache/arb_cache.js +1010 -0
- package/dist/cache/arb_event_pub.d.ts +14 -0
- package/dist/cache/arb_event_pub.js +77 -0
- package/dist/cache/arb_event_sub.d.ts +17 -0
- package/dist/cache/arb_event_sub.js +166 -0
- package/dist/cache/index.d.ts +6 -0
- package/dist/cache/index.js +22 -0
- package/dist/cache/loading_cache.d.ts +62 -0
- package/dist/cache/loading_cache.js +233 -0
- package/dist/cache/redis_client.d.ts +3 -0
- package/dist/cache/redis_client.js +73 -0
- package/dist/cache/redis_cmd.d.ts +14 -0
- package/dist/cache/redis_cmd.js +83 -0
- package/dist/index.d.ts +216 -0
- package/dist/index.js +883 -0
- package/dist/market_price/estimate_token_amount.d.ts +4 -0
- package/dist/market_price/estimate_token_amount.js +109 -0
- package/dist/market_price/index.d.ts +1 -0
- package/dist/market_price/index.js +17 -0
- package/dist/pool/cache_pool_config.d.ts +2 -0
- package/dist/pool/cache_pool_config.js +116 -0
- package/dist/pool/index.d.ts +3 -0
- package/dist/pool/index.js +19 -0
- package/dist/pool/pool_util.d.ts +5 -0
- package/dist/pool/pool_util.js +65 -0
- package/dist/pool/types.d.ts +20 -0
- package/dist/pool/types.js +2 -0
- package/dist/quote/index.d.ts +1 -0
- package/dist/quote/index.js +17 -0
- package/dist/quote/log_quote_price.d.ts +2 -0
- package/dist/quote/log_quote_price.js +29 -0
- package/dist/quote/on_quote_response.d.ts +3 -0
- package/dist/quote/on_quote_response.js +28 -0
- package/dist/quote/publish_quote_price.d.ts +3 -0
- package/dist/quote/publish_quote_price.js +19 -0
- package/dist/quote/to_price_message.d.ts +5 -0
- package/dist/quote/to_price_message.js +103 -0
- package/dist/test/test_is_empty.d.ts +1 -0
- package/dist/test/test_is_empty.js +24 -0
- package/dist/test/test_log_level.d.ts +3 -0
- package/dist/test/test_log_level.js +29 -0
- package/dist/test/test_merge_property.d.ts +1 -0
- package/dist/test/test_merge_property.js +21 -0
- package/dist/token/cache_token_config.d.ts +2 -0
- package/dist/token/cache_token_config.js +68 -0
- package/dist/token/fixed_symbol_address.d.ts +2 -0
- package/dist/token/fixed_symbol_address.js +26 -0
- package/dist/token/index.d.ts +6 -0
- package/dist/token/index.js +22 -0
- package/dist/token/is_not_arb_token.d.ts +1 -0
- package/dist/token/is_not_arb_token.js +24 -0
- package/dist/token/price/gecko_terminal.d.ts +2 -0
- package/dist/token/price/gecko_terminal.js +69 -0
- package/dist/token/price/get_bsc_token_price.d.ts +2 -0
- package/dist/token/price/get_bsc_token_price.js +131 -0
- package/dist/token/price/get_solana_token_price.d.ts +2 -0
- package/dist/token/price/get_solana_token_price.js +17 -0
- package/dist/token/price/get_tron_token_price.d.ts +2 -0
- package/dist/token/price/get_tron_token_price.js +17 -0
- package/dist/token/price/index.d.ts +3 -0
- package/dist/token/price/index.js +19 -0
- package/dist/token/token_util.d.ts +3 -0
- package/dist/token/token_util.js +23 -0
- package/dist/token/types.d.ts +29 -0
- package/dist/token/types.js +2 -0
- package/package.json +47 -0
- package/types/index.d.ts +709 -0
package/README.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { OrderMessageType, PriceMessageType } from "../../types";
|
|
2
|
+
export declare const report_trade_analyze_data: (type: string, message: PriceMessageType | OrderMessageType) => void;
|
|
3
|
+
export declare const get_pool_latest_quote_price: (unique_orderbook_id: string) => Promise<PriceMessageType>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.get_pool_latest_quote_price = exports.report_trade_analyze_data = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const index_1 = require("../index");
|
|
18
|
+
const trade_analyze_url = process.env.TRADE_ANALYZE_URL || `http://localhost:8004/trade/analyze`;
|
|
19
|
+
const report_trade_log = process.env.REPORT_TRADE_LOG === 'true';
|
|
20
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
21
|
+
const report_trade_analyze_data = (type, message) => {
|
|
22
|
+
const body = {
|
|
23
|
+
type,
|
|
24
|
+
message
|
|
25
|
+
};
|
|
26
|
+
if (!report_trade_log) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
axios_1.default.post(trade_analyze_url, body, { headers })
|
|
30
|
+
.then(res => (0, index_1.log_trace)('report_trade_analzye_data, success, res=', res.data))
|
|
31
|
+
.catch(err => (0, index_1.log_warn)(`report_trade_analzye_data, error: ${err.message}`));
|
|
32
|
+
};
|
|
33
|
+
exports.report_trade_analyze_data = report_trade_analyze_data;
|
|
34
|
+
const get_pool_latest_quote_price = (unique_orderbook_id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
let price_msg = null;
|
|
36
|
+
let url = `${trade_analyze_url}/price_msg?unique_orderbook_id=${unique_orderbook_id}`;
|
|
37
|
+
if (!(0, index_1.isEmpty)(unique_orderbook_id)) {
|
|
38
|
+
try {
|
|
39
|
+
let res = (yield axios_1.default.get(url, { headers })).data;
|
|
40
|
+
let { code, msg, data } = res;
|
|
41
|
+
price_msg = data;
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
(0, index_1.log_error)(`get_pool_latest_quote_price error! url=${url}`, new Error(err.message));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return price_msg;
|
|
48
|
+
});
|
|
49
|
+
exports.get_pool_latest_quote_price = get_pool_latest_quote_price;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import EventEmitter from "events";
|
|
2
|
+
import { DEX_ID } from "..";
|
|
3
|
+
import { ArbCache, ArbEventSubscriber } from "../cache";
|
|
4
|
+
import { EnvArgs } from "./env_args";
|
|
5
|
+
export declare class AppConfig extends EventEmitter {
|
|
6
|
+
env_args: EnvArgs;
|
|
7
|
+
app_full_name: string;
|
|
8
|
+
arb_cache: ArbCache;
|
|
9
|
+
dex_id: DEX_ID;
|
|
10
|
+
arb_event_subscriber: ArbEventSubscriber;
|
|
11
|
+
query_token_market_price_url: string;
|
|
12
|
+
constructor();
|
|
13
|
+
init(): Promise<void>;
|
|
14
|
+
subscribe_config_change(): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AppConfig = void 0;
|
|
16
|
+
const events_1 = __importDefault(require("events"));
|
|
17
|
+
const __1 = require("..");
|
|
18
|
+
const env_args_1 = require("./env_args");
|
|
19
|
+
class AppConfig extends events_1.default {
|
|
20
|
+
constructor() {
|
|
21
|
+
super();
|
|
22
|
+
this.env_args = new env_args_1.EnvArgs();
|
|
23
|
+
let { chain_id, app_name, dex_id } = this.env_args;
|
|
24
|
+
this.app_full_name = `${chain_id}_${dex_id}_${app_name}`;
|
|
25
|
+
this.dex_id = dex_id;
|
|
26
|
+
}
|
|
27
|
+
init() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
this.arb_cache = (0, __1.getArbCache)(this.env_args);
|
|
30
|
+
yield this.arb_cache.init();
|
|
31
|
+
let common_service_config = yield this.arb_cache.get_common_service();
|
|
32
|
+
if ((0, __1.isEmpty)(common_service_config)) {
|
|
33
|
+
throw new Error(`get_common_service from cache failed! read from cache=${(0, __1.to_json_str)(common_service_config)}`);
|
|
34
|
+
}
|
|
35
|
+
let { config_center } = common_service_config;
|
|
36
|
+
this.query_token_market_price_url = this.env_args.token_market_price_url
|
|
37
|
+
.replace('${config_center_http_port}', config_center.http_port + '')
|
|
38
|
+
.replace('${chain_id}', this.env_args.chain_id);
|
|
39
|
+
yield this.subscribe_config_change();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
subscribe_config_change() {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
this.arb_event_subscriber = (0, __1.getArbEventSubscriber)(this.arb_cache);
|
|
45
|
+
yield this.arb_event_subscriber.pre_load_config_cache();
|
|
46
|
+
yield this.arb_event_subscriber.subscribe_config_change_event();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.AppConfig = AppConfig;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CHAIN_ID, DEX_ID } from "..";
|
|
2
|
+
export declare class EnvArgs {
|
|
3
|
+
chain_id: CHAIN_ID;
|
|
4
|
+
app_name: string;
|
|
5
|
+
dex_id: DEX_ID;
|
|
6
|
+
pair_list: string[];
|
|
7
|
+
redis_host: string;
|
|
8
|
+
redis_port: string;
|
|
9
|
+
rpc_endpoint: string;
|
|
10
|
+
ws_endpoint: string;
|
|
11
|
+
token_market_price_url: string;
|
|
12
|
+
auto_quote_enable: boolean;
|
|
13
|
+
auto_quote_interval_seconds: number;
|
|
14
|
+
token_market_pairce_cache_expire_mills: number;
|
|
15
|
+
constructor();
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnvArgs = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class EnvArgs {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.app_name = process.env.APP_NAME || '';
|
|
8
|
+
this.chain_id = process.env.CHAIN_ID.toUpperCase();
|
|
9
|
+
if ((0, __1.isEmpty)(this.chain_id)) {
|
|
10
|
+
throw new Error(`environment: CHAIN_ID is empty!!!`);
|
|
11
|
+
}
|
|
12
|
+
this.dex_id = process.env.DEX_ID.toUpperCase();
|
|
13
|
+
if ((0, __1.isEmpty)(this.dex_id)) {
|
|
14
|
+
throw new Error(`Invalid config: DEX_ID=${process.env.DEX_ID}!!!`);
|
|
15
|
+
}
|
|
16
|
+
this.pair_list = process.env.PAIR_LIST.split(',').filter(Boolean);
|
|
17
|
+
this.redis_host = process.env.REDIS_HOST;
|
|
18
|
+
this.redis_port = process.env.REDIS_PORT;
|
|
19
|
+
this.rpc_endpoint = process.env.RPC_ENDPOINT;
|
|
20
|
+
this.ws_endpoint = process.env.WS_ENDPOINT;
|
|
21
|
+
this.token_market_price_url = process.env.TOKEN_MARKET_PRICE_URL;
|
|
22
|
+
this.auto_quote_enable = process.env.AUTO_QUOTE_ENABLE === 'true';
|
|
23
|
+
this.auto_quote_interval_seconds = parseInt(process.env.AUTO_QUOTE_INTERVAL_SECONDS || '60');
|
|
24
|
+
this.token_market_pairce_cache_expire_mills = parseInt(process.env.TOKEN_MARKET_PAIRCE_CACHE_EXPIRE_MILLS || '600000');
|
|
25
|
+
(0, __1.log_info)('Env args init finish', this);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.EnvArgs = EnvArgs;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./env_args"), exports);
|
|
18
|
+
__exportStar(require("./app_config"), exports);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { CommonServiceType, LoadingCache, OrderMessageType, PriceMessageType, RedisCommand, StandardDexPoolConfigType, StandardPairType, StandardPoolInfoType, StandardTokenInfoType, TradePairDexPoolsType, TradePairType, TradeResponseType, TradeRuntimeType, TradeServiceConfigType } from "../../types";
|
|
3
|
+
import { CHAIN_ID } from "../index";
|
|
4
|
+
import { ArbEventPublisher } from './arb_event_pub';
|
|
5
|
+
export declare class ArbCache {
|
|
6
|
+
chain_id: CHAIN_ID;
|
|
7
|
+
loading_cache: LoadingCache;
|
|
8
|
+
redis_cmd: RedisCommand;
|
|
9
|
+
redis_event_publisher: ArbEventPublisher;
|
|
10
|
+
token_list: StandardTokenInfoType[];
|
|
11
|
+
token_symbol_map: Map<string, StandardTokenInfoType>;
|
|
12
|
+
token_address_map: Map<string, StandardTokenInfoType>;
|
|
13
|
+
token_list_cache_last_update_time: string;
|
|
14
|
+
pool_list: StandardPoolInfoType[];
|
|
15
|
+
pool_address_map: Map<string, StandardPoolInfoType>;
|
|
16
|
+
pool_list_cahce_last_update_time: string;
|
|
17
|
+
trade_config_list: TradeServiceConfigType[];
|
|
18
|
+
trade_config_map: Map<string, TradeServiceConfigType>;
|
|
19
|
+
trade_config_cache_last_update_time: string;
|
|
20
|
+
event_emitter: EventEmitter;
|
|
21
|
+
constructor(env_args: any);
|
|
22
|
+
init(): Promise<void>;
|
|
23
|
+
init_configs(): Promise<void>;
|
|
24
|
+
get_config_filepath(suffix: string): string;
|
|
25
|
+
get_bak_config_filepath(suffix: string): string;
|
|
26
|
+
refresh_local_cache_token_list(token_list: StandardTokenInfoType[]): void;
|
|
27
|
+
refresh_local_cache_pool_list(pool_list: StandardPoolInfoType[]): void;
|
|
28
|
+
refresh_local_cache_group_map(trade_config: TradeServiceConfigType): void;
|
|
29
|
+
cache_token_list(): Promise<void>;
|
|
30
|
+
update_token_list(input_token_list: StandardTokenInfoType[]): Promise<void>;
|
|
31
|
+
get_token_list(): Promise<StandardTokenInfoType[]>;
|
|
32
|
+
get_token_list_no_cache(): Promise<StandardTokenInfoType[]>;
|
|
33
|
+
get_one_token_info_by_symbol(symbol: string): Promise<StandardTokenInfoType>;
|
|
34
|
+
publish_token_change_event(): Promise<void>;
|
|
35
|
+
cache_pool_list(): Promise<void>;
|
|
36
|
+
set_pool_token_info(pool: StandardPoolInfoType, token_info_list: StandardTokenInfoType[]): void;
|
|
37
|
+
set_pool_extra(pool: StandardPoolInfoType): void;
|
|
38
|
+
update_pool_list(input_dex_pool_list: StandardDexPoolConfigType[]): Promise<void>;
|
|
39
|
+
get_pool_list_by_pair(pair: string): Promise<StandardPoolInfoType[]>;
|
|
40
|
+
get_pool_list(): Promise<StandardPoolInfoType[]>;
|
|
41
|
+
get_pool_list_no_cache(): Promise<StandardPoolInfoType[]>;
|
|
42
|
+
get_one_pool_info(pool_address: string, refresh_cache_if_not_found?: boolean): Promise<StandardPoolInfoType>;
|
|
43
|
+
publish_pool_change_event(): Promise<void>;
|
|
44
|
+
get_one_pair(input_pair: string): Promise<StandardPairType>;
|
|
45
|
+
get_pair_list(input_pair?: string): Promise<StandardPairType[]>;
|
|
46
|
+
cache_common_service(): Promise<void>;
|
|
47
|
+
get_common_service(): Promise<CommonServiceType>;
|
|
48
|
+
cache_trade_group(update_group_id?: string): Promise<void>;
|
|
49
|
+
update_trade_group(input_trade_config: TradeServiceConfigType): Promise<void>;
|
|
50
|
+
get_trade_group_id_list(): Promise<string[]>;
|
|
51
|
+
get_trade_service_by_group_id(group_id: string): Promise<TradeServiceConfigType>;
|
|
52
|
+
get_trade_service_by_group_id_no_cache(group_id: string): Promise<TradeServiceConfigType>;
|
|
53
|
+
create_trade_runtime(chain_id: string, group_id: string, dex_id: string, pair_name: string): Promise<TradeRuntimeType>;
|
|
54
|
+
find_pair_in_trade_config(pair_name: string, trade_config: TradeServiceConfigType): TradePairType;
|
|
55
|
+
find_pair_dex_in_trade_config(dex_id: string, pair_config: TradePairType): TradePairDexPoolsType;
|
|
56
|
+
cache_token_market_price(token_with_price: StandardTokenInfoType, ttl?: number): Promise<void>;
|
|
57
|
+
get_token_market_price(symbol: string): Promise<StandardTokenInfoType>;
|
|
58
|
+
cache_price_message(price_msg: PriceMessageType, ttl?: number): Promise<void>;
|
|
59
|
+
get_price_message(price_id: string): Promise<PriceMessageType>;
|
|
60
|
+
cache_order_message(order_msg: OrderMessageType, ttl?: number): Promise<{
|
|
61
|
+
key: string;
|
|
62
|
+
field: string;
|
|
63
|
+
res: number[];
|
|
64
|
+
ttl: number;
|
|
65
|
+
}>;
|
|
66
|
+
get_order_message(group_id: string, price_id: string, order_trace_id: string): Promise<OrderMessageType>;
|
|
67
|
+
cache_trade_result(trade_result: TradeResponseType, ttl?: number): Promise<{
|
|
68
|
+
key: string;
|
|
69
|
+
field: string;
|
|
70
|
+
res: number[];
|
|
71
|
+
ttl: number;
|
|
72
|
+
}>;
|
|
73
|
+
get_trade_result(group_id: string, txid: string): Promise<TradeResponseType>;
|
|
74
|
+
listen_trade_result(event_emitter: EventEmitter): void;
|
|
75
|
+
get_pair_dex_pool_list(quote_pair_list: string[], dex_id_list: string[]): Promise<StandardPoolInfoType[]>;
|
|
76
|
+
get_trade_dex_pool_list(dex_id_list: string[], trade_runtime: TradeRuntimeType): Promise<StandardPoolInfoType[]>;
|
|
77
|
+
get_group_trade_pair_info(chain_id: CHAIN_ID, group_id: string, pair: string): Promise<Map<string, StandardPairType>>;
|
|
78
|
+
get_all_trade_tokens(): Promise<StandardTokenInfoType[]>;
|
|
79
|
+
get_all_trade_pools(group_id?: string): Promise<StandardPoolInfoType[]>;
|
|
80
|
+
}
|