@3rd-eye-labs/openmm 0.1.6 → 0.1.9
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/routes/health.js +1 -1
- package/dist/api/routes/health.js.map +1 -1
- package/dist/cli/commands/grid.d.ts +3 -0
- package/dist/cli/commands/grid.d.ts.map +1 -0
- package/dist/cli/commands/grid.js +103 -0
- package/dist/cli/commands/grid.js.map +1 -0
- package/dist/cli/commands/multi-trade.d.ts +3 -0
- package/dist/cli/commands/multi-trade.d.ts.map +1 -0
- package/dist/cli/commands/multi-trade.js +175 -0
- package/dist/cli/commands/multi-trade.js.map +1 -0
- package/dist/cli/commands/trade.js +1 -1
- package/dist/cli/exchange-factory.d.ts +8 -0
- package/dist/cli/exchange-factory.d.ts.map +1 -1
- package/dist/cli/exchange-factory.js +16 -0
- package/dist/cli/exchange-factory.js.map +1 -1
- package/dist/cli/pool-discovery.d.ts +56 -0
- package/dist/cli/pool-discovery.d.ts.map +1 -0
- package/dist/cli/pool-discovery.js +283 -0
- package/dist/cli/pool-discovery.js.map +1 -0
- package/dist/config/environment.d.ts +23 -0
- package/dist/config/environment.d.ts.map +1 -1
- package/dist/config/environment.js +99 -59
- package/dist/config/environment.js.map +1 -1
- package/dist/core/price-aggregation/price-cache.d.ts +55 -0
- package/dist/core/price-aggregation/price-cache.d.ts.map +1 -0
- package/dist/core/price-aggregation/price-cache.js +152 -0
- package/dist/core/price-aggregation/price-cache.js.map +1 -0
- package/dist/examples/mexc-connector-comprehensive-test.d.ts +15 -0
- package/dist/examples/mexc-connector-comprehensive-test.d.ts.map +1 -0
- package/dist/examples/mexc-connector-comprehensive-test.js +514 -0
- package/dist/examples/mexc-connector-comprehensive-test.js.map +1 -0
- package/dist/examples/mexc-order-update-test.d.ts +4 -0
- package/dist/examples/mexc-order-update-test.d.ts.map +1 -0
- package/dist/examples/mexc-order-update-test.js +186 -0
- package/dist/examples/mexc-order-update-test.js.map +1 -0
- package/dist/examples/mexc-test.d.ts +9 -0
- package/dist/examples/mexc-test.d.ts.map +1 -0
- package/dist/examples/mexc-test.js +218 -0
- package/dist/examples/mexc-test.js.map +1 -0
- package/dist/examples/mexc-trades-debug.d.ts +2 -0
- package/dist/examples/mexc-trades-debug.d.ts.map +1 -0
- package/dist/examples/mexc-trades-debug.js +101 -0
- package/dist/examples/mexc-trades-debug.js.map +1 -0
- package/dist/examples/mexc-trades-subscription-debug.d.ts +2 -0
- package/dist/examples/mexc-trades-subscription-debug.d.ts.map +1 -0
- package/dist/examples/mexc-trades-subscription-debug.js +150 -0
- package/dist/examples/mexc-trades-subscription-debug.js.map +1 -0
- package/dist/examples/mexc-websocket-test.d.ts +8 -0
- package/dist/examples/mexc-websocket-test.d.ts.map +1 -0
- package/dist/examples/mexc-websocket-test.js +115 -0
- package/dist/examples/mexc-websocket-test.js.map +1 -0
- package/dist/examples/test-protobuf-status-detection.d.ts +9 -0
- package/dist/examples/test-protobuf-status-detection.d.ts.map +1 -0
- package/dist/examples/test-protobuf-status-detection.js +83 -0
- package/dist/examples/test-protobuf-status-detection.js.map +1 -0
- package/dist/exchanges/base-exchange-connector.d.ts +33 -0
- package/dist/exchanges/base-exchange-connector.d.ts.map +1 -0
- package/dist/exchanges/base-exchange-connector.js +55 -0
- package/dist/exchanges/base-exchange-connector.js.map +1 -0
- package/dist/exchanges/kraken/test-kraken-websocket.d.ts +19 -0
- package/dist/exchanges/kraken/test-kraken-websocket.d.ts.map +1 -0
- package/dist/exchanges/kraken/test-kraken-websocket.js +413 -0
- package/dist/exchanges/kraken/test-kraken-websocket.js.map +1 -0
- package/dist/mcp/resources/index.d.ts +3 -0
- package/dist/mcp/resources/index.d.ts.map +1 -0
- package/dist/mcp/resources/index.js +11 -0
- package/dist/mcp/resources/index.js.map +1 -0
- package/dist/mcp/server.d.ts +4 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +29 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +3 -0
- package/dist/mcp/tools/index.d.ts.map +1 -0
- package/dist/mcp/tools/index.js +12 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/tests/fixtures/test-helpers.d.ts +5 -0
- package/dist/tests/fixtures/test-helpers.d.ts.map +1 -0
- package/dist/tests/fixtures/test-helpers.js +8 -0
- package/dist/tests/fixtures/test-helpers.js.map +1 -0
- package/dist/tests/integration/exchanges/mexc/mexc-integration.test.d.ts +2 -0
- package/dist/tests/integration/exchanges/mexc/mexc-integration.test.d.ts.map +1 -0
- package/dist/tests/integration/exchanges/mexc/mexc-integration.test.js +237 -0
- package/dist/tests/integration/exchanges/mexc/mexc-integration.test.js.map +1 -0
- package/dist/tests/integration/price-aggregation/cardano-price-service.test.d.ts +2 -0
- package/dist/tests/integration/price-aggregation/cardano-price-service.test.d.ts.map +1 -0
- package/dist/tests/integration/price-aggregation/cardano-price-service.test.js +57 -0
- package/dist/tests/integration/price-aggregation/cardano-price-service.test.js.map +1 -0
- package/dist/tests/integration/price-aggregation/price-aggregation-integration.test.d.ts +2 -0
- package/dist/tests/integration/price-aggregation/price-aggregation-integration.test.d.ts.map +1 -0
- package/dist/tests/integration/price-aggregation/price-aggregation-integration.test.js +141 -0
- package/dist/tests/integration/price-aggregation/price-aggregation-integration.test.js.map +1 -0
- package/dist/tests/integration/strategies/grid/grid-strategy-e2e.test.d.ts +2 -0
- package/dist/tests/integration/strategies/grid/grid-strategy-e2e.test.d.ts.map +1 -0
- package/dist/tests/integration/strategies/grid/grid-strategy-e2e.test.js +375 -0
- package/dist/tests/integration/strategies/grid/grid-strategy-e2e.test.js.map +1 -0
- package/dist/tests/unit/cli/exchange-factory.test.d.ts +2 -0
- package/dist/tests/unit/cli/exchange-factory.test.d.ts.map +1 -0
- package/dist/tests/unit/cli/exchange-factory.test.js +148 -0
- package/dist/tests/unit/cli/exchange-factory.test.js.map +1 -0
- package/dist/tests/unit/config/environment.test.d.ts +2 -0
- package/dist/tests/unit/config/environment.test.d.ts.map +1 -0
- package/dist/tests/unit/config/environment.test.js +158 -0
- package/dist/tests/unit/config/environment.test.js.map +1 -0
- package/dist/tests/unit/config/launcher-config.test.d.ts +2 -0
- package/dist/tests/unit/config/launcher-config.test.d.ts.map +1 -0
- package/dist/tests/unit/config/launcher-config.test.js +117 -0
- package/dist/tests/unit/config/launcher-config.test.js.map +1 -0
- package/dist/tests/unit/config/price-aggregation.test.d.ts +2 -0
- package/dist/tests/unit/config/price-aggregation.test.d.ts.map +1 -0
- package/dist/tests/unit/config/price-aggregation.test.js +144 -0
- package/dist/tests/unit/config/price-aggregation.test.js.map +1 -0
- package/dist/tests/unit/core/exchange/base-exchange-connector.test.d.ts +2 -0
- package/dist/tests/unit/core/exchange/base-exchange-connector.test.d.ts.map +1 -0
- package/dist/tests/unit/core/exchange/base-exchange-connector.test.js +191 -0
- package/dist/tests/unit/core/exchange/base-exchange-connector.test.js.map +1 -0
- package/dist/tests/unit/core/exchange/base-exchange-data-mapper.test.d.ts +2 -0
- package/dist/tests/unit/core/exchange/base-exchange-data-mapper.test.d.ts.map +1 -0
- package/dist/tests/unit/core/exchange/base-exchange-data-mapper.test.js +324 -0
- package/dist/tests/unit/core/exchange/base-exchange-data-mapper.test.js.map +1 -0
- package/dist/tests/unit/core/price-aggregation/cardano-price-service.test.d.ts +2 -0
- package/dist/tests/unit/core/price-aggregation/cardano-price-service.test.d.ts.map +1 -0
- package/dist/tests/unit/core/price-aggregation/cardano-price-service.test.js +177 -0
- package/dist/tests/unit/core/price-aggregation/cardano-price-service.test.js.map +1 -0
- package/dist/tests/unit/core/price-aggregation/iris-api-client.test.d.ts +2 -0
- package/dist/tests/unit/core/price-aggregation/iris-api-client.test.d.ts.map +1 -0
- package/dist/tests/unit/core/price-aggregation/iris-api-client.test.js +168 -0
- package/dist/tests/unit/core/price-aggregation/iris-api-client.test.js.map +1 -0
- package/dist/tests/unit/core/price-aggregation/iris-pool-discovery.test.d.ts +2 -0
- package/dist/tests/unit/core/price-aggregation/iris-pool-discovery.test.d.ts.map +1 -0
- package/dist/tests/unit/core/price-aggregation/iris-pool-discovery.test.js +217 -0
- package/dist/tests/unit/core/price-aggregation/iris-pool-discovery.test.js.map +1 -0
- package/dist/tests/unit/core/price-aggregation/price-calculator.test.d.ts +2 -0
- package/dist/tests/unit/core/price-aggregation/price-calculator.test.d.ts.map +1 -0
- package/dist/tests/unit/core/price-aggregation/price-calculator.test.js +229 -0
- package/dist/tests/unit/core/price-aggregation/price-calculator.test.js.map +1 -0
- package/dist/tests/unit/core/risk-management/risk-manager.test.d.ts +2 -0
- package/dist/tests/unit/core/risk-management/risk-manager.test.d.ts.map +1 -0
- package/dist/tests/unit/core/risk-management/risk-manager.test.js +194 -0
- package/dist/tests/unit/core/risk-management/risk-manager.test.js.map +1 -0
- package/dist/tests/unit/core/strategy/base-strategy.test.d.ts +2 -0
- package/dist/tests/unit/core/strategy/base-strategy.test.d.ts.map +1 -0
- package/dist/tests/unit/core/strategy/base-strategy.test.js +254 -0
- package/dist/tests/unit/core/strategy/base-strategy.test.js.map +1 -0
- package/dist/tests/unit/core/strategy/strategy-factory.test.d.ts +2 -0
- package/dist/tests/unit/core/strategy/strategy-factory.test.d.ts.map +1 -0
- package/dist/tests/unit/core/strategy/strategy-factory.test.js +213 -0
- package/dist/tests/unit/core/strategy/strategy-factory.test.js.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-auth.test.d.ts +2 -0
- package/dist/tests/unit/exchanges/mexc/mexc-auth.test.d.ts.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-auth.test.js +452 -0
- package/dist/tests/unit/exchanges/mexc/mexc-auth.test.js.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-connector.test.d.ts +2 -0
- package/dist/tests/unit/exchanges/mexc/mexc-connector.test.d.ts.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-connector.test.js +1419 -0
- package/dist/tests/unit/exchanges/mexc/mexc-connector.test.js.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-data-mapper.test.d.ts +2 -0
- package/dist/tests/unit/exchanges/mexc/mexc-data-mapper.test.d.ts.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-data-mapper.test.js +435 -0
- package/dist/tests/unit/exchanges/mexc/mexc-data-mapper.test.js.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-protobuf-decoder.test.d.ts +2 -0
- package/dist/tests/unit/exchanges/mexc/mexc-protobuf-decoder.test.d.ts.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-protobuf-decoder.test.js +314 -0
- package/dist/tests/unit/exchanges/mexc/mexc-protobuf-decoder.test.js.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-protobuf-status-detection.test.d.ts +2 -0
- package/dist/tests/unit/exchanges/mexc/mexc-protobuf-status-detection.test.d.ts.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-protobuf-status-detection.test.js +178 -0
- package/dist/tests/unit/exchanges/mexc/mexc-protobuf-status-detection.test.js.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-user-stream.test.d.ts +2 -0
- package/dist/tests/unit/exchanges/mexc/mexc-user-stream.test.d.ts.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-user-stream.test.js +502 -0
- package/dist/tests/unit/exchanges/mexc/mexc-user-stream.test.js.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-utils.test.d.ts +2 -0
- package/dist/tests/unit/exchanges/mexc/mexc-utils.test.d.ts.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-utils.test.js +317 -0
- package/dist/tests/unit/exchanges/mexc/mexc-utils.test.js.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-websocket.test.d.ts +2 -0
- package/dist/tests/unit/exchanges/mexc/mexc-websocket.test.d.ts.map +1 -0
- package/dist/tests/unit/exchanges/mexc/mexc-websocket.test.js +843 -0
- package/dist/tests/unit/exchanges/mexc/mexc-websocket.test.js.map +1 -0
- package/dist/tests/unit/strategies/grid/grid-calculator.test.d.ts +2 -0
- package/dist/tests/unit/strategies/grid/grid-calculator.test.d.ts.map +1 -0
- package/dist/tests/unit/strategies/grid/grid-calculator.test.js +67 -0
- package/dist/tests/unit/strategies/grid/grid-calculator.test.js.map +1 -0
- package/dist/tests/unit/strategies/grid/grid-order-manager.test.d.ts +2 -0
- package/dist/tests/unit/strategies/grid/grid-order-manager.test.d.ts.map +1 -0
- package/dist/tests/unit/strategies/grid/grid-order-manager.test.js +211 -0
- package/dist/tests/unit/strategies/grid/grid-order-manager.test.js.map +1 -0
- package/dist/tests/unit/strategies/grid/grid-strategy-simple.test.d.ts +2 -0
- package/dist/tests/unit/strategies/grid/grid-strategy-simple.test.d.ts.map +1 -0
- package/dist/tests/unit/strategies/grid/grid-strategy-simple.test.js +197 -0
- package/dist/tests/unit/strategies/grid/grid-strategy-simple.test.js.map +1 -0
- package/dist/tests/unit/strategies/grid/grid-strategy.test.d.ts +2 -0
- package/dist/tests/unit/strategies/grid/grid-strategy.test.d.ts.map +1 -0
- package/dist/tests/unit/strategies/grid/grid-strategy.test.js +429 -0
- package/dist/tests/unit/strategies/grid/grid-strategy.test.js.map +1 -0
- package/dist/tests/unit/utils/logger.test.d.ts +2 -0
- package/dist/tests/unit/utils/logger.test.d.ts.map +1 -0
- package/dist/tests/unit/utils/logger.test.js +260 -0
- package/dist/tests/unit/utils/logger.test.js.map +1 -0
- package/dist/tests/unit/utils/symbol-utils.test.d.ts +2 -0
- package/dist/tests/unit/utils/symbol-utils.test.d.ts.map +1 -0
- package/dist/tests/unit/utils/symbol-utils.test.js +178 -0
- package/dist/tests/unit/utils/symbol-utils.test.js.map +1 -0
- package/dist/types/price-aggregation.d.ts +31 -0
- package/dist/types/price-aggregation.d.ts.map +1 -0
- package/dist/types/price-aggregation.js +6 -0
- package/dist/types/price-aggregation.js.map +1 -0
- package/dist/utils/crypto.d.ts +15 -0
- package/dist/utils/crypto.d.ts.map +1 -0
- package/dist/utils/crypto.js +50 -0
- package/dist/utils/crypto.js.map +1 -0
- package/dist/utils/validation.d.ts +36 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +174 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEhD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAA4B;IAEhE,MAAM,CAAC,cAAc,CACnB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,uBAA4B,GACpC,gBAAgB;IAoCnB,MAAM,CAAC,aAAa,CAClB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,sBAA2B,GACnC,gBAAgB;IAmCnB,MAAM,CAAC,cAAc,CACnB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,sBAA2B,GACnC,gBAAgB;IAmCnB,MAAM,CAAC,aAAa,CAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,GAAE,sBAA2B,GACnC,gBAAgB;IAkDnB,MAAM,CAAC,sBAAsB,CAC3B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,MAAM,GAClB,gBAAgB;IA6BnB,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,SAAS;IAIxD,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,SAAS;IAIxD,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAWhD;AAED,OAAO,EAAE,eAAe,IAAI,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.ValidationUtils = void 0;
|
|
4
|
+
class ValidationUtils {
|
|
5
|
+
static validateSymbol(symbol, options = {}) {
|
|
6
|
+
const errors = [];
|
|
7
|
+
const warnings = [];
|
|
8
|
+
if (!symbol || typeof symbol !== 'string') {
|
|
9
|
+
errors.push('Symbol must be a non-empty string');
|
|
10
|
+
return { isValid: false, errors, warnings };
|
|
11
|
+
}
|
|
12
|
+
const trimmedSymbol = symbol.trim().toUpperCase();
|
|
13
|
+
if (options.minLength && trimmedSymbol.length < options.minLength) {
|
|
14
|
+
errors.push(`Symbol must be at least ${options.minLength} characters long`);
|
|
15
|
+
}
|
|
16
|
+
if (options.maxLength && trimmedSymbol.length > options.maxLength) {
|
|
17
|
+
errors.push(`Symbol must not exceed ${options.maxLength} characters`);
|
|
18
|
+
}
|
|
19
|
+
if (!this.SYMBOL_REGEX.test(trimmedSymbol)) {
|
|
20
|
+
errors.push('Symbol must be in format BASE/QUOTE (e.g., BTC/USDT)');
|
|
21
|
+
}
|
|
22
|
+
if (options.supportedAssets) {
|
|
23
|
+
const [baseAsset, quoteAsset] = trimmedSymbol.split('/');
|
|
24
|
+
if (!options.supportedAssets.includes(baseAsset)) {
|
|
25
|
+
errors.push(`Base asset ${baseAsset} is not supported`);
|
|
26
|
+
}
|
|
27
|
+
if (!options.supportedAssets.includes(quoteAsset)) {
|
|
28
|
+
errors.push(`Quote asset ${quoteAsset} is not supported`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { isValid: errors.length === 0, errors, warnings };
|
|
32
|
+
}
|
|
33
|
+
static validatePrice(price, options = {}) {
|
|
34
|
+
const errors = [];
|
|
35
|
+
const warnings = [];
|
|
36
|
+
if (typeof price !== 'number' || isNaN(price)) {
|
|
37
|
+
errors.push('Price must be a valid number');
|
|
38
|
+
return { isValid: false, errors, warnings };
|
|
39
|
+
}
|
|
40
|
+
if (price <= 0) {
|
|
41
|
+
errors.push('Price must be greater than zero');
|
|
42
|
+
}
|
|
43
|
+
if (options.minPrice && price < options.minPrice) {
|
|
44
|
+
errors.push(`Price must be at least ${options.minPrice}`);
|
|
45
|
+
}
|
|
46
|
+
if (options.maxPrice && price > options.maxPrice) {
|
|
47
|
+
errors.push(`Price must not exceed ${options.maxPrice}`);
|
|
48
|
+
}
|
|
49
|
+
if (options.tickSize && price % options.tickSize !== 0) {
|
|
50
|
+
errors.push(`Price must be a multiple of tick size ${options.tickSize}`);
|
|
51
|
+
}
|
|
52
|
+
if (options.maxPrecision) {
|
|
53
|
+
const decimalPlaces = this.getDecimalPlaces(price);
|
|
54
|
+
if (decimalPlaces > options.maxPrecision) {
|
|
55
|
+
errors.push(`Price cannot have more than ${options.maxPrecision} decimal places`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return { isValid: errors.length === 0, errors, warnings };
|
|
59
|
+
}
|
|
60
|
+
static validateAmount(amount, options = {}) {
|
|
61
|
+
const errors = [];
|
|
62
|
+
const warnings = [];
|
|
63
|
+
if (typeof amount !== 'number' || isNaN(amount)) {
|
|
64
|
+
errors.push('Amount must be a valid number');
|
|
65
|
+
return { isValid: false, errors, warnings };
|
|
66
|
+
}
|
|
67
|
+
if (amount <= 0) {
|
|
68
|
+
errors.push('Amount must be greater than zero');
|
|
69
|
+
}
|
|
70
|
+
if (options.minAmount && amount < options.minAmount) {
|
|
71
|
+
errors.push(`Amount must be at least ${options.minAmount}`);
|
|
72
|
+
}
|
|
73
|
+
if (options.maxAmount && amount > options.maxAmount) {
|
|
74
|
+
errors.push(`Amount must not exceed ${options.maxAmount}`);
|
|
75
|
+
}
|
|
76
|
+
if (options.stepSize && amount % options.stepSize !== 0) {
|
|
77
|
+
errors.push(`Amount must be a multiple of step size ${options.stepSize}`);
|
|
78
|
+
}
|
|
79
|
+
if (options.maxPrecision) {
|
|
80
|
+
const decimalPlaces = this.getDecimalPlaces(amount);
|
|
81
|
+
if (decimalPlaces > options.maxPrecision) {
|
|
82
|
+
errors.push(`Amount cannot have more than ${options.maxPrecision} decimal places`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return { isValid: errors.length === 0, errors, warnings };
|
|
86
|
+
}
|
|
87
|
+
static validateOrder(symbol, type, side, amount, price, options = {}) {
|
|
88
|
+
const errors = [];
|
|
89
|
+
const warnings = [];
|
|
90
|
+
const symbolValidation = this.validateSymbol(symbol);
|
|
91
|
+
if (!symbolValidation.isValid) {
|
|
92
|
+
errors.push(...symbolValidation.errors);
|
|
93
|
+
}
|
|
94
|
+
if (!this.isValidOrderType(type)) {
|
|
95
|
+
errors.push(`Invalid order type: ${type}`);
|
|
96
|
+
}
|
|
97
|
+
if (!this.isValidOrderSide(side)) {
|
|
98
|
+
errors.push(`Invalid order side: ${side}`);
|
|
99
|
+
}
|
|
100
|
+
const amountValidation = this.validateAmount(amount, options);
|
|
101
|
+
if (!amountValidation.isValid) {
|
|
102
|
+
errors.push(...amountValidation.errors);
|
|
103
|
+
}
|
|
104
|
+
if (type === 'limit') {
|
|
105
|
+
if (price === undefined) {
|
|
106
|
+
errors.push(`Price is required for ${type} orders`);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const priceValidation = this.validatePrice(price, options);
|
|
110
|
+
if (!priceValidation.isValid) {
|
|
111
|
+
errors.push(...priceValidation.errors);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (price && options.minNotional) {
|
|
116
|
+
const notional = price * amount;
|
|
117
|
+
if (notional < options.minNotional) {
|
|
118
|
+
errors.push(`Order notional value ${notional} is below minimum ${options.minNotional}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (price && options.maxNotional) {
|
|
122
|
+
const notional = price * amount;
|
|
123
|
+
if (notional > options.maxNotional) {
|
|
124
|
+
errors.push(`Order notional value ${notional} exceeds maximum ${options.maxNotional}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return { isValid: errors.length === 0, errors, warnings };
|
|
128
|
+
}
|
|
129
|
+
static validateApiCredentials(apiKey, apiSecret, passphrase) {
|
|
130
|
+
const errors = [];
|
|
131
|
+
const warnings = [];
|
|
132
|
+
if (!apiKey || typeof apiKey !== 'string' || apiKey.trim().length === 0) {
|
|
133
|
+
errors.push('API key is required and must be a non-empty string');
|
|
134
|
+
}
|
|
135
|
+
if (!apiSecret || typeof apiSecret !== 'string' || apiSecret.trim().length === 0) {
|
|
136
|
+
errors.push('API secret is required and must be a non-empty string');
|
|
137
|
+
}
|
|
138
|
+
if (apiKey && apiKey.length < 16) {
|
|
139
|
+
warnings.push('API key seems unusually short');
|
|
140
|
+
}
|
|
141
|
+
if (apiSecret && apiSecret.length < 32) {
|
|
142
|
+
warnings.push('API secret seems unusually short');
|
|
143
|
+
}
|
|
144
|
+
if (passphrase !== undefined) {
|
|
145
|
+
if (typeof passphrase !== 'string' || passphrase.trim().length === 0) {
|
|
146
|
+
errors.push('Passphrase must be a non-empty string when provided');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return { isValid: errors.length === 0, errors, warnings };
|
|
150
|
+
}
|
|
151
|
+
static isValidOrderType(type) {
|
|
152
|
+
return ['market', 'limit'].includes(type);
|
|
153
|
+
}
|
|
154
|
+
static isValidOrderSide(side) {
|
|
155
|
+
return ['buy', 'sell'].includes(side);
|
|
156
|
+
}
|
|
157
|
+
static getDecimalPlaces(number) {
|
|
158
|
+
if (Math.floor(number) === number)
|
|
159
|
+
return 0;
|
|
160
|
+
const str = number.toString();
|
|
161
|
+
if (str.indexOf('.') !== -1 && str.indexOf('e-') === -1) {
|
|
162
|
+
return str.split('.')[1].length;
|
|
163
|
+
}
|
|
164
|
+
else if (str.indexOf('e-') !== -1) {
|
|
165
|
+
const parts = str.split('e-');
|
|
166
|
+
return parseInt(parts[1], 10);
|
|
167
|
+
}
|
|
168
|
+
return 0;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.ValidationUtils = ValidationUtils;
|
|
172
|
+
exports.default = ValidationUtils;
|
|
173
|
+
ValidationUtils.SYMBOL_REGEX = /^[A-Z0-9]+\/[A-Z0-9]+$/;
|
|
174
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":";;;AA2BA,MAAa,eAAe;IAG1B,MAAM,CAAC,cAAc,CACnB,MAAc,EACd,UAAmC,EAAE;QAErC,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAa,EAAE,CAAC;QAE9B,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC1C,MAAM,CAAC,I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