@tradejs/cli 1.0.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/README.md +65 -0
- package/dist/cli.js +10727 -0
- package/dist/lib/runBot.js +157 -0
- package/dist/scripts/backtest.js +2044 -0
- package/dist/scripts/bot.js +153 -0
- package/dist/scripts/cleanDir.js +40 -0
- package/dist/scripts/cleanRedis.js +40 -0
- package/dist/scripts/cleanTests.js +81 -0
- package/dist/scripts/continuity.js +183 -0
- package/dist/scripts/derivativesIngest.js +107 -0
- package/dist/scripts/derivativesIngestCoinalyzeAll.js +391 -0
- package/dist/scripts/doctor.js +5143 -0
- package/dist/scripts/findMlSignalsByTestSuite.js +83 -0
- package/dist/scripts/infraCommon.js +135 -0
- package/dist/scripts/infraDown.js +82 -0
- package/dist/scripts/infraInit.js +107 -0
- package/dist/scripts/infraUp.js +82 -0
- package/dist/scripts/migration.js +67 -0
- package/dist/scripts/mlExport.js +95 -0
- package/dist/scripts/mlExportSelect.js +100 -0
- package/dist/scripts/mlInspect.js +553 -0
- package/dist/scripts/mlTrainLatestSelect.js +1056 -0
- package/dist/scripts/results.js +1909 -0
- package/dist/scripts/selectStrategy.js +99 -0
- package/dist/scripts/signals.js +300 -0
- package/dist/scripts/test-ml.js +133 -0
- package/dist/scripts/test.js +16 -0
- package/dist/scripts/user-add.js +64 -0
- package/dist/workers/testerWorker.js +54 -0
- package/package.json +75 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/lib/runBot.ts
|
|
31
|
+
var runBot_exports = {};
|
|
32
|
+
__export(runBot_exports, {
|
|
33
|
+
runBot: () => runBot
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(runBot_exports);
|
|
36
|
+
var import_lodash = __toESM(require("lodash"));
|
|
37
|
+
var import_connectors = require("@tradejs/node/connectors");
|
|
38
|
+
var import_json = require("@tradejs/core/json");
|
|
39
|
+
var import_strategies = require("@tradejs/node/strategies");
|
|
40
|
+
var import_async = require("@tradejs/core/async");
|
|
41
|
+
var import_constants = require("@tradejs/core/constants");
|
|
42
|
+
var import_time = require("@tradejs/core/time");
|
|
43
|
+
var import_logger = require("@tradejs/infra/logger");
|
|
44
|
+
var import_redis = require("@tradejs/infra/redis");
|
|
45
|
+
var runBot = async () => {
|
|
46
|
+
const botResults = [];
|
|
47
|
+
const preloadStart = (0, import_time.getTimestamp)(import_constants.BOT_PRELOAD_DAYS);
|
|
48
|
+
const end = (0, import_time.getTimestamp)();
|
|
49
|
+
const keys = await (0, import_redis.getKeys)(import_redis.redisKeys.botsPrefix());
|
|
50
|
+
const botKeys = keys.filter((key) => key.endsWith(":bots"));
|
|
51
|
+
await (0, import_async.delay)(5e3);
|
|
52
|
+
import_logger.logger.log("info", "files count: %s", botKeys.length);
|
|
53
|
+
for await (const key of botKeys) {
|
|
54
|
+
const userName = key.split(":")[1];
|
|
55
|
+
import_logger.logger.log("info", "user: %s", userName);
|
|
56
|
+
const botConfig = await (0, import_redis.getData)(import_redis.redisKeys.bots(userName));
|
|
57
|
+
if (import_lodash.default.isEmpty(botConfig)) {
|
|
58
|
+
import_logger.logger.log("error", "botConfig is empty: %s", userName);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
import_logger.logger.log("info", "bots count: %s", botConfig.length);
|
|
62
|
+
for await (const bot of botConfig) {
|
|
63
|
+
const { symbol, strategyName, strategyConfig, connectorName, disabled } = bot;
|
|
64
|
+
import_logger.logger.log("info", "bot %s", symbol);
|
|
65
|
+
if (disabled) {
|
|
66
|
+
import_logger.logger.log("error", "bot %s disabled", symbol);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const strategyCreator = await (0, import_strategies.getStrategyCreator)(strategyName);
|
|
71
|
+
if (!strategyCreator) {
|
|
72
|
+
throw new Error(`Unknown strategy: ${strategyName}`);
|
|
73
|
+
}
|
|
74
|
+
const connectorCreator = await (0, import_connectors.getConnectorCreatorByName)(connectorName);
|
|
75
|
+
if (!connectorCreator) {
|
|
76
|
+
throw new Error(`Unknown connector: ${connectorName}`);
|
|
77
|
+
}
|
|
78
|
+
const connector = await connectorCreator({
|
|
79
|
+
userName
|
|
80
|
+
});
|
|
81
|
+
const binanceConnectorCreator = await (0, import_connectors.getConnectorCreatorByName)(
|
|
82
|
+
import_connectors.BUILTIN_CONNECTOR_NAMES.Binance
|
|
83
|
+
);
|
|
84
|
+
const coinbaseConnectorCreator = await (0, import_connectors.getConnectorCreatorByName)(
|
|
85
|
+
import_connectors.BUILTIN_CONNECTOR_NAMES.Coinbase
|
|
86
|
+
);
|
|
87
|
+
if (!binanceConnectorCreator || !coinbaseConnectorCreator) {
|
|
88
|
+
throw new Error("Binance/Coinbase connectors are required");
|
|
89
|
+
}
|
|
90
|
+
const [binanceConnector, coinbaseConnector] = await Promise.all([
|
|
91
|
+
binanceConnectorCreator({
|
|
92
|
+
userName
|
|
93
|
+
}),
|
|
94
|
+
coinbaseConnectorCreator({
|
|
95
|
+
userName
|
|
96
|
+
})
|
|
97
|
+
]);
|
|
98
|
+
const interval = "15";
|
|
99
|
+
const data = await connector.kline({
|
|
100
|
+
symbol,
|
|
101
|
+
start: preloadStart,
|
|
102
|
+
end,
|
|
103
|
+
interval
|
|
104
|
+
});
|
|
105
|
+
const [btcData, btcBinanceData, btcCoinbaseData] = await Promise.all([
|
|
106
|
+
connector.kline({
|
|
107
|
+
symbol: "BTCUSDT",
|
|
108
|
+
start: preloadStart,
|
|
109
|
+
end,
|
|
110
|
+
interval
|
|
111
|
+
}),
|
|
112
|
+
binanceConnector.kline({
|
|
113
|
+
symbol: "BTCUSDT",
|
|
114
|
+
start: preloadStart,
|
|
115
|
+
end,
|
|
116
|
+
interval
|
|
117
|
+
}),
|
|
118
|
+
coinbaseConnector.kline({
|
|
119
|
+
symbol: "BTCUSDT",
|
|
120
|
+
start: preloadStart,
|
|
121
|
+
end,
|
|
122
|
+
interval
|
|
123
|
+
})
|
|
124
|
+
]);
|
|
125
|
+
const candle = data.pop();
|
|
126
|
+
const btcCandle = btcData.pop();
|
|
127
|
+
const strategy = await strategyCreator({
|
|
128
|
+
userName,
|
|
129
|
+
config: strategyConfig,
|
|
130
|
+
symbol,
|
|
131
|
+
data,
|
|
132
|
+
btcData,
|
|
133
|
+
btcBinanceData,
|
|
134
|
+
btcCoinbaseData,
|
|
135
|
+
connector
|
|
136
|
+
});
|
|
137
|
+
import_logger.logger.log("info", "strategy created");
|
|
138
|
+
if (!candle || !btcCandle) {
|
|
139
|
+
throw new Error("Candle is empty");
|
|
140
|
+
}
|
|
141
|
+
const status = await strategy(candle, btcCandle);
|
|
142
|
+
botResults.push({
|
|
143
|
+
symbol,
|
|
144
|
+
status: JSON.stringify(status)
|
|
145
|
+
});
|
|
146
|
+
} catch (err) {
|
|
147
|
+
import_logger.logger.log("error", "bot %s error: %s", bot.symbol, (0, import_json.toJson)(err, false));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
import_logger.logger.log("info", "botResults: %s", (0, import_json.toJson)(botResults, true));
|
|
152
|
+
return botResults;
|
|
153
|
+
};
|
|
154
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
+
0 && (module.exports = {
|
|
156
|
+
runBot
|
|
157
|
+
});
|