@typedtrader/exchange 0.3.3 → 0.5.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 +2 -0
- package/dist/broker/Broker.d.ts +3 -29
- package/dist/broker/Broker.js +8 -22
- package/dist/broker/Broker.js.map +1 -1
- package/dist/broker/BrokerMock.d.ts +12 -8
- package/dist/broker/BrokerMock.js +75 -189
- package/dist/broker/BrokerMock.js.map +1 -1
- package/dist/broker/MarketDataSource.d.ts +1 -0
- package/dist/broker/MarketDataSource.js +24 -16
- package/dist/broker/MarketDataSource.js.map +1 -1
- package/dist/broker/MockBalances.d.ts +14 -0
- package/dist/broker/MockBalances.js +62 -0
- package/dist/broker/MockBalances.js.map +1 -0
- package/dist/broker/alpaca/AlpacaBroker.d.ts +3 -2
- package/dist/broker/alpaca/AlpacaBroker.js +25 -70
- package/dist/broker/alpaca/AlpacaBroker.js.map +1 -1
- package/dist/broker/alpaca/AlpacaBrokerMapper.d.ts +5 -1
- package/dist/broker/alpaca/AlpacaBrokerMapper.js +32 -0
- package/dist/broker/alpaca/AlpacaBrokerMapper.js.map +1 -1
- package/dist/broker/alpaca/AlpacaBrokerMock.d.ts +4 -1
- package/dist/broker/alpaca/AlpacaBrokerMock.js +2 -2
- package/dist/broker/alpaca/AlpacaBrokerMock.js.map +1 -1
- package/dist/broker/alpaca/AlpacaMarketData.d.ts +2 -1
- package/dist/broker/alpaca/AlpacaMarketData.js +25 -8
- package/dist/broker/alpaca/AlpacaMarketData.js.map +1 -1
- package/dist/broker/alpaca/api/AlpacaAPI.d.ts +12 -11
- package/dist/broker/alpaca/api/AlpacaAPI.js +2 -1
- package/dist/broker/alpaca/api/AlpacaAPI.js.map +1 -1
- package/dist/broker/alpaca/api/AlpacaStream.d.ts +0 -1
- package/dist/broker/alpaca/api/AlpacaStream.js +1 -2
- package/dist/broker/alpaca/api/AlpacaStream.js.map +1 -1
- package/dist/broker/alpaca/api/schema/AccountSchema.d.ts +0 -2
- package/dist/broker/alpaca/api/schema/AccountSchema.js +0 -2
- package/dist/broker/alpaca/api/schema/AccountSchema.js.map +1 -1
- package/dist/broker/alpaca/api/schema/AssetSchema.d.ts +1 -0
- package/dist/broker/alpaca/api/schema/AssetSchema.js +1 -0
- package/dist/broker/alpaca/api/schema/AssetSchema.js.map +1 -1
- package/dist/broker/alpaca/getAlpacaClient.d.ts +1 -1
- package/dist/broker/alpaca/getAlpacaRules.js +1 -1
- package/dist/broker/alpaca/getAlpacaRules.js.map +1 -1
- package/dist/broker/brokerMockPricing.d.ts +16 -0
- package/dist/broker/brokerMockPricing.js +49 -0
- package/dist/broker/brokerMockPricing.js.map +1 -0
- package/dist/broker/getBrokerClient.d.ts +1 -1
- package/dist/broker/trading212/Trading212Broker.js +17 -41
- package/dist/broker/trading212/Trading212Broker.js.map +1 -1
- package/dist/broker/trading212/Trading212BrokerMapper.d.ts +5 -1
- package/dist/broker/trading212/Trading212BrokerMapper.js +20 -0
- package/dist/broker/trading212/Trading212BrokerMapper.js.map +1 -1
- package/dist/broker/trading212/api/Trading212API.d.ts +13 -2
- package/dist/broker/trading212/api/Trading212API.js +168 -121
- package/dist/broker/trading212/api/Trading212API.js.map +1 -1
- package/dist/broker/trading212/api/schema/ExchangeSchema.d.ts +9 -0
- package/dist/broker/trading212/api/schema/ExchangeSchema.js +11 -0
- package/dist/broker/trading212/api/schema/ExchangeSchema.js.map +1 -0
- package/dist/broker/trading212/api/schema/InstrumentSchema.d.ts +1 -0
- package/dist/broker/trading212/api/schema/InstrumentSchema.js +1 -0
- package/dist/broker/trading212/api/schema/InstrumentSchema.js.map +1 -1
- package/dist/broker/trading212/api/schema/OrderSchema.d.ts +0 -1
- package/dist/broker/trading212/api/schema/OrderSchema.js +0 -1
- package/dist/broker/trading212/api/schema/OrderSchema.js.map +1 -1
- package/dist/broker/trading212/newFilledOrders.d.ts +54 -0
- package/dist/broker/trading212/newFilledOrders.js +20 -0
- package/dist/broker/trading212/newFilledOrders.js.map +1 -0
- package/dist/candle/CandleBatcher.js +26 -15
- package/dist/candle/CandleBatcher.js.map +1 -1
- package/dist/schemas.d.ts +26 -0
- package/dist/schemas.js +22 -0
- package/dist/schemas.js.map +1 -0
- package/dist/util/SimplifiedHttpError.d.ts +2 -2
- package/dist/util/SimplifiedHttpError.js.map +1 -1
- package/dist/util/retry.d.ts +8 -0
- package/dist/util/retry.js +26 -0
- package/dist/util/retry.js.map +1 -0
- package/package.json +26 -13
|
@@ -1,9 +1,44 @@
|
|
|
1
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
2
|
+
var useValue = arguments.length > 2;
|
|
3
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
4
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5
|
+
}
|
|
6
|
+
return useValue ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
+
var _, done = false;
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
var context = {};
|
|
16
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
+
if (kind === "accessor") {
|
|
21
|
+
if (result === void 0) continue;
|
|
22
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
+
}
|
|
27
|
+
else if (_ = accept(result)) {
|
|
28
|
+
if (kind === "field") initializers.unshift(_);
|
|
29
|
+
else descriptor[key] = _;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
+
done = true;
|
|
34
|
+
};
|
|
1
35
|
import axios from 'axios';
|
|
2
|
-
import axiosRetry from 'axios-retry';
|
|
3
36
|
import { z } from 'zod';
|
|
37
|
+
import { retry } from '../../../util/retry.js';
|
|
4
38
|
import { simplifyError } from '../../../util/simplifyError.js';
|
|
5
39
|
import { AccountCashSchema, AccountInfoSchema } from './schema/AccountSchema.js';
|
|
6
40
|
import { HistoryOrderPageSchema } from './schema/HistoryOrderSchema.js';
|
|
41
|
+
import { ExchangeSchema } from './schema/ExchangeSchema.js';
|
|
7
42
|
import { InstrumentSchema } from './schema/InstrumentSchema.js';
|
|
8
43
|
import { OrderSchema, PlaceLimitOrderRequestSchema, PlaceMarketOrderRequestSchema, } from './schema/OrderSchema.js';
|
|
9
44
|
import { PositionSchema } from './schema/PositionSchema.js';
|
|
@@ -11,133 +46,145 @@ const URL = {
|
|
|
11
46
|
ACCOUNT_CASH: '/api/v0/equity/account/cash',
|
|
12
47
|
ACCOUNT_INFO: '/api/v0/equity/account/info',
|
|
13
48
|
HISTORY_ORDERS: '/api/v0/equity/history/orders',
|
|
49
|
+
METADATA_EXCHANGES: '/api/v0/equity/metadata/exchanges',
|
|
14
50
|
METADATA_INSTRUMENTS: '/api/v0/equity/metadata/instruments',
|
|
15
51
|
ORDERS: '/api/v0/equity/orders',
|
|
16
52
|
ORDERS_LIMIT: '/api/v0/equity/orders/limit',
|
|
17
53
|
ORDERS_MARKET: '/api/v0/equity/orders/market',
|
|
18
54
|
PORTFOLIO: '/api/v0/equity/portfolio',
|
|
19
55
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
56
|
+
let Trading212API = (() => {
|
|
57
|
+
let _instanceExtraInitializers = [];
|
|
58
|
+
let _getAccountCash_decorators;
|
|
59
|
+
let _getAccountInfo_decorators;
|
|
60
|
+
let _getPositions_decorators;
|
|
61
|
+
let _getPositionByTicker_decorators;
|
|
62
|
+
let _getOrders_decorators;
|
|
63
|
+
let _getOrderById_decorators;
|
|
64
|
+
let _cancelOrder_decorators;
|
|
65
|
+
let _placeMarketOrder_decorators;
|
|
66
|
+
let _placeLimitOrder_decorators;
|
|
67
|
+
let _getExchanges_decorators;
|
|
68
|
+
let _getInstruments_decorators;
|
|
69
|
+
let _getHistoryOrdersPage_decorators;
|
|
70
|
+
return class Trading212API {
|
|
71
|
+
static {
|
|
72
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
73
|
+
_getAccountCash_decorators = [retry({ delayMs: 2_000 })];
|
|
74
|
+
_getAccountInfo_decorators = [retry({ delayMs: 30_000 })];
|
|
75
|
+
_getPositions_decorators = [retry({ delayMs: 5_000 })];
|
|
76
|
+
_getPositionByTicker_decorators = [retry()];
|
|
77
|
+
_getOrders_decorators = [retry({ delayMs: 5_000 })];
|
|
78
|
+
_getOrderById_decorators = [retry({ delayMs: 1_000 })];
|
|
79
|
+
_cancelOrder_decorators = [retry()];
|
|
80
|
+
_placeMarketOrder_decorators = [retry()];
|
|
81
|
+
_placeLimitOrder_decorators = [retry()];
|
|
82
|
+
_getExchanges_decorators = [retry({ delayMs: 30_000 })];
|
|
83
|
+
_getInstruments_decorators = [retry({ delayMs: 50_000 })];
|
|
84
|
+
_getHistoryOrdersPage_decorators = [retry({ delayMs: 60_000 })];
|
|
85
|
+
__esDecorate(this, null, _getAccountCash_decorators, { kind: "method", name: "getAccountCash", static: false, private: false, access: { has: obj => "getAccountCash" in obj, get: obj => obj.getAccountCash }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
86
|
+
__esDecorate(this, null, _getAccountInfo_decorators, { kind: "method", name: "getAccountInfo", static: false, private: false, access: { has: obj => "getAccountInfo" in obj, get: obj => obj.getAccountInfo }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
87
|
+
__esDecorate(this, null, _getPositions_decorators, { kind: "method", name: "getPositions", static: false, private: false, access: { has: obj => "getPositions" in obj, get: obj => obj.getPositions }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
88
|
+
__esDecorate(this, null, _getPositionByTicker_decorators, { kind: "method", name: "getPositionByTicker", static: false, private: false, access: { has: obj => "getPositionByTicker" in obj, get: obj => obj.getPositionByTicker }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
89
|
+
__esDecorate(this, null, _getOrders_decorators, { kind: "method", name: "getOrders", static: false, private: false, access: { has: obj => "getOrders" in obj, get: obj => obj.getOrders }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
90
|
+
__esDecorate(this, null, _getOrderById_decorators, { kind: "method", name: "getOrderById", static: false, private: false, access: { has: obj => "getOrderById" in obj, get: obj => obj.getOrderById }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
91
|
+
__esDecorate(this, null, _cancelOrder_decorators, { kind: "method", name: "cancelOrder", static: false, private: false, access: { has: obj => "cancelOrder" in obj, get: obj => obj.cancelOrder }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
92
|
+
__esDecorate(this, null, _placeMarketOrder_decorators, { kind: "method", name: "placeMarketOrder", static: false, private: false, access: { has: obj => "placeMarketOrder" in obj, get: obj => obj.placeMarketOrder }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
93
|
+
__esDecorate(this, null, _placeLimitOrder_decorators, { kind: "method", name: "placeLimitOrder", static: false, private: false, access: { has: obj => "placeLimitOrder" in obj, get: obj => obj.placeLimitOrder }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
94
|
+
__esDecorate(this, null, _getExchanges_decorators, { kind: "method", name: "getExchanges", static: false, private: false, access: { has: obj => "getExchanges" in obj, get: obj => obj.getExchanges }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
95
|
+
__esDecorate(this, null, _getInstruments_decorators, { kind: "method", name: "getInstruments", static: false, private: false, access: { has: obj => "getInstruments" in obj, get: obj => obj.getInstruments }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
96
|
+
__esDecorate(this, null, _getHistoryOrdersPage_decorators, { kind: "method", name: "getHistoryOrdersPage", static: false, private: false, access: { has: obj => "getHistoryOrdersPage" in obj, get: obj => obj.getHistoryOrdersPage }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
97
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
98
|
+
}
|
|
99
|
+
static URL = URL;
|
|
100
|
+
static URL_LIVE = 'https://live.trading212.com';
|
|
101
|
+
static URL_DEMO = 'https://demo.trading212.com';
|
|
102
|
+
#httpClient = __runInitializers(this, _instanceExtraInitializers);
|
|
103
|
+
constructor(options) {
|
|
104
|
+
this.#httpClient = axios.create({
|
|
105
|
+
baseURL: options.usePaperTrading ? Trading212API.URL_DEMO : Trading212API.URL_LIVE,
|
|
106
|
+
});
|
|
107
|
+
const credentials = Buffer.from(`${options.apiKey}:${options.apiSecret}`).toString('base64');
|
|
108
|
+
this.#httpClient.interceptors.request.use(config => {
|
|
109
|
+
config.headers.set('Authorization', `Basic ${credentials}`);
|
|
110
|
+
return config;
|
|
111
|
+
});
|
|
112
|
+
simplifyError(this.#httpClient);
|
|
113
|
+
}
|
|
114
|
+
get defaults() {
|
|
115
|
+
return this.#httpClient.defaults;
|
|
116
|
+
}
|
|
117
|
+
get interceptors() {
|
|
118
|
+
return this.#httpClient.interceptors;
|
|
119
|
+
}
|
|
120
|
+
async getAccountCash() {
|
|
121
|
+
const response = await this.#httpClient.get(URL.ACCOUNT_CASH);
|
|
122
|
+
return AccountCashSchema.parse(response.data);
|
|
123
|
+
}
|
|
124
|
+
async getAccountInfo() {
|
|
125
|
+
const response = await this.#httpClient.get(URL.ACCOUNT_INFO);
|
|
126
|
+
return AccountInfoSchema.parse(response.data);
|
|
127
|
+
}
|
|
128
|
+
async getPositions() {
|
|
129
|
+
const response = await this.#httpClient.get(URL.PORTFOLIO);
|
|
130
|
+
return z.array(PositionSchema).parse(response.data);
|
|
131
|
+
}
|
|
132
|
+
async getPositionByTicker(ticker) {
|
|
133
|
+
const response = await this.#httpClient.get(`${URL.PORTFOLIO}/${ticker}`);
|
|
134
|
+
return PositionSchema.parse(response.data);
|
|
135
|
+
}
|
|
136
|
+
async getOrders() {
|
|
137
|
+
const response = await this.#httpClient.get(URL.ORDERS);
|
|
138
|
+
return z.array(OrderSchema).parse(response.data);
|
|
139
|
+
}
|
|
140
|
+
async getOrderById(id) {
|
|
141
|
+
const response = await this.#httpClient.get(`${URL.ORDERS}/${id}`);
|
|
142
|
+
return OrderSchema.parse(response.data);
|
|
143
|
+
}
|
|
144
|
+
async cancelOrder(id) {
|
|
145
|
+
await this.#httpClient.delete(`${URL.ORDERS}/${id}`);
|
|
146
|
+
}
|
|
147
|
+
async placeMarketOrder(request) {
|
|
148
|
+
const validated = PlaceMarketOrderRequestSchema.parse(request);
|
|
149
|
+
const response = await this.#httpClient.post(URL.ORDERS_MARKET, validated);
|
|
150
|
+
return OrderSchema.parse(response.data);
|
|
151
|
+
}
|
|
152
|
+
async placeLimitOrder(request) {
|
|
153
|
+
const validated = PlaceLimitOrderRequestSchema.parse(request);
|
|
154
|
+
const response = await this.#httpClient.post(URL.ORDERS_LIMIT, validated);
|
|
155
|
+
return OrderSchema.parse(response.data);
|
|
156
|
+
}
|
|
157
|
+
async getExchanges() {
|
|
158
|
+
const response = await this.#httpClient.get(URL.METADATA_EXCHANGES);
|
|
159
|
+
return z.array(ExchangeSchema).parse(response.data);
|
|
160
|
+
}
|
|
161
|
+
async getInstruments() {
|
|
162
|
+
const response = await this.#httpClient.get(URL.METADATA_INSTRUMENTS);
|
|
163
|
+
return z.array(InstrumentSchema).parse(response.data);
|
|
164
|
+
}
|
|
165
|
+
async getHistoryOrdersPage(options) {
|
|
166
|
+
if (options?.nextPath) {
|
|
167
|
+
const response = await this.#httpClient.get(options.nextPath);
|
|
168
|
+
return HistoryOrderPageSchema.parse(response.data);
|
|
169
|
+
}
|
|
170
|
+
const params = { limit: '50' };
|
|
171
|
+
if (options?.ticker) {
|
|
172
|
+
params.ticker = options.ticker;
|
|
173
|
+
}
|
|
174
|
+
const response = await this.#httpClient.get(URL.HISTORY_ORDERS, { params });
|
|
116
175
|
return HistoryOrderPageSchema.parse(response.data);
|
|
117
176
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
177
|
+
async getHistoryOrders(ticker) {
|
|
178
|
+
const items = [];
|
|
179
|
+
let nextPath = undefined;
|
|
180
|
+
do {
|
|
181
|
+
const page = await this.getHistoryOrdersPage({ nextPath, ticker });
|
|
182
|
+
items.push(...page.items);
|
|
183
|
+
nextPath = page.nextPagePath ?? undefined;
|
|
184
|
+
} while (nextPath);
|
|
185
|
+
return items;
|
|
121
186
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
async getHistoryOrders(ticker) {
|
|
126
|
-
const items = [];
|
|
127
|
-
let nextPath = null;
|
|
128
|
-
const params = { limit: '50' };
|
|
129
|
-
if (ticker) {
|
|
130
|
-
params.ticker = ticker;
|
|
131
|
-
}
|
|
132
|
-
do {
|
|
133
|
-
const response = nextPath
|
|
134
|
-
? await this.#httpClient.get(nextPath)
|
|
135
|
-
: await this.#httpClient.get(URL.HISTORY_ORDERS, { params });
|
|
136
|
-
const page = HistoryOrderPageSchema.parse(response.data);
|
|
137
|
-
items.push(...page.items);
|
|
138
|
-
nextPath = page.nextPagePath;
|
|
139
|
-
} while (nextPath);
|
|
140
|
-
return items;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
187
|
+
};
|
|
188
|
+
})();
|
|
189
|
+
export { Trading212API };
|
|
143
190
|
//# sourceMappingURL=Trading212API.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Trading212API.js","sourceRoot":"","sources":["../../../../src/broker/trading212/api/Trading212API.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Trading212API.js","sourceRoot":"","sources":["../../../../src/broker/trading212/api/Trading212API.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AACpE,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,KAAK,EAAC,MAAM,wBAAwB,CAAC;AAC7C,OAAO,EAAC,aAAa,EAAC,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAC,iBAAiB,EAAE,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAC,sBAAsB,EAAoB,MAAM,gCAAgC,CAAC;AACzF,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EACL,WAAW,EACX,4BAA4B,EAC5B,6BAA6B,GAG9B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAE1D,MAAM,GAAG,GAAG;IACV,YAAY,EAAE,6BAA6B;IAC3C,YAAY,EAAE,6BAA6B;IAC3C,cAAc,EAAE,+BAA+B;IAC/C,kBAAkB,EAAE,mCAAmC;IACvD,oBAAoB,EAAE,qCAAqC;IAC3D,MAAM,EAAE,uBAAuB;IAC/B,YAAY,EAAE,6BAA6B;IAC3C,aAAa,EAAE,8BAA8B;IAC7C,SAAS,EAAE,0BAA0B;CAC7B,CAAC;IAQE,aAAa;;;;;;;;;;;;;;iBAAb,aAAa;;;0CAgCvB,KAAK,CAAC,EAAC,OAAO,EAAE,KAAK,EAAC,CAAC;0CAOvB,KAA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AAC;QACrD,CAAC;QASD,KAAK,CAAC,gBAAgB,CAAC,MAAe;YACpC,MAAM,KAAK,GAAmB,EAAE,CAAC;YACjC,IAAI,QAAQ,GAAuB,SAAS,CAAC;YAE7C,GAAG,CAAC;gBACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;gBACjE,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC1B,QAAQ,GAAG,IAAI,CAAC,YAAY,IAAI,SAAS,CAAC;YAC5C,CAAC,QAAQ,QAAQ,EAAE;YAEnB,OAAO,KAAK,CAAC;QACf,CAAC;;;SAzJU,aAAa"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ExchangeSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodNumber;
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
workingSchedules: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
6
|
+
id: z.ZodNumber;
|
|
7
|
+
}, z.core.$loose>>>>;
|
|
8
|
+
}, z.core.$loose>;
|
|
9
|
+
export type Exchange = z.infer<typeof ExchangeSchema>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExchangeSchema.js","sourceRoot":"","sources":["../../../../../src/broker/trading212/api/schema/ExchangeSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAGtB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,WAAW,CAAC;IAC1C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,gBAAgB,EAAE,CAAC;SAChB,KAAK,CACJ,CAAC,CAAC,WAAW,CAAC;QACZ,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;KACf,CAAC,CACH;SACA,OAAO,EAAE;CACb,CAAC,CAAC"}
|
|
@@ -14,6 +14,7 @@ export declare const Trading212InstrumentTypeSchema: z.ZodEnum<{
|
|
|
14
14
|
export declare const InstrumentSchema: z.ZodObject<{
|
|
15
15
|
addedOn: z.ZodString;
|
|
16
16
|
currencyCode: z.ZodString;
|
|
17
|
+
extendedHours: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
17
18
|
isin: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
18
19
|
maxOpenQuantity: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
19
20
|
minTradeQuantity: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
@@ -14,6 +14,7 @@ export const Trading212InstrumentTypeSchema = z.enum([
|
|
|
14
14
|
export const InstrumentSchema = z.looseObject({
|
|
15
15
|
addedOn: z.string(),
|
|
16
16
|
currencyCode: z.string(),
|
|
17
|
+
extendedHours: z.boolean().nullish(),
|
|
17
18
|
isin: z.string().nullish(),
|
|
18
19
|
maxOpenQuantity: z.number().nullish(),
|
|
19
20
|
minTradeQuantity: z.number().nullish(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InstrumentSchema.js","sourceRoot":"","sources":["../../../../../src/broker/trading212/api/schema/InstrumentSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,CAAC,IAAI,CAAC;IACnD,SAAS;IACT,QAAQ;IACR,gBAAgB;IAChB,KAAK;IACL,KAAK;IACL,OAAO;IACP,SAAS;IACT,OAAO;IACP,OAAO;IACP,SAAS;CACV,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,WAAW,CAAC;IAC5C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;IAExB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;IAC1B,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;IACrC,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;IACtC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;IAE/B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,IAAI,EAAE,8BAA8B;IACpC,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;CACxC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"InstrumentSchema.js","sourceRoot":"","sources":["../../../../../src/broker/trading212/api/schema/InstrumentSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,CAAC,IAAI,CAAC;IACnD,SAAS;IACT,QAAQ;IACR,gBAAgB;IAChB,KAAK;IACL,KAAK;IACL,OAAO;IACP,SAAS;IACT,OAAO;IACP,OAAO;IACP,SAAS;CACV,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,WAAW,CAAC;IAC5C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;IAExB,aAAa,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE;IAEpC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;IAC1B,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;IACrC,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;IACtC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;IAE/B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,IAAI,EAAE,8BAA8B;IACpC,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;CACxC,CAAC,CAAC"}
|
|
@@ -83,7 +83,6 @@ export declare const PlaceMarketOrderRequestSchema: z.ZodObject<{
|
|
|
83
83
|
ticker: z.ZodString;
|
|
84
84
|
}, z.core.$strip>;
|
|
85
85
|
export declare const PlaceLimitOrderRequestSchema: z.ZodObject<{
|
|
86
|
-
extendedHours: z.ZodOptional<z.ZodBoolean>;
|
|
87
86
|
limitPrice: z.ZodNumber;
|
|
88
87
|
quantity: z.ZodNumber;
|
|
89
88
|
ticker: z.ZodString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OrderSchema.js","sourceRoot":"","sources":["../../../../../src/broker/trading212/api/schema/OrderSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC,IAAI,CAAC;IAChD,WAAW;IACX,YAAY;IACZ,WAAW;IACX,QAAQ;IACR,OAAO;IACP,KAAK;IACL,kBAAkB;IAClB,UAAU;IACV,UAAU;IACV,WAAW;IACX,aAAa;CACd,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;AAE3F,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;AAE3E,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAEnE,MAAM,CAAC,MA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Order } from './api/schema/HistoryOrderSchema.js';
|
|
3
|
+
export declare function latestFilledOrderId(items: HistoryOrder[]): number;
|
|
4
|
+
export declare function fetchFilledOrdersSince(api: Pick<Trading212API, 'getHistoryOrdersPage'>, lastSeenId: number): Promise<{
|
|
5
|
+
[x: string]: unknown;
|
|
6
|
+
fill?: {
|
|
7
|
+
[x: string]: unknown;
|
|
8
|
+
filledAt?: string | null | undefined;
|
|
9
|
+
id?: number | null | undefined;
|
|
10
|
+
price?: number | null | undefined;
|
|
11
|
+
quantity?: number | null | undefined;
|
|
12
|
+
tradingMethod?: string | null | undefined;
|
|
13
|
+
type?: string | null | undefined;
|
|
14
|
+
walletImpact?: {
|
|
15
|
+
[x: string]: unknown;
|
|
16
|
+
currency?: string | null | undefined;
|
|
17
|
+
fxRate?: number | null | undefined;
|
|
18
|
+
netValue?: number | null | undefined;
|
|
19
|
+
realisedProfitLoss?: number | null | undefined;
|
|
20
|
+
taxes?: {
|
|
21
|
+
[x: string]: unknown;
|
|
22
|
+
chargedAt?: string | null | undefined;
|
|
23
|
+
currency?: string | null | undefined;
|
|
24
|
+
name?: string | null | undefined;
|
|
25
|
+
quantity?: number | null | undefined;
|
|
26
|
+
}[] | null | undefined;
|
|
27
|
+
} | null | undefined;
|
|
28
|
+
} | null | undefined;
|
|
29
|
+
order: {
|
|
30
|
+
[x: string]: unknown;
|
|
31
|
+
createdAt?: string | null | undefined;
|
|
32
|
+
currency?: string | null | undefined;
|
|
33
|
+
extendedHours?: boolean | null | undefined;
|
|
34
|
+
filledQuantity?: number | null | undefined;
|
|
35
|
+
id?: number | null | undefined;
|
|
36
|
+
initiatedFrom?: string | null | undefined;
|
|
37
|
+
instrument?: {
|
|
38
|
+
[x: string]: unknown;
|
|
39
|
+
currency?: string | null | undefined;
|
|
40
|
+
isin?: string | null | undefined;
|
|
41
|
+
name?: string | null | undefined;
|
|
42
|
+
ticker?: string | null | undefined;
|
|
43
|
+
} | null | undefined;
|
|
44
|
+
limitPrice?: number | null | undefined;
|
|
45
|
+
quantity?: number | null | undefined;
|
|
46
|
+
side?: string | null | undefined;
|
|
47
|
+
status?: "CANCELLED" | "CANCELLING" | "CONFIRMED" | "FILLED" | "LOCAL" | "NEW" | "PARTIALLY_FILLED" | "REJECTED" | "REPLACED" | "REPLACING" | "UNCONFIRMED" | null | undefined;
|
|
48
|
+
stopPrice?: number | null | undefined;
|
|
49
|
+
strategy?: string | null | undefined;
|
|
50
|
+
ticker?: string | null | undefined;
|
|
51
|
+
timeValidity?: "DAY" | "GTC" | null | undefined;
|
|
52
|
+
type?: "LIMIT" | "MARKET" | "STOP" | "STOP_LIMIT" | null | undefined;
|
|
53
|
+
};
|
|
54
|
+
}[]>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Trading212OrderStatus } from './api/schema/OrderSchema.js';
|
|
2
|
+
function isFilled(item) {
|
|
3
|
+
return item.order.id != null && item.order.status === Trading212OrderStatus.FILLED;
|
|
4
|
+
}
|
|
5
|
+
export function latestFilledOrderId(items) {
|
|
6
|
+
return items.filter(isFilled).reduce((max, item) => Math.max(max, item.order.id ?? 0), 0);
|
|
7
|
+
}
|
|
8
|
+
export async function fetchFilledOrdersSince(api, lastSeenId) {
|
|
9
|
+
const newFills = [];
|
|
10
|
+
let nextPath = null;
|
|
11
|
+
do {
|
|
12
|
+
const page = await api.getHistoryOrdersPage(nextPath ? { nextPath } : undefined);
|
|
13
|
+
const seenIndex = page.items.findIndex(item => item.order.id != null && item.order.id <= lastSeenId);
|
|
14
|
+
const unseen = seenIndex === -1 ? page.items : page.items.slice(0, seenIndex);
|
|
15
|
+
newFills.push(...unseen.filter(item => isFilled(item) && item.fill));
|
|
16
|
+
nextPath = seenIndex === -1 ? page.nextPagePath : null;
|
|
17
|
+
} while (nextPath);
|
|
18
|
+
return newFills.sort((a, b) => (a.order.id ?? 0) - (b.order.id ?? 0));
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=newFilledOrders.js.map
|
|
@@ -0,0 +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S,CAAC,CAAC;QAC9E,QAAQ,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACrE,QAAQ,GAAG,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;IACzD,CAAC,QAAQ,QAAQ,EAAE;IAEnB,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACxE,CAAC"}
|
|
@@ -5,6 +5,7 @@ import { ONE_MINUTE_IN_MS } from './BatchedCandle.js';
|
|
|
5
5
|
export class CandleBatcher extends EventEmitter {
|
|
6
6
|
#batch = [];
|
|
7
7
|
#desiredIntervalInMillis;
|
|
8
|
+
#startedMidInterval;
|
|
8
9
|
constructor(desiredIntervalInMillis) {
|
|
9
10
|
super();
|
|
10
11
|
this.#desiredIntervalInMillis = desiredIntervalInMillis;
|
|
@@ -33,7 +34,10 @@ export class CandleBatcher extends EventEmitter {
|
|
|
33
34
|
const openTimesArray = batch.map(candle => candle.openTimeInMillis);
|
|
34
35
|
batch = batch.filter((candle, index) => index === openTimesArray.indexOf(candle.openTimeInMillis));
|
|
35
36
|
const firstCandle = batch[0];
|
|
36
|
-
const lastCandle = batch
|
|
37
|
+
const lastCandle = batch.at(-1);
|
|
38
|
+
if (!firstCandle || !lastCandle) {
|
|
39
|
+
throw new Error('A batched candle needs at least one candle to describe');
|
|
40
|
+
}
|
|
37
41
|
const isPositive = new Big(lastCandle.close).gt(firstCandle.open);
|
|
38
42
|
const accumulator = {
|
|
39
43
|
base: firstCandle.base,
|
|
@@ -43,7 +47,6 @@ export class CandleBatcher extends EventEmitter {
|
|
|
43
47
|
counter: firstCandle.counter,
|
|
44
48
|
high: new Big(firstCandle.high),
|
|
45
49
|
highAsk: new Big(firstCandle.highAsk || firstCandle.high),
|
|
46
|
-
isLatest: lastCandle.isLatest,
|
|
47
50
|
isNegative: !isPositive,
|
|
48
51
|
isPositive,
|
|
49
52
|
low: new Big(firstCandle.low),
|
|
@@ -69,7 +72,6 @@ export class CandleBatcher extends EventEmitter {
|
|
|
69
72
|
counter: accumulator.counter,
|
|
70
73
|
high: high.gte(candle.high) ? high : new Big(candle.high),
|
|
71
74
|
highAsk: highAsk.gte(candle.highAsk) ? highAsk : new Big(candle.highAsk),
|
|
72
|
-
isLatest: accumulator.isLatest,
|
|
73
75
|
isNegative: accumulator.isNegative,
|
|
74
76
|
isPositive: accumulator.isPositive,
|
|
75
77
|
low: low.lte(candle.low) ? low : new Big(candle.low),
|
|
@@ -100,11 +102,17 @@ export class CandleBatcher extends EventEmitter {
|
|
|
100
102
|
}
|
|
101
103
|
addToBatch(candle) {
|
|
102
104
|
const exchangeCandle = CandleBatcher.isBatchedCandle(candle) ? CandleBatcher.toCandle(candle) : candle;
|
|
105
|
+
this.#startedMidInterval ??= exchangeCandle.openTimeInMillis % this.#desiredIntervalInMillis !== 0;
|
|
103
106
|
const { currentBatchArray, newBatch } = CandleBatcher.add(exchangeCandle, this.#batch, this.#desiredIntervalInMillis);
|
|
104
107
|
this.#batch = currentBatchArray;
|
|
105
|
-
if (newBatch) {
|
|
106
|
-
|
|
108
|
+
if (!newBatch) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
if (this.#startedMidInterval) {
|
|
112
|
+
this.#startedMidInterval = false;
|
|
113
|
+
return undefined;
|
|
107
114
|
}
|
|
115
|
+
this.emit('batchedCandle', newBatch);
|
|
108
116
|
return newBatch;
|
|
109
117
|
}
|
|
110
118
|
static batchMany(candles, desiredIntervalInMillis) {
|
|
@@ -132,12 +140,6 @@ export class CandleBatcher extends EventEmitter {
|
|
|
132
140
|
return newCandle;
|
|
133
141
|
}
|
|
134
142
|
static add(candle, currentBatchArray, desiredIntervalInMillis) {
|
|
135
|
-
if (new Big(candle.volume).eq(0)) {
|
|
136
|
-
return {
|
|
137
|
-
currentBatchArray: currentBatchArray,
|
|
138
|
-
newBatch: undefined,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
143
|
if (currentBatchArray.length === 0) {
|
|
142
144
|
const adjustedCandle = CandleBatcher.adjustCandle(candle, desiredIntervalInMillis);
|
|
143
145
|
currentBatchArray.push(adjustedCandle);
|
|
@@ -150,8 +152,9 @@ export class CandleBatcher extends EventEmitter {
|
|
|
150
152
|
}
|
|
151
153
|
else {
|
|
152
154
|
const firstCandle = currentBatchArray[0];
|
|
153
|
-
const
|
|
154
|
-
const
|
|
155
|
+
const reach = firstCandle === undefined ? 0 : candle.openTimeInMillis + candle.sizeInMillis - firstCandle.openTimeInMillis;
|
|
156
|
+
const isNextInterval = reach > desiredIntervalInMillis;
|
|
157
|
+
const isEndOfCurrentInterval = reach === desiredIntervalInMillis;
|
|
155
158
|
if (isNextInterval || isEndOfCurrentInterval) {
|
|
156
159
|
if (isEndOfCurrentInterval) {
|
|
157
160
|
currentBatchArray.push(candle);
|
|
@@ -177,10 +180,15 @@ export class CandleBatcher extends EventEmitter {
|
|
|
177
180
|
};
|
|
178
181
|
}
|
|
179
182
|
static toBatchedCandles(candles) {
|
|
180
|
-
|
|
183
|
+
const [first] = candles;
|
|
184
|
+
return first ? CandleBatcher.batchMany(candles, first.sizeInMillis) : [];
|
|
181
185
|
}
|
|
182
186
|
static toBatchedCandle(candle) {
|
|
183
|
-
|
|
187
|
+
const [batched] = CandleBatcher.batchMany([candle], candle.sizeInMillis);
|
|
188
|
+
if (!batched) {
|
|
189
|
+
throw new Error('One candle always batches into one candle of the same size');
|
|
190
|
+
}
|
|
191
|
+
return batched;
|
|
184
192
|
}
|
|
185
193
|
static toCandles(candles) {
|
|
186
194
|
return candles.map(CandleBatcher.toCandle);
|
|
@@ -224,6 +232,9 @@ export class CandleBatcher extends EventEmitter {
|
|
|
224
232
|
};
|
|
225
233
|
};
|
|
226
234
|
const [firstCandle] = candles;
|
|
235
|
+
if (!firstCandle) {
|
|
236
|
+
throw new Error('A high and a low need at least one candle');
|
|
237
|
+
}
|
|
227
238
|
return candles.reduce(reducer, {
|
|
228
239
|
high: new Big(firstCandle.high),
|
|
229
240
|
low: new Big(firstCandle.low),
|