@typedtrader/exchange 0.2.3 → 0.2.5
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/index.cjs +10 -11
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/package.json +4 -5
package/dist/index.cjs
CHANGED
|
@@ -28,10 +28,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
let zod = require("zod");
|
|
29
29
|
let node_events = require("node:events");
|
|
30
30
|
let ms = require("ms");
|
|
31
|
-
ms = __toESM(ms);
|
|
32
31
|
let jsonabc = require("jsonabc");
|
|
33
32
|
jsonabc = __toESM(jsonabc);
|
|
34
|
-
let
|
|
33
|
+
let _master_chief_alpaca_ts = require("@master-chief/alpaca-ts");
|
|
35
34
|
let ts_retry_promise = require("ts-retry-promise");
|
|
36
35
|
|
|
37
36
|
//#region src/candle/BatchedCandle.ts
|
|
@@ -461,8 +460,8 @@ var CandleBatcher = class CandleBatcher extends node_events.EventEmitter {
|
|
|
461
460
|
return this.batch.length;
|
|
462
461
|
}
|
|
463
462
|
static amountOfCandles(intervalInMillis, timespanInMillis) {
|
|
464
|
-
const interval = typeof intervalInMillis === "number" ? intervalInMillis : (0, ms.
|
|
465
|
-
return (typeof timespanInMillis === "number" ? timespanInMillis : (0, ms.
|
|
463
|
+
const interval = typeof intervalInMillis === "number" ? intervalInMillis : (0, ms.ms)(intervalInMillis);
|
|
464
|
+
return (typeof timespanInMillis === "number" ? timespanInMillis : (0, ms.ms)(timespanInMillis)) / interval;
|
|
466
465
|
}
|
|
467
466
|
static isBatchedCandle(candle) {
|
|
468
467
|
return typeof candle.open !== "string";
|
|
@@ -759,9 +758,9 @@ var Exchange = class {
|
|
|
759
758
|
//#region src/exchange-alpaca/AlpacaExchangeMapper.ts
|
|
760
759
|
var AlpacaExchangeMapper = class {
|
|
761
760
|
static mapInterval(intervalInMillis) {
|
|
762
|
-
if (intervalInMillis < (0, ms.
|
|
763
|
-
if (intervalInMillis > (0, ms.
|
|
764
|
-
return (0, ms.
|
|
761
|
+
if (intervalInMillis < (0, ms.ms)("1m")) throw new Error(`Timeframes below 1 minute are not supported.`);
|
|
762
|
+
if (intervalInMillis > (0, ms.ms)("1d")) throw new Error(`Timeframes above 1 day are not supported.`);
|
|
763
|
+
return (0, ms.ms)(intervalInMillis).replace("m", "Min").replace("h", "Hour").replace("d", "Day");
|
|
765
764
|
}
|
|
766
765
|
static toExchangeCandle(candle, pair, sizeInMillis) {
|
|
767
766
|
const date = new Date(candle.t);
|
|
@@ -796,7 +795,7 @@ var AlpacaExchangeMapper = class {
|
|
|
796
795
|
};
|
|
797
796
|
}
|
|
798
797
|
static toFilledOrder(order, pair) {
|
|
799
|
-
if (order.status !==
|
|
798
|
+
if (order.status !== _master_chief_alpaca_ts.OrderStatus.FILLED) throw new Error(`Order ID "${order.id}" is not filled.`);
|
|
800
799
|
return {
|
|
801
800
|
created_at: `${order.created_at}`,
|
|
802
801
|
fee: "0",
|
|
@@ -849,7 +848,7 @@ var AlpacaExchange = class AlpacaExchange extends Exchange {
|
|
|
849
848
|
};
|
|
850
849
|
constructor(options) {
|
|
851
850
|
super(AlpacaExchange.NAME);
|
|
852
|
-
this.client = new
|
|
851
|
+
this.client = new _master_chief_alpaca_ts.Client({
|
|
853
852
|
credentials: {
|
|
854
853
|
key: options.apiKey,
|
|
855
854
|
secret: options.apiSecret
|
|
@@ -870,7 +869,7 @@ var AlpacaExchange = class AlpacaExchange extends Exchange {
|
|
|
870
869
|
const response = await this.fetchLatestCryptoBars(pair);
|
|
871
870
|
return Object.keys(response.bars).length > 0;
|
|
872
871
|
} catch (error) {
|
|
873
|
-
if (error instanceof
|
|
872
|
+
if (error instanceof _master_chief_alpaca_ts.ApiError && error.status === 400) return false;
|
|
874
873
|
throw error;
|
|
875
874
|
}
|
|
876
875
|
}
|
|
@@ -962,6 +961,6 @@ exports.hasErrorStatus = hasErrorStatus;
|
|
|
962
961
|
Object.defineProperty(exports, 'ms', {
|
|
963
962
|
enumerable: true,
|
|
964
963
|
get: function () {
|
|
965
|
-
return ms.
|
|
964
|
+
return ms.parse;
|
|
966
965
|
}
|
|
967
966
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { Big as Big$1 } from "big.js";
|
|
3
3
|
import { EventEmitter } from "node:events";
|
|
4
|
+
import { StringValue, parse as ms } from "ms";
|
|
4
5
|
import { Bar, Client, Order } from "@master-chief/alpaca-ts";
|
|
5
|
-
import ms from "ms";
|
|
6
6
|
|
|
7
7
|
//#region src/core/CurrencyPair.d.ts
|
|
8
8
|
type CurrencyPairJSON = {
|
|
@@ -145,7 +145,7 @@ declare class CandleBatcher extends EventEmitter<EventMap> {
|
|
|
145
145
|
private readonly desiredIntervalInMillis;
|
|
146
146
|
constructor(desiredIntervalInMillis: number);
|
|
147
147
|
get present(): number;
|
|
148
|
-
static amountOfCandles(intervalInMillis: number |
|
|
148
|
+
static amountOfCandles(intervalInMillis: number | StringValue, timespanInMillis: number | StringValue): number;
|
|
149
149
|
static isBatchedCandle(candle: ExchangeCandle | BatchedCandle): candle is BatchedCandle;
|
|
150
150
|
static createBatchedCandle(batch: ExchangeCandle[], desiredIntervalInMillis: number): BatchedCandle;
|
|
151
151
|
addToBatch(candle: ExchangeCandle | BatchedCandle): BatchedCandle | undefined;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { EventEmitter } from "node:events";
|
|
3
|
-
import ms from "ms";
|
|
3
|
+
import { StringValue, parse as ms } from "ms";
|
|
4
4
|
import { Bar, Client, Order } from "@master-chief/alpaca-ts";
|
|
5
5
|
import { Big as Big$1 } from "big.js";
|
|
6
6
|
|
|
@@ -145,7 +145,7 @@ declare class CandleBatcher extends EventEmitter<EventMap> {
|
|
|
145
145
|
private readonly desiredIntervalInMillis;
|
|
146
146
|
constructor(desiredIntervalInMillis: number);
|
|
147
147
|
get present(): number;
|
|
148
|
-
static amountOfCandles(intervalInMillis: number |
|
|
148
|
+
static amountOfCandles(intervalInMillis: number | StringValue, timespanInMillis: number | StringValue): number;
|
|
149
149
|
static isBatchedCandle(candle: ExchangeCandle | BatchedCandle): candle is BatchedCandle;
|
|
150
150
|
static createBatchedCandle(batch: ExchangeCandle[], desiredIntervalInMillis: number): BatchedCandle;
|
|
151
151
|
addToBatch(candle: ExchangeCandle | BatchedCandle): BatchedCandle | undefined;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { EventEmitter } from "node:events";
|
|
3
|
-
import
|
|
3
|
+
import { ms as ms$1, parse as ms } from "ms";
|
|
4
4
|
import jsonabc from "jsonabc";
|
|
5
5
|
import { ApiError, Client, OrderStatus } from "@master-chief/alpaca-ts";
|
|
6
6
|
import { retry } from "ts-retry-promise";
|
package/package.json
CHANGED
|
@@ -5,13 +5,12 @@
|
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@master-chief/alpaca-ts": "^7.0.15-alpha",
|
|
7
7
|
"@types/jsonabc": "^2.3.3",
|
|
8
|
-
"@types/ms": "^0.7.34",
|
|
9
8
|
"alpaca-legacy": "npm:@master-chief/alpaca@^6.3.20",
|
|
10
9
|
"dotenv-defaults": "^5.0.2",
|
|
11
10
|
"jsonabc": "^2.3.1",
|
|
12
|
-
"ms": "
|
|
11
|
+
"ms": "4.0.0-nightly.202508271359",
|
|
13
12
|
"ts-retry-promise": "^0.8.1",
|
|
14
|
-
"zod": "^4.3.
|
|
13
|
+
"zod": "^4.3.5"
|
|
15
14
|
},
|
|
16
15
|
"description": "Trading strategies to run trading bots with JavaScript / TypeScript.",
|
|
17
16
|
"exports": {
|
|
@@ -58,6 +57,6 @@
|
|
|
58
57
|
"test:units:watch": "vitest --watch"
|
|
59
58
|
},
|
|
60
59
|
"type": "module",
|
|
61
|
-
"version": "0.2.
|
|
62
|
-
"gitHead": "
|
|
60
|
+
"version": "0.2.5",
|
|
61
|
+
"gitHead": "6713fac78e087f98e2a0349c95c01b0792430915"
|
|
63
62
|
}
|