wenay-common 1.0.21 → 1.0.22
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/lib/{srcClient/index.js → index.js} +16 -16
- package/package.json +5 -1
- package/lib/src/Common/BaseTypes.d.ts +0 -38
- package/lib/src/Common/BaseTypes.js +0 -3
- package/lib/src/Common/BaseTypes.js.map +0 -1
- package/lib/src/Common/ByteStream.d.ts +0 -96
- package/lib/src/Common/ByteStream.js +0 -427
- package/lib/src/Common/ByteStream.js.map +0 -1
- package/lib/src/Common/Color.d.ts +0 -26
- package/lib/src/Common/Color.js +0 -52
- package/lib/src/Common/Color.js.map +0 -1
- package/lib/src/Common/Common.d.ts +0 -232
- package/lib/src/Common/Common.js +0 -615
- package/lib/src/Common/Common.js.map +0 -1
- package/lib/src/Common/List.d.ts +0 -64
- package/lib/src/Common/List.js +0 -194
- package/lib/src/Common/List.js.map +0 -1
- package/lib/src/Common/ListNodeAnd.d.ts +0 -46
- package/lib/src/Common/ListNodeAnd.js +0 -90
- package/lib/src/Common/ListNodeAnd.js.map +0 -1
- package/lib/src/Common/Math.d.ts +0 -27
- package/lib/src/Common/Math.js +0 -71
- package/lib/src/Common/Math.js.map +0 -1
- package/lib/src/Common/Time.d.ts +0 -181
- package/lib/src/Common/Time.js +0 -356
- package/lib/src/Common/Time.js.map +0 -1
- package/lib/src/Exchange/Bars.d.ts +0 -182
- package/lib/src/Exchange/Bars.js +0 -454
- package/lib/src/Exchange/Bars.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/base.d.ts +0 -28
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/base.js +0 -9
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/base.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/spot.d.ts +0 -600
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/spot.js +0 -356
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/spot.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/type.d.ts +0 -4
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/type.js +0 -108
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/type.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/commonOrder.d.ts +0 -1
- package/lib/src/Exchange/ConnectData/Binance/commonOrder.js +0 -9
- package/lib/src/Exchange/ConnectData/Binance/commonOrder.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/funcTimeWait.d.ts +0 -22
- package/lib/src/Exchange/ConnectData/Binance/funcTimeWait.js +0 -44
- package/lib/src/Exchange/ConnectData/Binance/funcTimeWait.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/interfaces.d.ts +0 -345
- package/lib/src/Exchange/ConnectData/Binance/interfaces.js +0 -3
- package/lib/src/Exchange/ConnectData/Binance/interfaces.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/order.d.ts +0 -204
- package/lib/src/Exchange/ConnectData/Binance/order.js +0 -417
- package/lib/src/Exchange/ConnectData/Binance/order.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/signatureCoder.d.ts +0 -14
- package/lib/src/Exchange/ConnectData/Binance/signatureCoder.js +0 -26
- package/lib/src/Exchange/ConnectData/Binance/signatureCoder.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/use.d.ts +0 -44
- package/lib/src/Exchange/ConnectData/Binance/use.js +0 -90
- package/lib/src/Exchange/ConnectData/Binance/use.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance.d.ts +0 -122
- package/lib/src/Exchange/ConnectData/Binance.js +0 -514
- package/lib/src/Exchange/ConnectData/Binance.js.map +0 -1
- package/lib/src/Exchange/IHistoryBase.d.ts +0 -157
- package/lib/src/Exchange/IHistoryBase.js +0 -3
- package/lib/src/Exchange/IHistoryBase.js.map +0 -1
- package/lib/src/Exchange/LoadBase.d.ts +0 -59
- package/lib/src/Exchange/LoadBase.js +0 -103
- package/lib/src/Exchange/LoadBase.js.map +0 -1
- package/lib/src/Exchange/MarketData.d.ts +0 -78
- package/lib/src/Exchange/MarketData.js +0 -358
- package/lib/src/Exchange/MarketData.js.map +0 -1
- package/lib/src/Exchange/mini.d.ts +0 -68
- package/lib/src/Exchange/mini.js +0 -3
- package/lib/src/Exchange/mini.js.map +0 -1
- package/lib/srcClient/index.d.ts +0 -15
- package/lib/srcClient/index.js.map +0 -1
- package/lib/srcServer/index.d.ts +0 -16
- package/lib/srcServer/index.js +0 -40
- package/lib/srcServer/index.js.map +0 -1
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/// <reference path="../Common/BaseTypes.d.ts" />
|
|
2
|
-
import * as lib from "../Common/Common";
|
|
3
|
-
import { IItems, ParsedUrlQueryInputMy, SearchMatchMode } from "../Common/Common";
|
|
4
|
-
import { TF } from "../Common/Time";
|
|
5
|
-
import { ByteStreamR, ByteStreamW, Nullable, NumericTypes } from "../Common/ByteStream";
|
|
6
|
-
import { const_Date, ReadonlyFull } from "../Common/BaseTypes";
|
|
7
|
-
export * from "../Common/Time";
|
|
8
|
-
export declare class OHLC {
|
|
9
|
-
readonly open: number;
|
|
10
|
-
readonly high: number;
|
|
11
|
-
readonly low: number;
|
|
12
|
-
readonly close: number;
|
|
13
|
-
constructor(open: number, high: number, low: number, close: number);
|
|
14
|
-
}
|
|
15
|
-
export type IBar = CBarBase;
|
|
16
|
-
export declare class CBarBase {
|
|
17
|
-
readonly time: const_Date;
|
|
18
|
-
readonly open: number;
|
|
19
|
-
readonly high: number;
|
|
20
|
-
readonly low: number;
|
|
21
|
-
readonly close: number;
|
|
22
|
-
readonly volume: number;
|
|
23
|
-
readonly tickVolume: number;
|
|
24
|
-
constructor(data: CBarBase);
|
|
25
|
-
constructor(time: const_Date, open: number, high: number, low: number, close: number, volume?: number, tickVolume?: number);
|
|
26
|
-
}
|
|
27
|
-
export declare class CBar extends CBarBase {
|
|
28
|
-
static new(time: const_Date, ohlc: OHLC, volume?: number, tickVolume?: number): CBar;
|
|
29
|
-
static fromParsedJSON(data: ParsedUrlQueryInputMy<CBar>): CBar;
|
|
30
|
-
}
|
|
31
|
-
export type BarInfo = Readonly<{
|
|
32
|
-
bar: CBar;
|
|
33
|
-
closed: boolean;
|
|
34
|
-
index: number;
|
|
35
|
-
getAllBars: () => IBars;
|
|
36
|
-
}>;
|
|
37
|
-
export interface ITick {
|
|
38
|
-
readonly time: const_Date;
|
|
39
|
-
readonly price: number;
|
|
40
|
-
readonly volume: number;
|
|
41
|
-
}
|
|
42
|
-
export declare class CTick implements ITick {
|
|
43
|
-
readonly time: const_Date;
|
|
44
|
-
readonly price: number;
|
|
45
|
-
readonly volume: number;
|
|
46
|
-
constructor(time: const_Date, price: number, volume: number);
|
|
47
|
-
}
|
|
48
|
-
export declare abstract class IBars implements Iterable<CBar> {
|
|
49
|
-
readonly [key: number]: CBar;
|
|
50
|
-
[Symbol.iterator](): Iterator<CBar, any, undefined>;
|
|
51
|
-
readonly Tf: TF;
|
|
52
|
-
constructor(tf: TF);
|
|
53
|
-
abstract get data(): readonly CBar[];
|
|
54
|
-
abstract readonly Mutable: boolean;
|
|
55
|
-
get Immutable(): boolean;
|
|
56
|
-
toImmutable(): IBarsImmutable;
|
|
57
|
-
get count(): number;
|
|
58
|
-
get length(): number;
|
|
59
|
-
get last(): CBar | undefined;
|
|
60
|
-
backwardBar(i: number): CBar;
|
|
61
|
-
_getBar(i: number, prop: string): CBar;
|
|
62
|
-
at(i: number): CBar | undefined;
|
|
63
|
-
time(i: number): const_Date;
|
|
64
|
-
open(i: number): number;
|
|
65
|
-
high(i: number): number;
|
|
66
|
-
low(i: number): number;
|
|
67
|
-
close(i: number): number;
|
|
68
|
-
volume(i: number): number;
|
|
69
|
-
tickVolume(i: number): number;
|
|
70
|
-
closeTime(i: number): const_Date;
|
|
71
|
-
get firstTime(): const_Date | null;
|
|
72
|
-
get lastTime(): const_Date | null;
|
|
73
|
-
get lastCloseTime(): const_Date | null;
|
|
74
|
-
abstract get tickSize(): number;
|
|
75
|
-
Values<T>(getter: (bar: CBar) => T): lib.VirtualItems<T>;
|
|
76
|
-
get times(): lib.VirtualItems<const_Date>;
|
|
77
|
-
get opens(): lib.VirtualItems<number>;
|
|
78
|
-
get highs(): lib.VirtualItems<number>;
|
|
79
|
-
get lows(): lib.VirtualItems<number>;
|
|
80
|
-
get closes(): lib.VirtualItems<number>;
|
|
81
|
-
get volumes(): lib.VirtualItems<number>;
|
|
82
|
-
entries(): IterableIterator<[number, CBar]>;
|
|
83
|
-
indexOf(time: const_Date, match?: SearchMatchMode): number;
|
|
84
|
-
indexOfLessOrEqual(time: const_Date): number;
|
|
85
|
-
concat(newBars: readonly CBar[] | CBar): CBars | null;
|
|
86
|
-
slice(startIndex: number, stopIndex?: number): CBars;
|
|
87
|
-
sliceMutable(startIndex: number, stopIndex?: number): CBarsMutable;
|
|
88
|
-
sliceByTime(startTime: const_Date | null, lastTime?: const_Date | null): CBars;
|
|
89
|
-
range(timeStart?: const_Date, timeEnd?: const_Date): Generator<CBar, void, unknown>;
|
|
90
|
-
getArray(startTime?: const_Date | null, lastTime?: const_Date | null): CBar[] | null;
|
|
91
|
-
toBars(tf: TF, endDayTime_s?: number): CBarsMutableBase;
|
|
92
|
-
toBarsImmutable(tf: TF, endDayTime_s?: number): IBarsImmutable;
|
|
93
|
-
toBarsArray(dstTf: TF, endDayTime_s?: number): CBar[];
|
|
94
|
-
_getHighestHigh(i0: number, i1: number): number;
|
|
95
|
-
_getLowestLow(i0: number, i1: number): number;
|
|
96
|
-
getBest(comparer: (prevBar: CBar, newBar: CBar) => boolean, iFirst?: number | undefined, iLast?: number | undefined): undefined[] | (number | CBar)[];
|
|
97
|
-
getFirstHighest(iFirst: number | undefined, iLast: number | undefined): undefined[] | (number | CBar)[];
|
|
98
|
-
getFirstLowest(iFirst: number | undefined, iLast: number | undefined): undefined[] | (number | CBar)[];
|
|
99
|
-
getSumVolume(i0: number, i1: number): number;
|
|
100
|
-
getSumTickVolume(i0: number, i1: number): number;
|
|
101
|
-
}
|
|
102
|
-
export interface IBarsExt extends IBars {
|
|
103
|
-
readonly lastBarClosed: boolean;
|
|
104
|
-
readonly barInfo: (i: number) => BarInfo;
|
|
105
|
-
}
|
|
106
|
-
export declare abstract class CBarsBase extends IBars {
|
|
107
|
-
protected _data: readonly CBar[];
|
|
108
|
-
protected _ticksize?: number;
|
|
109
|
-
get _tickSize(): number | undefined;
|
|
110
|
-
get data(): readonly CBar[];
|
|
111
|
-
get tickSize(): number;
|
|
112
|
-
protected _Add(bars: readonly CBar[]): void;
|
|
113
|
-
constructor(tf: TF, bars: Iterable<CBar>, tickSize?: number);
|
|
114
|
-
static fromParsedJSON(data: ParsedUrlQueryInputMy<IBars>): CBars;
|
|
115
|
-
}
|
|
116
|
-
export type IBarsImmutable = IBars & {
|
|
117
|
-
readonly Mutable: false;
|
|
118
|
-
};
|
|
119
|
-
export declare class CBars extends CBarsBase implements IBarsImmutable {
|
|
120
|
-
constructor(tf: TF, bars: readonly CBar[], tickSize?: number);
|
|
121
|
-
readonly Mutable = false;
|
|
122
|
-
static createCopy(bars: IBars): CBars;
|
|
123
|
-
static createCopyExt(bars: IBars, lastBarClosed: boolean): IBarsExt;
|
|
124
|
-
static createBarInfo(bars: IBarsExt, i: number): BarInfo;
|
|
125
|
-
}
|
|
126
|
-
export declare abstract class CBarsMutableBase extends CBarsBase {
|
|
127
|
-
private _tickSizeAuto;
|
|
128
|
-
get data(): CBar[];
|
|
129
|
-
constructor(tf: TF, bars?: readonly CBar[], tickSize?: number);
|
|
130
|
-
Add(Bars: readonly CBar[] | CBar): void;
|
|
131
|
-
push(bars: readonly CBar[] | CBar): void;
|
|
132
|
-
updateLast(bar: CBar): void;
|
|
133
|
-
AddTick(tick: ITick): boolean;
|
|
134
|
-
AddTicks(ticks: readonly ITick[]): boolean;
|
|
135
|
-
}
|
|
136
|
-
export declare class CBarsMutable extends CBarsMutableBase {
|
|
137
|
-
readonly Mutable = true;
|
|
138
|
-
}
|
|
139
|
-
export declare class CBarsMutableExt extends CBarsMutable implements IBarsExt {
|
|
140
|
-
lastBarClosed: boolean;
|
|
141
|
-
readonly barInfo: (i: number) => BarInfo;
|
|
142
|
-
}
|
|
143
|
-
export declare function CreateRandomBars(tf: TF, startTime: const_Date, endTime: const_Date, startPrice?: number, volatility?: number | `${number}%`, ticksize?: number): CBars;
|
|
144
|
-
export declare function CreateRandomBars(tf: TF, startTime: const_Date, barsCount: number, startPrice?: number, volatility?: number | `${number}%`, ticksize?: number): CBars;
|
|
145
|
-
export type TimeValue<T> = {
|
|
146
|
-
readonly time: const_Date;
|
|
147
|
-
readonly value: T;
|
|
148
|
-
};
|
|
149
|
-
export interface ITimeseries<T = number> extends IItems<Readonly<TimeValue<T>>> {
|
|
150
|
-
time(i: number): const_Date;
|
|
151
|
-
value(i: number): T;
|
|
152
|
-
readonly times: IItems<const_Date>;
|
|
153
|
-
readonly values: IItems<T>;
|
|
154
|
-
indexOf(time: const_Date, match?: SearchMatchMode): number;
|
|
155
|
-
}
|
|
156
|
-
export declare abstract class CTimeSeriesBase<T = number> implements ITimeseries<T> {
|
|
157
|
-
abstract get points(): readonly TimeValue<T>[];
|
|
158
|
-
abstract get name(): string | undefined;
|
|
159
|
-
time(i: number): const_Date;
|
|
160
|
-
value(i: number): T;
|
|
161
|
-
get last(): TimeValue<T> | undefined;
|
|
162
|
-
get times(): IItems<const_Date>;
|
|
163
|
-
get values(): IItems<T>;
|
|
164
|
-
get length(): number;
|
|
165
|
-
indexOf(time: const_Date, match?: SearchMatchMode): number;
|
|
166
|
-
protected constructor();
|
|
167
|
-
[Symbol.iterator](): IterableIterator<TimeValue<T>>;
|
|
168
|
-
readonly [key: number]: Readonly<TimeValue<T>>;
|
|
169
|
-
}
|
|
170
|
-
export declare class CTimeSeries<T = number> extends CTimeSeriesBase<T> {
|
|
171
|
-
points: TimeValue<T>[];
|
|
172
|
-
name: string | undefined;
|
|
173
|
-
constructor(name?: string, points?: readonly TimeValue<T>[]);
|
|
174
|
-
static fromParsedJSON<T extends never>(data: ParsedUrlQueryInputMy<CTimeSeries<T>>): CTimeSeries<ParsedUrlQueryInputMy<T>>;
|
|
175
|
-
static fromParsedJSON<T extends null | undefined>(data: T): T;
|
|
176
|
-
write(stream: ByteStreamW, valueWriter: ((stream: ByteStreamW, value: T) => boolean | void)): boolean;
|
|
177
|
-
write(stream: ByteStreamW, valueType: T extends number ? NumericTypes | Nullable<NumericTypes> : never): boolean;
|
|
178
|
-
static read<T extends NumericTypes | Nullable<NumericTypes>>(stream: ByteStreamR, type: T): T extends NumericTypes ? CTimeSeries<number> : CTimeSeries<number | null>;
|
|
179
|
-
static read<T>(stream: ByteStreamR, valueGetter: (stream: ByteStreamR) => T): CTimeSeries<T>;
|
|
180
|
-
}
|
|
181
|
-
export type CTimeSeriesReadonly<T> = ReadonlyFull<CTimeSeries<T>>;
|
|
182
|
-
export declare function findBarsShallow(srcBars: readonly CBar[], barsToFind: readonly CBar[]): number;
|
package/lib/src/Exchange/Bars.js
DELETED
|
@@ -1,454 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.findBarsShallow = exports.CTimeSeries = exports.CTimeSeriesBase = exports.CreateRandomBars = exports.CBarsMutableExt = exports.CBarsMutable = exports.CBarsMutableBase = exports.CBars = exports.CBarsBase = exports.IBars = exports.CTick = exports.CBar = exports.CBarBase = exports.OHLC = void 0;
|
|
18
|
-
const lib = require("../Common/Common");
|
|
19
|
-
const Common_1 = require("../Common/Common");
|
|
20
|
-
const Time_1 = require("../Common/Time");
|
|
21
|
-
__exportStar(require("../Common/Time"), exports);
|
|
22
|
-
class OHLC {
|
|
23
|
-
open;
|
|
24
|
-
high;
|
|
25
|
-
low;
|
|
26
|
-
close;
|
|
27
|
-
constructor(open, high, low, close) { return Object.assign(this, { open, high, low, close }); }
|
|
28
|
-
}
|
|
29
|
-
exports.OHLC = OHLC;
|
|
30
|
-
class CBarBase {
|
|
31
|
-
time;
|
|
32
|
-
open;
|
|
33
|
-
high;
|
|
34
|
-
low;
|
|
35
|
-
close;
|
|
36
|
-
volume;
|
|
37
|
-
tickVolume;
|
|
38
|
-
constructor(timeOrBar, open = 0, high = 0, low = 0, close = 0, volume = 0, tickVolume = 0) {
|
|
39
|
-
function isDate(obj) { return obj instanceof Date; }
|
|
40
|
-
if (isDate(timeOrBar)) {
|
|
41
|
-
this.time = timeOrBar;
|
|
42
|
-
this.open = open;
|
|
43
|
-
this.high = high;
|
|
44
|
-
this.low = low;
|
|
45
|
-
this.close = close;
|
|
46
|
-
this.volume = volume;
|
|
47
|
-
this.tickVolume = tickVolume;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
let b = timeOrBar;
|
|
51
|
-
this.time = b.time;
|
|
52
|
-
this.open = b.open;
|
|
53
|
-
this.high = b.high;
|
|
54
|
-
this.low = b.low;
|
|
55
|
-
this.close = b.close;
|
|
56
|
-
this.volume = b.volume;
|
|
57
|
-
this.tickVolume = b.tickVolume;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.CBarBase = CBarBase;
|
|
62
|
-
class CBar extends CBarBase {
|
|
63
|
-
static new(time, ohlc, volume = 0, tickVolume = 0) {
|
|
64
|
-
return new CBar(time, ohlc.open, ohlc.high, ohlc.low, ohlc.close, volume, tickVolume);
|
|
65
|
-
}
|
|
66
|
-
static fromParsedJSON(data) { return new CBar(new Date(data.time), data.open, data.high, data.low, data.close, data.volume, data.tickVolume ?? 0); }
|
|
67
|
-
}
|
|
68
|
-
exports.CBar = CBar;
|
|
69
|
-
class CTick {
|
|
70
|
-
time;
|
|
71
|
-
price;
|
|
72
|
-
volume;
|
|
73
|
-
constructor(time, price, volume) { this.time = time; this.price = price; this.volume = volume; }
|
|
74
|
-
;
|
|
75
|
-
}
|
|
76
|
-
exports.CTick = CTick;
|
|
77
|
-
function getDraftTickSize(bars) { return bars instanceof CBarsBase ? bars._tickSize : bars.tickSize; }
|
|
78
|
-
class IBars {
|
|
79
|
-
[Symbol.iterator]() { return this.data[Symbol.iterator](); }
|
|
80
|
-
Tf;
|
|
81
|
-
constructor(tf) {
|
|
82
|
-
this.Tf = tf;
|
|
83
|
-
console.assert(tf.msec <= Time_1.TF.W1.msec);
|
|
84
|
-
return lib.CreateArrayProxy(this, (i) => this.data[i]);
|
|
85
|
-
}
|
|
86
|
-
get Immutable() { return !this.Mutable; }
|
|
87
|
-
toImmutable() { return this.Mutable ? new CBars(this.Tf, this.data, getDraftTickSize(this)) : this; }
|
|
88
|
-
get count() { return this.data?.length ?? 0; }
|
|
89
|
-
get length() { return this.count; }
|
|
90
|
-
get last() { return this.count > 0 ? this.data[this.count - 1] : undefined; }
|
|
91
|
-
backwardBar(i) { return this.data[this.length - 1 - i]; }
|
|
92
|
-
_getBar(i, prop) { return this.data[i] ?? (() => { console.trace(); throw ("Wrong bar index: i=" + i + ", barsTotal=" + this.count + ", property: " + prop); })(); }
|
|
93
|
-
at(i) { return this.data.at(i); }
|
|
94
|
-
time(i) { return this._getBar(i, "time").time; }
|
|
95
|
-
open(i) { return this._getBar(i, "open").open; }
|
|
96
|
-
high(i) { return this._getBar(i, "high").high; }
|
|
97
|
-
low(i) { return this._getBar(i, "low").low; }
|
|
98
|
-
close(i) { return this._getBar(i, "close").close; }
|
|
99
|
-
volume(i) { return this._getBar(i, "volume").volume; }
|
|
100
|
-
tickVolume(i) { return this._getBar(i, "tickVolume").tickVolume; }
|
|
101
|
-
closeTime(i) { return Time_1.Period.EndTime(this.Tf, this.time(i)); }
|
|
102
|
-
get firstTime() { return this.count > 0 ? this.data[0].time : null; }
|
|
103
|
-
get lastTime() { return this.count > 0 ? this.data[this.count - 1].time : null; }
|
|
104
|
-
get lastCloseTime() { return this.count > 0 ? this.closeTime(this.count - 1) : null; }
|
|
105
|
-
Values(getter) { return new Common_1.VirtualItems((i) => getter(this.data[i]), () => this.data.length); }
|
|
106
|
-
get times() { return this.Values((bar) => bar.time); }
|
|
107
|
-
get opens() { return this.Values((bar) => bar.open); }
|
|
108
|
-
get highs() { return this.Values((bar) => bar.high); }
|
|
109
|
-
get lows() { return this.Values((bar) => bar.low); }
|
|
110
|
-
get closes() { return this.Values((bar) => bar.close); }
|
|
111
|
-
get volumes() { return this.Values((bar) => bar.volume); }
|
|
112
|
-
entries() { return this.data.entries(); }
|
|
113
|
-
indexOf(time, match) {
|
|
114
|
-
time = Time_1.Period.StartTime(this.Tf, time);
|
|
115
|
-
return lib.BSearch(this.data, time, (bar, time) => bar.time.valueOf() - time.valueOf(), match ? match : Common_1.BSearch.EQUAL);
|
|
116
|
-
}
|
|
117
|
-
indexOfLessOrEqual(time) { return this.indexOf(time, "lessOrEqual"); }
|
|
118
|
-
concat(newBars) {
|
|
119
|
-
let bars = newBars instanceof Array ? newBars : [newBars];
|
|
120
|
-
let time = bars && bars.length > 0 && this.count > 0 ? bars[0].time : null;
|
|
121
|
-
if (time && time <= this.lastTime) {
|
|
122
|
-
console.error("Wrong bar start time: " + time.toString() + " <= " + this.lastTime.toString());
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
return new CBars(this.Tf, this.data.concat(bars), this.tickSize);
|
|
126
|
-
}
|
|
127
|
-
slice(startIndex, stopIndex) { let result = this.data.slice(startIndex, stopIndex); return new CBars(this.Tf, result, this.tickSize); }
|
|
128
|
-
sliceMutable(startIndex, stopIndex) { let result = this.data.slice(startIndex, stopIndex); return new CBarsMutable(this.Tf, result, this.tickSize); }
|
|
129
|
-
sliceByTime(startTime, lastTime) {
|
|
130
|
-
let arr = this.getArray(startTime, lastTime);
|
|
131
|
-
return new CBars(this.Tf, arr ?? [], this.tickSize);
|
|
132
|
-
}
|
|
133
|
-
*range(timeStart, timeEnd) {
|
|
134
|
-
if (this.length == 0)
|
|
135
|
-
return;
|
|
136
|
-
let ibar = timeStart ? this.indexOf(timeStart, "greatOrEqual") : 0;
|
|
137
|
-
timeEnd ??= this.lastTime;
|
|
138
|
-
for (let i = ibar; this.data[i].time <= timeEnd; i++)
|
|
139
|
-
yield this.data[i];
|
|
140
|
-
}
|
|
141
|
-
getArray(startTime, lastTime) {
|
|
142
|
-
let istart = startTime ? this.indexOf(startTime, Common_1.BSearch.GREAT_OR_EQUAL) : 0;
|
|
143
|
-
let ilast = lastTime ? this.indexOf(lastTime, Common_1.BSearch.LESS_OR_EQUAL) : this.data.length - 1;
|
|
144
|
-
if (istart == -1 || istart > ilast)
|
|
145
|
-
return null;
|
|
146
|
-
return this.data.slice(istart, ilast + 1);
|
|
147
|
-
}
|
|
148
|
-
toBars(tf, endDayTime_s) {
|
|
149
|
-
let bars = this.toBarsArray(tf, endDayTime_s);
|
|
150
|
-
return new CBarsMutable(tf, bars, this instanceof CBarsBase ? this._tickSize : this.tickSize);
|
|
151
|
-
}
|
|
152
|
-
toBarsImmutable(tf, endDayTime_s) {
|
|
153
|
-
if (tf == this.Tf && endDayTime_s == null)
|
|
154
|
-
return this.toImmutable();
|
|
155
|
-
return Object.assign(this.toBars(tf, endDayTime_s), { Mutable: false });
|
|
156
|
-
}
|
|
157
|
-
toBarsArray(dstTf, endDayTime_s) {
|
|
158
|
-
const src = this;
|
|
159
|
-
if (src.Tf == dstTf && !endDayTime_s) {
|
|
160
|
-
return [...src.data];
|
|
161
|
-
}
|
|
162
|
-
console.assert(dstTf.sec > 0);
|
|
163
|
-
let count = src.count;
|
|
164
|
-
let dst = new Array(count);
|
|
165
|
-
let mainTime = count > 0 ? src.time(0) : new Date(0);
|
|
166
|
-
let period = new Time_1.Period(dstTf);
|
|
167
|
-
let nextPeriodTime = period.span(mainTime).next().startTime;
|
|
168
|
-
let istart = 0;
|
|
169
|
-
let ilast = 0;
|
|
170
|
-
let n = 0;
|
|
171
|
-
for (let i = 1; i <= count; i++) {
|
|
172
|
-
let bartime = i < count ? src.time(i) : new Date(2100, 1, 1);
|
|
173
|
-
if (endDayTime_s && bartime.valueOf() % Time_1.D1_MS >= endDayTime_s * 1000 % Time_1.D1_MS)
|
|
174
|
-
continue;
|
|
175
|
-
if (bartime >= nextPeriodTime) {
|
|
176
|
-
let close = src.close(ilast);
|
|
177
|
-
let time = period.span(mainTime).startTime;
|
|
178
|
-
let high = src._getHighestHigh(istart, ilast);
|
|
179
|
-
let low = src._getLowestLow(istart, ilast);
|
|
180
|
-
let open = src.open(istart);
|
|
181
|
-
let volume = src.getSumVolume(istart, ilast);
|
|
182
|
-
let tickVolume = src.getSumTickVolume(istart, ilast);
|
|
183
|
-
dst[n] = new CBar(time, open, high, low, close, volume, tickVolume);
|
|
184
|
-
mainTime = bartime;
|
|
185
|
-
istart = i;
|
|
186
|
-
n++;
|
|
187
|
-
nextPeriodTime = period.span(mainTime).next().startTime;
|
|
188
|
-
}
|
|
189
|
-
ilast = i;
|
|
190
|
-
}
|
|
191
|
-
dst.length = n;
|
|
192
|
-
return dst;
|
|
193
|
-
}
|
|
194
|
-
_getHighestHigh(i0, i1) { let a = -Number.MAX_VALUE; for (let i = i0; i <= i1; i++)
|
|
195
|
-
a = Math.max(a, this.high(i)); return a; }
|
|
196
|
-
_getLowestLow(i0, i1) { let a = Number.MAX_VALUE; for (let i = i0; i <= i1; i++)
|
|
197
|
-
a = Math.min(a, this.low(i)); return a; }
|
|
198
|
-
getBest(comparer, iFirst, iLast) {
|
|
199
|
-
iFirst ??= 0;
|
|
200
|
-
iLast ??= this.count - 1;
|
|
201
|
-
if (iFirst > iLast)
|
|
202
|
-
return [undefined, undefined];
|
|
203
|
-
let n = iFirst, bestBar = this.data[iFirst];
|
|
204
|
-
for (let i = iFirst + 1; i <= iLast; i++) {
|
|
205
|
-
let bar = this.data[i];
|
|
206
|
-
if (comparer(bestBar, bar) == true)
|
|
207
|
-
[n, bestBar] = [i, bar];
|
|
208
|
-
}
|
|
209
|
-
return [n, bestBar];
|
|
210
|
-
}
|
|
211
|
-
getFirstHighest(iFirst, iLast) { return this.getBest((old, current) => current.high > old.high, iFirst, iLast); }
|
|
212
|
-
getFirstLowest(iFirst, iLast) { return this.getBest((old, current) => current.low < old.low, iFirst, iLast); }
|
|
213
|
-
getSumVolume(i0, i1) { let sum = 0; for (let i = i0; i <= i1; i++)
|
|
214
|
-
sum += this.volume(i); return sum; }
|
|
215
|
-
getSumTickVolume(i0, i1) { let sum = 0; for (let i = i0; i <= i1; i++)
|
|
216
|
-
sum += this.tickVolume(i); return sum; }
|
|
217
|
-
}
|
|
218
|
-
exports.IBars = IBars;
|
|
219
|
-
class CBarsBase extends IBars {
|
|
220
|
-
_data;
|
|
221
|
-
_ticksize;
|
|
222
|
-
get _tickSize() { return this._ticksize; }
|
|
223
|
-
get data() { return this._data; }
|
|
224
|
-
get tickSize() { return this._ticksize ??= lib.MaxCommonDivisorOnArray(this.closes); }
|
|
225
|
-
_Add(bars) { this._data = this._data.concat(bars); }
|
|
226
|
-
constructor(tf, bars, tickSize) {
|
|
227
|
-
super(tf);
|
|
228
|
-
this._ticksize = tickSize ? tickSize : 0;
|
|
229
|
-
if (bars == null)
|
|
230
|
-
bars = [];
|
|
231
|
-
if (bars instanceof IBars) {
|
|
232
|
-
if (tf != bars.Tf)
|
|
233
|
-
this._data = bars.toBarsArray(tf) ?? [];
|
|
234
|
-
else
|
|
235
|
-
this._data = !bars.Mutable ? bars.data : [...bars];
|
|
236
|
-
}
|
|
237
|
-
else
|
|
238
|
-
this._data = [...bars];
|
|
239
|
-
}
|
|
240
|
-
static fromParsedJSON(data) {
|
|
241
|
-
let d = data;
|
|
242
|
-
let tf = Time_1.TF.fromSec(d.Tf.sec);
|
|
243
|
-
if (!tf) {
|
|
244
|
-
console.assert(tf != null);
|
|
245
|
-
throw ("wrong TF");
|
|
246
|
-
}
|
|
247
|
-
let obj = new CBars(tf, d._data.map((el) => CBar.fromParsedJSON(el)));
|
|
248
|
-
return obj;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
exports.CBarsBase = CBarsBase;
|
|
252
|
-
class CBars extends CBarsBase {
|
|
253
|
-
constructor(tf, bars, tickSize) { super(tf, bars ?? [], tickSize); }
|
|
254
|
-
Mutable = false;
|
|
255
|
-
static createCopy(bars) { return new CBars(bars.Tf, bars.data, bars.tickSize); }
|
|
256
|
-
static createCopyExt(bars, lastBarClosed) {
|
|
257
|
-
let obj = Object.assign(CBars.createCopy(bars), {
|
|
258
|
-
lastBarClosed,
|
|
259
|
-
barInfo: (i) => CBars.createBarInfo(obj, i)
|
|
260
|
-
});
|
|
261
|
-
return obj;
|
|
262
|
-
}
|
|
263
|
-
static createBarInfo(bars, i) {
|
|
264
|
-
return {
|
|
265
|
-
bar: bars.data[i] ?? (() => { console.trace(); throw ("Wrong bar index: i=" + i + " barsTotal=" + bars.count); })(),
|
|
266
|
-
index: i,
|
|
267
|
-
closed: bars.lastBarClosed || i < bars.count - 1,
|
|
268
|
-
getAllBars: () => bars
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
exports.CBars = CBars;
|
|
273
|
-
let x = [];
|
|
274
|
-
for (let fff of x) { }
|
|
275
|
-
class CBarsMutableBase extends CBarsBase {
|
|
276
|
-
_tickSizeAuto;
|
|
277
|
-
get data() { return this._data; }
|
|
278
|
-
constructor(tf, bars, tickSize) { super(tf, bars ?? [], tickSize); this._tickSizeAuto = !tickSize; }
|
|
279
|
-
Add(Bars) {
|
|
280
|
-
let bars = Bars instanceof Array ? Bars : [Bars];
|
|
281
|
-
if (!bars || bars.length == 0)
|
|
282
|
-
return;
|
|
283
|
-
let time = bars[0].time;
|
|
284
|
-
if (this.count > 0 && time <= this.lastTime)
|
|
285
|
-
throw "Wrong bar time: " + time + " <= " + this.lastTime;
|
|
286
|
-
if (!this.data)
|
|
287
|
-
this._data = [];
|
|
288
|
-
for (let bar of bars)
|
|
289
|
-
Object.freeze(bar);
|
|
290
|
-
this.data.push(...bars);
|
|
291
|
-
if (this._tickSizeAuto)
|
|
292
|
-
this._ticksize = 0;
|
|
293
|
-
}
|
|
294
|
-
push(bars) { this.Add(bars); }
|
|
295
|
-
updateLast(bar) {
|
|
296
|
-
if (this.lastTime)
|
|
297
|
-
if (bar.time.valueOf() == this.lastTime.valueOf()) {
|
|
298
|
-
this.data[this.length - 1] = { ...bar };
|
|
299
|
-
if (this._tickSizeAuto)
|
|
300
|
-
this._ticksize = 0;
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
else if (bar.time < this.lastTime)
|
|
304
|
-
throw "Wrong bar time: " + bar.time + " < " + this.lastTime;
|
|
305
|
-
this.push(bar);
|
|
306
|
-
}
|
|
307
|
-
AddTick(tick) {
|
|
308
|
-
if (!tick)
|
|
309
|
-
return false;
|
|
310
|
-
if (this.count > 0 && tick.time < this.lastTime) {
|
|
311
|
-
console.error("Wrong tick time: " + tick.time + " < " + this.lastTime);
|
|
312
|
-
return false;
|
|
313
|
-
}
|
|
314
|
-
let barTime = Time_1.Period.StartTime(this.Tf, tick.time);
|
|
315
|
-
let bar;
|
|
316
|
-
let price = tick.price;
|
|
317
|
-
let i = this.count;
|
|
318
|
-
if (this.count > 0 && barTime.valueOf() == this.lastTime.valueOf()) {
|
|
319
|
-
bar = this.last;
|
|
320
|
-
i--;
|
|
321
|
-
bar = new CBar(barTime, bar.open, Math.max(bar.high, price), Math.min(bar.low, price), price, bar.volume + tick.volume, bar.tickVolume + 1);
|
|
322
|
-
}
|
|
323
|
-
else
|
|
324
|
-
bar = new CBar(barTime, price, price, price, price, tick.volume, 1);
|
|
325
|
-
if (!this._data)
|
|
326
|
-
this._data = [];
|
|
327
|
-
Object.freeze(bar);
|
|
328
|
-
this.data[i] = bar;
|
|
329
|
-
return true;
|
|
330
|
-
}
|
|
331
|
-
AddTicks(ticks) { for (let tick of ticks)
|
|
332
|
-
if (!this.AddTick(tick))
|
|
333
|
-
return false; return true; }
|
|
334
|
-
}
|
|
335
|
-
exports.CBarsMutableBase = CBarsMutableBase;
|
|
336
|
-
class CBarsMutable extends CBarsMutableBase {
|
|
337
|
-
Mutable = true;
|
|
338
|
-
}
|
|
339
|
-
exports.CBarsMutable = CBarsMutable;
|
|
340
|
-
class CBarsMutableExt extends CBarsMutable {
|
|
341
|
-
lastBarClosed = true;
|
|
342
|
-
barInfo = (i) => CBars.createBarInfo(this, i);
|
|
343
|
-
}
|
|
344
|
-
exports.CBarsMutableExt = CBarsMutableExt;
|
|
345
|
-
function CreateRandomBars(tf, startTime, endTimeOrCount, startPrice = 100, volatility = "1%", tickSize) {
|
|
346
|
-
if (!tf || tf.msec == 0)
|
|
347
|
-
return null;
|
|
348
|
-
console.log("Creating bars with parameters: ", ...([...arguments].map(arg => arg instanceof Time_1.TF ? arg.name : arg)));
|
|
349
|
-
const tickSizeNum = tickSize ?? 10 ** Math.min(Math.round(Math.log10(startPrice) - 4), 0);
|
|
350
|
-
let period = new Time_1.Period(tf);
|
|
351
|
-
let count;
|
|
352
|
-
if (typeof endTimeOrCount == "number")
|
|
353
|
-
count = endTimeOrCount;
|
|
354
|
-
else
|
|
355
|
-
count = period.IndexFromTime(endTimeOrCount) - period.IndexFromTime(startTime) + 1;
|
|
356
|
-
console.log(count);
|
|
357
|
-
if (count < 0)
|
|
358
|
-
return null;
|
|
359
|
-
let bars = new Array(count);
|
|
360
|
-
let price = startPrice;
|
|
361
|
-
let periodSpan = period.span(startTime);
|
|
362
|
-
let digits = (0, Common_1.GetDblPrecision)(tickSizeNum);
|
|
363
|
-
function norm(value) { return (0, Common_1.NormalizeDouble)(Math.round(value / tickSizeNum) * tickSizeNum, digits); }
|
|
364
|
-
const [volatFactor, volatNum] = typeof volatility == "string" ? [Number(volatility.slice(0, -1)) / 100, undefined] : [undefined, volatility];
|
|
365
|
-
for (let i = 0; i < count; i++) {
|
|
366
|
-
const volat = volatNum ?? volatFactor * price;
|
|
367
|
-
let open = norm(price + (Math.random() * 2 - 1) * volat / 10);
|
|
368
|
-
let high = norm(open + Math.random() * volat);
|
|
369
|
-
let low = norm(open - Math.random() * volat);
|
|
370
|
-
let close = norm(low + Math.random() * (high - low));
|
|
371
|
-
let volume = tf.msec;
|
|
372
|
-
let time = periodSpan.startTime;
|
|
373
|
-
let bar = new CBar(time, open, high, low, close, volume, volume);
|
|
374
|
-
bars[i] = bar;
|
|
375
|
-
periodSpan = periodSpan.next();
|
|
376
|
-
price = close;
|
|
377
|
-
}
|
|
378
|
-
return new CBars(tf, bars);
|
|
379
|
-
}
|
|
380
|
-
exports.CreateRandomBars = CreateRandomBars;
|
|
381
|
-
class CTimeSeriesBase {
|
|
382
|
-
time(i) { return this.points[i]?.time ?? (() => { throw "Wrong index i=" + i + " of " + this.length; })(); }
|
|
383
|
-
value(i) { return this.points[i]?.value ?? (() => { throw "Wrong index i=" + i + " of " + this.length; })(); }
|
|
384
|
-
get last() { return this.points.at(-1); }
|
|
385
|
-
get times() { return new lib.VirtualItems((i) => this.time(i), () => this.length); }
|
|
386
|
-
get values() { return new lib.VirtualItems((i) => this.value(i), () => this.length); }
|
|
387
|
-
get length() { return this.points.length; }
|
|
388
|
-
indexOf(time, match) { return (0, Common_1.BSearch)(this.times, time, match); }
|
|
389
|
-
constructor() {
|
|
390
|
-
return (0, Common_1.CreateArrayProxy)(this, (i) => this.points[i]);
|
|
391
|
-
}
|
|
392
|
-
[Symbol.iterator]() { return this.points[Symbol.iterator](); }
|
|
393
|
-
}
|
|
394
|
-
exports.CTimeSeriesBase = CTimeSeriesBase;
|
|
395
|
-
class CTimeSeries extends CTimeSeriesBase {
|
|
396
|
-
points = [];
|
|
397
|
-
name;
|
|
398
|
-
constructor(name, points) {
|
|
399
|
-
super();
|
|
400
|
-
this.name = name;
|
|
401
|
-
this.points = points ? [...points] : [];
|
|
402
|
-
}
|
|
403
|
-
static fromParsedJSON(data) {
|
|
404
|
-
if (!data)
|
|
405
|
-
return data;
|
|
406
|
-
let obj = new CTimeSeries();
|
|
407
|
-
console.assert(data.points != null);
|
|
408
|
-
obj.name = data.name;
|
|
409
|
-
obj.points = data.points.map((pnt) => { return { time: new Date(pnt.time), value: pnt.value }; });
|
|
410
|
-
return obj;
|
|
411
|
-
}
|
|
412
|
-
write(stream, arg) {
|
|
413
|
-
let valueWriter = (typeof arg == "function") ? arg : (stream, value) => stream.pushNumber(value, arg);
|
|
414
|
-
function _writePoint(stream, pair) { return stream.pushInt64(pair.time.valueOf()) != null && valueWriter(stream, pair.value) != false; }
|
|
415
|
-
return stream.pushUnicode(this.name ?? null).pushArrayByFunc(this.points, _writePoint) != null;
|
|
416
|
-
}
|
|
417
|
-
static read(stream, arg) {
|
|
418
|
-
let valueGetter = (typeof arg == "function") ? arg : (stream) => stream.readNumber(arg);
|
|
419
|
-
let name = stream.readUnicode();
|
|
420
|
-
let points = stream.readArray((stream) => ({ time: new Date(stream.readUint64()), value: valueGetter(stream) }));
|
|
421
|
-
return new CTimeSeries(name ?? undefined, points);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
exports.CTimeSeries = CTimeSeries;
|
|
425
|
-
function _findBars(srcBars, barsToFind, mode) {
|
|
426
|
-
let len = barsToFind.length;
|
|
427
|
-
if (srcBars.length < len || len == -1)
|
|
428
|
-
return -1;
|
|
429
|
-
let start = 0;
|
|
430
|
-
let end = len - 1;
|
|
431
|
-
let iStart = (0, Common_1.BSearch)(srcBars, barsToFind[start].time, (bar, time) => bar.time.valueOf() - time.valueOf());
|
|
432
|
-
let iEnd = (0, Common_1.BSearch)(srcBars, barsToFind[end].time, (bar, time) => bar.time.valueOf() - time.valueOf());
|
|
433
|
-
if (iStart < 0 || iEnd < 0 || iEnd - iStart + 1 != len)
|
|
434
|
-
return -1;
|
|
435
|
-
let delta = start - iStart;
|
|
436
|
-
if (mode == "deep") {
|
|
437
|
-
for (let i = iStart; i <= iEnd; i++)
|
|
438
|
-
if (!(0, Common_1.deepEqual)(srcBars[i], barsToFind[i + delta]))
|
|
439
|
-
return -1;
|
|
440
|
-
}
|
|
441
|
-
else
|
|
442
|
-
for (let i = iStart; i <= iEnd; i++)
|
|
443
|
-
if (srcBars[i] != barsToFind[i + delta])
|
|
444
|
-
return -1;
|
|
445
|
-
return iStart;
|
|
446
|
-
}
|
|
447
|
-
function findBarsDeep(srcBars, barsToFind) {
|
|
448
|
-
return _findBars(srcBars, barsToFind, "deep");
|
|
449
|
-
}
|
|
450
|
-
function findBarsShallow(srcBars, barsToFind) {
|
|
451
|
-
return _findBars(srcBars, barsToFind, "shallow");
|
|
452
|
-
}
|
|
453
|
-
exports.findBarsShallow = findBarsShallow;
|
|
454
|
-
//# sourceMappingURL=Bars.js.map
|