@typedtrader/exchange 0.2.2

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.
@@ -0,0 +1,361 @@
1
+ import { z } from "zod";
2
+ import { Big as Big$1 } from "big.js";
3
+ import { EventEmitter } from "node:events";
4
+ import { Bar, Client, Order } from "@master-chief/alpaca-ts";
5
+ import ms from "ms";
6
+
7
+ //#region src/core/CurrencyPair.d.ts
8
+ type CurrencyPairJSON = {
9
+ base: string;
10
+ counter: string;
11
+ };
12
+ declare class CurrencyPair implements CurrencyPairJSON {
13
+ readonly base: string;
14
+ readonly counter: string;
15
+ constructor(base: string, counter: string);
16
+ isEqual(other: CurrencyPair): boolean;
17
+ asString(delimiter: string): string;
18
+ static fromString(symbol: string, delimiter: string): CurrencyPair;
19
+ }
20
+ //#endregion
21
+ //#region src/core/Exchange.d.ts
22
+ declare enum ExchangeOrderSide {
23
+ BUY = "BUY",
24
+ SELL = "SELL",
25
+ }
26
+ interface ExchangeOrderBase {
27
+ side: ExchangeOrderSide;
28
+ size: string;
29
+ type: ExchangeOrderType;
30
+ }
31
+ declare const ExchangeCandleBaseSchema: z.ZodObject<{
32
+ base: z.ZodString;
33
+ counter: z.ZodString;
34
+ isLatest: z.ZodOptional<z.ZodBoolean>;
35
+ openTimeInISO: z.ZodString;
36
+ openTimeInMillis: z.ZodNumber;
37
+ sizeInMillis: z.ZodNumber;
38
+ }, z.core.$strip>;
39
+ type ExchangeCandleBase = z.infer<typeof ExchangeCandleBaseSchema>;
40
+ declare enum ExchangeOrderType {
41
+ LIMIT = "LIMIT",
42
+ MARKET = "MARKET",
43
+ }
44
+ declare const ExchangeCandleSchema: z.ZodObject<{
45
+ close: z.ZodString;
46
+ closeAsk: z.ZodOptional<z.ZodString>;
47
+ high: z.ZodString;
48
+ highAsk: z.ZodOptional<z.ZodString>;
49
+ low: z.ZodString;
50
+ lowAsk: z.ZodOptional<z.ZodString>;
51
+ open: z.ZodString;
52
+ openAsk: z.ZodOptional<z.ZodString>;
53
+ volume: z.ZodString;
54
+ base: z.ZodString;
55
+ counter: z.ZodString;
56
+ isLatest: z.ZodOptional<z.ZodBoolean>;
57
+ openTimeInISO: z.ZodString;
58
+ openTimeInMillis: z.ZodNumber;
59
+ sizeInMillis: z.ZodNumber;
60
+ }, z.core.$strip>;
61
+ type ExchangeCandle = z.infer<typeof ExchangeCandleSchema>;
62
+ interface ExchangeCandleImportRequest {
63
+ intervalInMillis: number;
64
+ startTimeFirstCandle: string;
65
+ startTimeLastCandle: string;
66
+ }
67
+ interface ExchangeFeeRate {
68
+ [ExchangeOrderType.LIMIT]: Big;
69
+ [ExchangeOrderType.MARKET]: Big;
70
+ }
71
+ declare enum ExchangeOrderPosition {
72
+ LONG = "LONG",
73
+ SHORT = "SHORT",
74
+ }
75
+ interface ExchangeFill {
76
+ created_at: string;
77
+ fee: string;
78
+ feeAsset: string;
79
+ order_id: string;
80
+ pair: CurrencyPair;
81
+ position: ExchangeOrderPosition;
82
+ price: string;
83
+ side: ExchangeOrderSide;
84
+ size: string;
85
+ }
86
+ interface ExchangePendingOrderBase {
87
+ id: string;
88
+ pair: CurrencyPair;
89
+ side: ExchangeOrderSide;
90
+ size: string;
91
+ type: ExchangeOrderType;
92
+ }
93
+ interface ExchangePendingLimitOrder extends ExchangePendingOrderBase {
94
+ price: string;
95
+ type: ExchangeOrderType.LIMIT;
96
+ }
97
+ interface ExchangePendingMarketOrder extends ExchangePendingOrderBase {
98
+ type: ExchangeOrderType.MARKET;
99
+ }
100
+ interface ExchangeMarketOrderOptions extends ExchangeOrderBase {
101
+ sizeInCounter: boolean;
102
+ type: ExchangeOrderType.MARKET;
103
+ }
104
+ interface ExchangeLimitOrderOptions extends ExchangeOrderBase {
105
+ price: string;
106
+ sizeInCounter: false;
107
+ type: ExchangeOrderType.LIMIT;
108
+ }
109
+ type ExchangeOrderOptions = ExchangeMarketOrderOptions | ExchangeLimitOrderOptions;
110
+ declare abstract class Exchange {
111
+ loggerName: string;
112
+ constructor(loggerName: string);
113
+ abstract getCandles(pair: CurrencyPair, request: ExchangeCandleImportRequest): Promise<ExchangeCandle[]>;
114
+ getLatestAvailableCandle(pair: CurrencyPair, intervalInMillis: number): Promise<ExchangeCandle>;
115
+ abstract getName(): string;
116
+ abstract getTime(): Promise<string>;
117
+ }
118
+ //#endregion
119
+ //#region src/candle/BatchedCandle.d.ts
120
+ declare const BasicCandlePrice: z.ZodUnion<readonly [z.ZodLiteral<"open">, z.ZodLiteral<"high">, z.ZodLiteral<"low">, z.ZodLiteral<"close">]>;
121
+ type BasicCandlePriceProperty = z.infer<typeof BasicCandlePrice>;
122
+ interface BatchedCandle extends ExchangeCandleBase {
123
+ close: Big;
124
+ closeAsk: Big;
125
+ high: Big;
126
+ highAsk: Big;
127
+ low: Big;
128
+ lowAsk: Big;
129
+ open: Big;
130
+ openAsk: Big;
131
+ change: Big;
132
+ medianPrice: Big;
133
+ volume: Big;
134
+ weightedMedianPrice: Big;
135
+ isNegative: boolean;
136
+ isPositive: boolean;
137
+ }
138
+ //#endregion
139
+ //#region src/candle/CandleBatcher.d.ts
140
+ type EventMap = {
141
+ batchedCandle: [candle: BatchedCandle];
142
+ };
143
+ declare class CandleBatcher extends EventEmitter<EventMap> {
144
+ private batch;
145
+ private readonly desiredIntervalInMillis;
146
+ constructor(desiredIntervalInMillis: number);
147
+ get present(): number;
148
+ static amountOfCandles(intervalInMillis: number | string, timespanInMillis: number | string): number;
149
+ static isBatchedCandle(candle: ExchangeCandle | BatchedCandle): candle is BatchedCandle;
150
+ static createBatchedCandle(batch: ExchangeCandle[], desiredIntervalInMillis: number): BatchedCandle;
151
+ addToBatch(candle: ExchangeCandle | BatchedCandle): BatchedCandle | undefined;
152
+ static batchMany(candles: ExchangeCandle[], desiredIntervalInMillis: number): BatchedCandle[];
153
+ static adjustCandle(candle: ExchangeCandle, desiredIntervalInMillis: number): ExchangeCandle;
154
+ static add(candle: ExchangeCandle, currentBatchArray: ExchangeCandle[], desiredIntervalInMillis: number): {
155
+ currentBatchArray: ExchangeCandle[];
156
+ newBatch: BatchedCandle | undefined;
157
+ };
158
+ static toBatchedCandles(candles: ExchangeCandle[]): BatchedCandle[];
159
+ static toBatchedCandle(candle: ExchangeCandle): BatchedCandle;
160
+ static toExchangeCandles(candles: BatchedCandle[]): ExchangeCandle[];
161
+ static toExchangeCandle(candle: BatchedCandle): ExchangeCandle;
162
+ static toString(candle: BatchedCandle): string;
163
+ static getHighAndLow(candles: ExchangeCandle[]): {
164
+ high: Big$1;
165
+ low: Big$1;
166
+ };
167
+ }
168
+ //#endregion
169
+ //#region src/exchange-alpaca/AlpacaExchange.d.ts
170
+ declare const hasErrorCode: (error: unknown) => error is {
171
+ code: string | number;
172
+ };
173
+ declare const hasErrorStatus: (error: unknown) => error is {
174
+ status: number;
175
+ };
176
+ declare class AlpacaExchange extends Exchange {
177
+ private readonly stream;
178
+ readonly client: Client;
179
+ private readonly SUBSCRIPTION_PLAN;
180
+ private readonly retryConfig;
181
+ constructor(options: {
182
+ apiKey: string;
183
+ apiSecret: string;
184
+ usePaperTrading: boolean;
185
+ });
186
+ static NAME: string;
187
+ private createSymbol;
188
+ private fetchLatestCryptoBars;
189
+ private isCryptoSymbol;
190
+ private fetchCryptoBars;
191
+ private fetchStockBars;
192
+ getCandles(pair: CurrencyPair, request: ExchangeCandleImportRequest): Promise<ExchangeCandle[]>;
193
+ getName(): string;
194
+ getTime(): Promise<string>;
195
+ disconnect(): void;
196
+ }
197
+ //#endregion
198
+ //#region src/exchange-alpaca/typings.d.ts
199
+ type CryptoAsset = {
200
+ attributes: string[];
201
+ class: string;
202
+ easy_to_borrow: boolean;
203
+ exchange: string;
204
+ fractionable: boolean;
205
+ id: string;
206
+ maintenance_margin_requirement: number;
207
+ marginable: boolean;
208
+ min_order_size: string;
209
+ min_trade_increment: string;
210
+ name: string;
211
+ price_increment: string;
212
+ shortable: boolean;
213
+ status: string;
214
+ symbol: string;
215
+ tradable: boolean;
216
+ };
217
+ type PendingNewOrder = {
218
+ asset_class: string;
219
+ asset_id: string;
220
+ canceled_at: string;
221
+ client_order_id: string;
222
+ created_at: string;
223
+ expired_at: string;
224
+ extended_hours: boolean;
225
+ failed_at: string;
226
+ filled_at: string;
227
+ filled_avg_price: null;
228
+ filled_qty: number;
229
+ hwm: null;
230
+ id: string;
231
+ order_class: string;
232
+ replaced_at: string;
233
+ replaced_by: null;
234
+ replaces: null;
235
+ source: null;
236
+ stop_price: null;
237
+ submitted_at: string;
238
+ subtag: null;
239
+ symbol: string;
240
+ time_in_force: string;
241
+ trail_percent: null;
242
+ trail_price: null;
243
+ updated_at: string;
244
+ status: "pending_new";
245
+ notional: number | null;
246
+ qty: number | null;
247
+ side: string;
248
+ type: string;
249
+ limit_price: number | null;
250
+ };
251
+ type QuantitativeMarketBuy = PendingNewOrder & {
252
+ notional: null;
253
+ qty: number;
254
+ side: "buy";
255
+ type: "market";
256
+ limit_price: null;
257
+ };
258
+ type QuantitativeMarketSell = PendingNewOrder & {
259
+ notional: null;
260
+ qty: number;
261
+ side: "sell";
262
+ type: "market";
263
+ limit_price: null;
264
+ };
265
+ type QuantitativeLimitBuy = PendingNewOrder & {
266
+ notional: null;
267
+ qty: number;
268
+ side: "buy";
269
+ type: "limit";
270
+ limit_price: number;
271
+ };
272
+ type QuantitativeLimitSell = PendingNewOrder & {
273
+ notional: null;
274
+ qty: number;
275
+ side: "sell";
276
+ type: "limit";
277
+ limit_price: number;
278
+ };
279
+ type NotionalMarketBuy = PendingNewOrder & {
280
+ notional: number;
281
+ qty: null;
282
+ side: "buy";
283
+ type: "market";
284
+ limit_price: null;
285
+ };
286
+ type NotionalMarketSell = PendingNewOrder & {
287
+ notional: number;
288
+ qty: null;
289
+ side: "sell";
290
+ type: "market";
291
+ limit_price: null;
292
+ };
293
+ type NotionalLimitBuy = PendingNewOrder & {
294
+ notional: number;
295
+ qty: null;
296
+ side: "buy";
297
+ type: "limit";
298
+ limit_price: number;
299
+ };
300
+ type NotionalLimitSell = PendingNewOrder & {
301
+ notional: number;
302
+ qty: null;
303
+ side: "sell";
304
+ type: "limit";
305
+ limit_price: number;
306
+ };
307
+ type PendingNewOrders = NotionalLimitSell | NotionalLimitBuy | NotionalMarketSell | NotionalMarketBuy | QuantitativeLimitSell | QuantitativeLimitBuy | QuantitativeMarketSell | QuantitativeMarketBuy;
308
+ interface ConnectedMessage {
309
+ msg: "connected";
310
+ T: "success";
311
+ }
312
+ interface AuthenticatedMessage {
313
+ msg: "authenticated";
314
+ T: "success";
315
+ }
316
+ interface SubscriptionMessage {
317
+ bars: string[];
318
+ cancelErrors: [];
319
+ corrections: [];
320
+ dailyBars: [];
321
+ lulds: [];
322
+ quotes: [];
323
+ statuses: [];
324
+ T: "subscription";
325
+ trades: [];
326
+ updatedBars: [];
327
+ }
328
+ type MinuteBarMessage = {
329
+ c: number;
330
+ h: number;
331
+ l: number;
332
+ n: number;
333
+ o: number;
334
+ S: string;
335
+ T: "b";
336
+ t: string;
337
+ v: number;
338
+ vw: number;
339
+ };
340
+ type StreamMessage = ConnectedMessage | AuthenticatedMessage | SubscriptionMessage | MinuteBarMessage;
341
+ //#endregion
342
+ //#region src/exchange-alpaca/AlpacaExchangeMapper.d.ts
343
+ declare class AlpacaExchangeMapper {
344
+ static mapInterval(intervalInMillis: number): string;
345
+ static toExchangeCandle(candle: Bar, pair: CurrencyPair, sizeInMillis: number): ExchangeCandle;
346
+ static toExchangePendingOrder(order: PendingNewOrders, pair: CurrencyPair, options: ExchangeOrderOptions): ExchangePendingMarketOrder | ExchangePendingLimitOrder;
347
+ static toFilledOrder(order: Order, pair: CurrencyPair): ExchangeFill;
348
+ }
349
+ //#endregion
350
+ //#region src/exchange-alpaca/getAlpacaClient.d.ts
351
+ declare function getAlpacaClient({
352
+ apiKey,
353
+ apiSecret,
354
+ usePaperTrading
355
+ }: {
356
+ apiKey: string;
357
+ apiSecret: string;
358
+ usePaperTrading: boolean;
359
+ }): AlpacaExchange;
360
+ //#endregion
361
+ export { AlpacaExchange, AlpacaExchangeMapper, AuthenticatedMessage, BasicCandlePrice, BasicCandlePriceProperty, BatchedCandle, CandleBatcher, ConnectedMessage, CryptoAsset, CurrencyPair, CurrencyPairJSON, Exchange, ExchangeCandle, ExchangeCandleBase, ExchangeCandleBaseSchema, ExchangeCandleImportRequest, ExchangeCandleSchema, ExchangeFeeRate, ExchangeFill, ExchangeLimitOrderOptions, ExchangeMarketOrderOptions, ExchangeOrderOptions, ExchangeOrderPosition, ExchangeOrderSide, ExchangeOrderType, ExchangePendingLimitOrder, ExchangePendingMarketOrder, ExchangePendingOrderBase, MinuteBarMessage, NotionalLimitBuy, NotionalLimitSell, NotionalMarketBuy, NotionalMarketSell, PendingNewOrder, PendingNewOrders, QuantitativeLimitBuy, QuantitativeLimitSell, QuantitativeMarketBuy, QuantitativeMarketSell, StreamMessage, SubscriptionMessage, getAlpacaClient, hasErrorCode, hasErrorStatus, ms };
@@ -0,0 +1,361 @@
1
+ import { z } from "zod";
2
+ import { EventEmitter } from "node:events";
3
+ import ms from "ms";
4
+ import { Bar, Client, Order } from "@master-chief/alpaca-ts";
5
+ import { Big as Big$1 } from "big.js";
6
+
7
+ //#region src/core/CurrencyPair.d.ts
8
+ type CurrencyPairJSON = {
9
+ base: string;
10
+ counter: string;
11
+ };
12
+ declare class CurrencyPair implements CurrencyPairJSON {
13
+ readonly base: string;
14
+ readonly counter: string;
15
+ constructor(base: string, counter: string);
16
+ isEqual(other: CurrencyPair): boolean;
17
+ asString(delimiter: string): string;
18
+ static fromString(symbol: string, delimiter: string): CurrencyPair;
19
+ }
20
+ //#endregion
21
+ //#region src/core/Exchange.d.ts
22
+ declare enum ExchangeOrderSide {
23
+ BUY = "BUY",
24
+ SELL = "SELL",
25
+ }
26
+ interface ExchangeOrderBase {
27
+ side: ExchangeOrderSide;
28
+ size: string;
29
+ type: ExchangeOrderType;
30
+ }
31
+ declare const ExchangeCandleBaseSchema: z.ZodObject<{
32
+ base: z.ZodString;
33
+ counter: z.ZodString;
34
+ isLatest: z.ZodOptional<z.ZodBoolean>;
35
+ openTimeInISO: z.ZodString;
36
+ openTimeInMillis: z.ZodNumber;
37
+ sizeInMillis: z.ZodNumber;
38
+ }, z.core.$strip>;
39
+ type ExchangeCandleBase = z.infer<typeof ExchangeCandleBaseSchema>;
40
+ declare enum ExchangeOrderType {
41
+ LIMIT = "LIMIT",
42
+ MARKET = "MARKET",
43
+ }
44
+ declare const ExchangeCandleSchema: z.ZodObject<{
45
+ close: z.ZodString;
46
+ closeAsk: z.ZodOptional<z.ZodString>;
47
+ high: z.ZodString;
48
+ highAsk: z.ZodOptional<z.ZodString>;
49
+ low: z.ZodString;
50
+ lowAsk: z.ZodOptional<z.ZodString>;
51
+ open: z.ZodString;
52
+ openAsk: z.ZodOptional<z.ZodString>;
53
+ volume: z.ZodString;
54
+ base: z.ZodString;
55
+ counter: z.ZodString;
56
+ isLatest: z.ZodOptional<z.ZodBoolean>;
57
+ openTimeInISO: z.ZodString;
58
+ openTimeInMillis: z.ZodNumber;
59
+ sizeInMillis: z.ZodNumber;
60
+ }, z.core.$strip>;
61
+ type ExchangeCandle = z.infer<typeof ExchangeCandleSchema>;
62
+ interface ExchangeCandleImportRequest {
63
+ intervalInMillis: number;
64
+ startTimeFirstCandle: string;
65
+ startTimeLastCandle: string;
66
+ }
67
+ interface ExchangeFeeRate {
68
+ [ExchangeOrderType.LIMIT]: Big;
69
+ [ExchangeOrderType.MARKET]: Big;
70
+ }
71
+ declare enum ExchangeOrderPosition {
72
+ LONG = "LONG",
73
+ SHORT = "SHORT",
74
+ }
75
+ interface ExchangeFill {
76
+ created_at: string;
77
+ fee: string;
78
+ feeAsset: string;
79
+ order_id: string;
80
+ pair: CurrencyPair;
81
+ position: ExchangeOrderPosition;
82
+ price: string;
83
+ side: ExchangeOrderSide;
84
+ size: string;
85
+ }
86
+ interface ExchangePendingOrderBase {
87
+ id: string;
88
+ pair: CurrencyPair;
89
+ side: ExchangeOrderSide;
90
+ size: string;
91
+ type: ExchangeOrderType;
92
+ }
93
+ interface ExchangePendingLimitOrder extends ExchangePendingOrderBase {
94
+ price: string;
95
+ type: ExchangeOrderType.LIMIT;
96
+ }
97
+ interface ExchangePendingMarketOrder extends ExchangePendingOrderBase {
98
+ type: ExchangeOrderType.MARKET;
99
+ }
100
+ interface ExchangeMarketOrderOptions extends ExchangeOrderBase {
101
+ sizeInCounter: boolean;
102
+ type: ExchangeOrderType.MARKET;
103
+ }
104
+ interface ExchangeLimitOrderOptions extends ExchangeOrderBase {
105
+ price: string;
106
+ sizeInCounter: false;
107
+ type: ExchangeOrderType.LIMIT;
108
+ }
109
+ type ExchangeOrderOptions = ExchangeMarketOrderOptions | ExchangeLimitOrderOptions;
110
+ declare abstract class Exchange {
111
+ loggerName: string;
112
+ constructor(loggerName: string);
113
+ abstract getCandles(pair: CurrencyPair, request: ExchangeCandleImportRequest): Promise<ExchangeCandle[]>;
114
+ getLatestAvailableCandle(pair: CurrencyPair, intervalInMillis: number): Promise<ExchangeCandle>;
115
+ abstract getName(): string;
116
+ abstract getTime(): Promise<string>;
117
+ }
118
+ //#endregion
119
+ //#region src/candle/BatchedCandle.d.ts
120
+ declare const BasicCandlePrice: z.ZodUnion<readonly [z.ZodLiteral<"open">, z.ZodLiteral<"high">, z.ZodLiteral<"low">, z.ZodLiteral<"close">]>;
121
+ type BasicCandlePriceProperty = z.infer<typeof BasicCandlePrice>;
122
+ interface BatchedCandle extends ExchangeCandleBase {
123
+ close: Big;
124
+ closeAsk: Big;
125
+ high: Big;
126
+ highAsk: Big;
127
+ low: Big;
128
+ lowAsk: Big;
129
+ open: Big;
130
+ openAsk: Big;
131
+ change: Big;
132
+ medianPrice: Big;
133
+ volume: Big;
134
+ weightedMedianPrice: Big;
135
+ isNegative: boolean;
136
+ isPositive: boolean;
137
+ }
138
+ //#endregion
139
+ //#region src/candle/CandleBatcher.d.ts
140
+ type EventMap = {
141
+ batchedCandle: [candle: BatchedCandle];
142
+ };
143
+ declare class CandleBatcher extends EventEmitter<EventMap> {
144
+ private batch;
145
+ private readonly desiredIntervalInMillis;
146
+ constructor(desiredIntervalInMillis: number);
147
+ get present(): number;
148
+ static amountOfCandles(intervalInMillis: number | string, timespanInMillis: number | string): number;
149
+ static isBatchedCandle(candle: ExchangeCandle | BatchedCandle): candle is BatchedCandle;
150
+ static createBatchedCandle(batch: ExchangeCandle[], desiredIntervalInMillis: number): BatchedCandle;
151
+ addToBatch(candle: ExchangeCandle | BatchedCandle): BatchedCandle | undefined;
152
+ static batchMany(candles: ExchangeCandle[], desiredIntervalInMillis: number): BatchedCandle[];
153
+ static adjustCandle(candle: ExchangeCandle, desiredIntervalInMillis: number): ExchangeCandle;
154
+ static add(candle: ExchangeCandle, currentBatchArray: ExchangeCandle[], desiredIntervalInMillis: number): {
155
+ currentBatchArray: ExchangeCandle[];
156
+ newBatch: BatchedCandle | undefined;
157
+ };
158
+ static toBatchedCandles(candles: ExchangeCandle[]): BatchedCandle[];
159
+ static toBatchedCandle(candle: ExchangeCandle): BatchedCandle;
160
+ static toExchangeCandles(candles: BatchedCandle[]): ExchangeCandle[];
161
+ static toExchangeCandle(candle: BatchedCandle): ExchangeCandle;
162
+ static toString(candle: BatchedCandle): string;
163
+ static getHighAndLow(candles: ExchangeCandle[]): {
164
+ high: Big$1;
165
+ low: Big$1;
166
+ };
167
+ }
168
+ //#endregion
169
+ //#region src/exchange-alpaca/AlpacaExchange.d.ts
170
+ declare const hasErrorCode: (error: unknown) => error is {
171
+ code: string | number;
172
+ };
173
+ declare const hasErrorStatus: (error: unknown) => error is {
174
+ status: number;
175
+ };
176
+ declare class AlpacaExchange extends Exchange {
177
+ private readonly stream;
178
+ readonly client: Client;
179
+ private readonly SUBSCRIPTION_PLAN;
180
+ private readonly retryConfig;
181
+ constructor(options: {
182
+ apiKey: string;
183
+ apiSecret: string;
184
+ usePaperTrading: boolean;
185
+ });
186
+ static NAME: string;
187
+ private createSymbol;
188
+ private fetchLatestCryptoBars;
189
+ private isCryptoSymbol;
190
+ private fetchCryptoBars;
191
+ private fetchStockBars;
192
+ getCandles(pair: CurrencyPair, request: ExchangeCandleImportRequest): Promise<ExchangeCandle[]>;
193
+ getName(): string;
194
+ getTime(): Promise<string>;
195
+ disconnect(): void;
196
+ }
197
+ //#endregion
198
+ //#region src/exchange-alpaca/typings.d.ts
199
+ type CryptoAsset = {
200
+ attributes: string[];
201
+ class: string;
202
+ easy_to_borrow: boolean;
203
+ exchange: string;
204
+ fractionable: boolean;
205
+ id: string;
206
+ maintenance_margin_requirement: number;
207
+ marginable: boolean;
208
+ min_order_size: string;
209
+ min_trade_increment: string;
210
+ name: string;
211
+ price_increment: string;
212
+ shortable: boolean;
213
+ status: string;
214
+ symbol: string;
215
+ tradable: boolean;
216
+ };
217
+ type PendingNewOrder = {
218
+ asset_class: string;
219
+ asset_id: string;
220
+ canceled_at: string;
221
+ client_order_id: string;
222
+ created_at: string;
223
+ expired_at: string;
224
+ extended_hours: boolean;
225
+ failed_at: string;
226
+ filled_at: string;
227
+ filled_avg_price: null;
228
+ filled_qty: number;
229
+ hwm: null;
230
+ id: string;
231
+ order_class: string;
232
+ replaced_at: string;
233
+ replaced_by: null;
234
+ replaces: null;
235
+ source: null;
236
+ stop_price: null;
237
+ submitted_at: string;
238
+ subtag: null;
239
+ symbol: string;
240
+ time_in_force: string;
241
+ trail_percent: null;
242
+ trail_price: null;
243
+ updated_at: string;
244
+ status: "pending_new";
245
+ notional: number | null;
246
+ qty: number | null;
247
+ side: string;
248
+ type: string;
249
+ limit_price: number | null;
250
+ };
251
+ type QuantitativeMarketBuy = PendingNewOrder & {
252
+ notional: null;
253
+ qty: number;
254
+ side: "buy";
255
+ type: "market";
256
+ limit_price: null;
257
+ };
258
+ type QuantitativeMarketSell = PendingNewOrder & {
259
+ notional: null;
260
+ qty: number;
261
+ side: "sell";
262
+ type: "market";
263
+ limit_price: null;
264
+ };
265
+ type QuantitativeLimitBuy = PendingNewOrder & {
266
+ notional: null;
267
+ qty: number;
268
+ side: "buy";
269
+ type: "limit";
270
+ limit_price: number;
271
+ };
272
+ type QuantitativeLimitSell = PendingNewOrder & {
273
+ notional: null;
274
+ qty: number;
275
+ side: "sell";
276
+ type: "limit";
277
+ limit_price: number;
278
+ };
279
+ type NotionalMarketBuy = PendingNewOrder & {
280
+ notional: number;
281
+ qty: null;
282
+ side: "buy";
283
+ type: "market";
284
+ limit_price: null;
285
+ };
286
+ type NotionalMarketSell = PendingNewOrder & {
287
+ notional: number;
288
+ qty: null;
289
+ side: "sell";
290
+ type: "market";
291
+ limit_price: null;
292
+ };
293
+ type NotionalLimitBuy = PendingNewOrder & {
294
+ notional: number;
295
+ qty: null;
296
+ side: "buy";
297
+ type: "limit";
298
+ limit_price: number;
299
+ };
300
+ type NotionalLimitSell = PendingNewOrder & {
301
+ notional: number;
302
+ qty: null;
303
+ side: "sell";
304
+ type: "limit";
305
+ limit_price: number;
306
+ };
307
+ type PendingNewOrders = NotionalLimitSell | NotionalLimitBuy | NotionalMarketSell | NotionalMarketBuy | QuantitativeLimitSell | QuantitativeLimitBuy | QuantitativeMarketSell | QuantitativeMarketBuy;
308
+ interface ConnectedMessage {
309
+ msg: "connected";
310
+ T: "success";
311
+ }
312
+ interface AuthenticatedMessage {
313
+ msg: "authenticated";
314
+ T: "success";
315
+ }
316
+ interface SubscriptionMessage {
317
+ bars: string[];
318
+ cancelErrors: [];
319
+ corrections: [];
320
+ dailyBars: [];
321
+ lulds: [];
322
+ quotes: [];
323
+ statuses: [];
324
+ T: "subscription";
325
+ trades: [];
326
+ updatedBars: [];
327
+ }
328
+ type MinuteBarMessage = {
329
+ c: number;
330
+ h: number;
331
+ l: number;
332
+ n: number;
333
+ o: number;
334
+ S: string;
335
+ T: "b";
336
+ t: string;
337
+ v: number;
338
+ vw: number;
339
+ };
340
+ type StreamMessage = ConnectedMessage | AuthenticatedMessage | SubscriptionMessage | MinuteBarMessage;
341
+ //#endregion
342
+ //#region src/exchange-alpaca/AlpacaExchangeMapper.d.ts
343
+ declare class AlpacaExchangeMapper {
344
+ static mapInterval(intervalInMillis: number): string;
345
+ static toExchangeCandle(candle: Bar, pair: CurrencyPair, sizeInMillis: number): ExchangeCandle;
346
+ static toExchangePendingOrder(order: PendingNewOrders, pair: CurrencyPair, options: ExchangeOrderOptions): ExchangePendingMarketOrder | ExchangePendingLimitOrder;
347
+ static toFilledOrder(order: Order, pair: CurrencyPair): ExchangeFill;
348
+ }
349
+ //#endregion
350
+ //#region src/exchange-alpaca/getAlpacaClient.d.ts
351
+ declare function getAlpacaClient({
352
+ apiKey,
353
+ apiSecret,
354
+ usePaperTrading
355
+ }: {
356
+ apiKey: string;
357
+ apiSecret: string;
358
+ usePaperTrading: boolean;
359
+ }): AlpacaExchange;
360
+ //#endregion
361
+ export { AlpacaExchange, AlpacaExchangeMapper, AuthenticatedMessage, BasicCandlePrice, BasicCandlePriceProperty, BatchedCandle, CandleBatcher, ConnectedMessage, CryptoAsset, CurrencyPair, CurrencyPairJSON, Exchange, ExchangeCandle, ExchangeCandleBase, ExchangeCandleBaseSchema, ExchangeCandleImportRequest, ExchangeCandleSchema, ExchangeFeeRate, ExchangeFill, ExchangeLimitOrderOptions, ExchangeMarketOrderOptions, ExchangeOrderOptions, ExchangeOrderPosition, ExchangeOrderSide, ExchangeOrderType, ExchangePendingLimitOrder, ExchangePendingMarketOrder, ExchangePendingOrderBase, MinuteBarMessage, NotionalLimitBuy, NotionalLimitSell, NotionalMarketBuy, NotionalMarketSell, PendingNewOrder, PendingNewOrders, QuantitativeLimitBuy, QuantitativeLimitSell, QuantitativeMarketBuy, QuantitativeMarketSell, StreamMessage, SubscriptionMessage, getAlpacaClient, hasErrorCode, hasErrorStatus, ms };