@tradecanvas/commons 1.19.1 → 1.20.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/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +437 -261
- package/dist/index.js.map +1 -1
- package/dist/market/index.d.ts +2 -2
- package/dist/market/index.d.ts.map +1 -1
- package/dist/market/presets.d.ts +53 -2
- package/dist/market/presets.d.ts.map +1 -1
- package/dist/market/types.d.ts +26 -2
- package/dist/market/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/market/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { MarketType, StockExchange, MarketConfig, TradingSession, MarketColorScheme, PriceLimitInfo } from './types.js';
|
|
2
|
-
export { VN_COLORS, HOSE_SESSIONS, HNX_SESSIONS, MARKET_HOSE, MARKET_HNX, MARKET_UPCOM, MARKET_CRYPTO, MARKET_NYSE, createVNTheme, computePriceLimits, getCurrentSession, } from './presets.js';
|
|
1
|
+
export type { MarketType, StockExchange, MarketConfig, PriceStepBand, TradingSession, MarketColorScheme, PriceLimitInfo, VN30FContract } from './types.js';
|
|
2
|
+
export { VN_COLORS, HOSE_SESSIONS, HNX_SESSIONS, UPCOM_SESSIONS, VN30F_SESSIONS, MARKET_HOSE, MARKET_HOSE_ETF, MARKET_HNX, MARKET_UPCOM, MARKET_VN30F, MARKET_CRYPTO, MARKET_NYSE, createVNTheme, priceStepAt, roundToPriceStep, computePriceLimits, scaleMarketPrices, getCurrentSession, vn30fLastTradingDay, vn30fContracts, } from './presets.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/market/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/market/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3J,OAAO,EACL,SAAS,EACT,aAAa,EACb,YAAY,EACZ,cAAc,EACd,cAAc,EACd,WAAW,EACX,eAAe,EACf,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,WAAW,EACX,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,GACf,MAAM,cAAc,CAAC"}
|
package/dist/market/presets.d.ts
CHANGED
|
@@ -1,18 +1,69 @@
|
|
|
1
|
-
import { MarketConfig, MarketColorScheme, TradingSession } from './types.js';
|
|
1
|
+
import { MarketConfig, MarketColorScheme, TradingSession, VN30FContract } from './types.js';
|
|
2
2
|
import { Theme } from '../types/theme.js';
|
|
3
|
+
/**
|
|
4
|
+
* Vietnamese price boards: green up, red down, purple at the ceiling (trần),
|
|
5
|
+
* cyan at the floor (sàn), yellow at the reference price (tham chiếu).
|
|
6
|
+
*/
|
|
3
7
|
export declare const VN_COLORS: MarketColorScheme;
|
|
4
8
|
export declare const HOSE_SESSIONS: TradingSession[];
|
|
5
9
|
export declare const HNX_SESSIONS: TradingSession[];
|
|
10
|
+
export declare const UPCOM_SESSIONS: TradingSession[];
|
|
11
|
+
export declare const VN30F_SESSIONS: TradingSession[];
|
|
6
12
|
export declare const MARKET_HOSE: MarketConfig;
|
|
13
|
+
/** HOSE ETFs and covered warrants: 10 dong at every price. */
|
|
14
|
+
export declare const MARKET_HOSE_ETF: MarketConfig;
|
|
7
15
|
export declare const MARKET_HNX: MarketConfig;
|
|
8
16
|
export declare const MARKET_UPCOM: MarketConfig;
|
|
17
|
+
/** VN30 index futures on HNX: index points, 0.1 a step, 100,000 dong a point. */
|
|
18
|
+
export declare const MARKET_VN30F: MarketConfig;
|
|
9
19
|
export declare const MARKET_CRYPTO: MarketConfig;
|
|
10
20
|
export declare const MARKET_NYSE: MarketConfig;
|
|
11
21
|
export declare function createVNTheme(base: Theme): Theme;
|
|
22
|
+
/**
|
|
23
|
+
* The price step at `price`: the band it falls in, else the market's
|
|
24
|
+
* `priceStep`; undefined when the market names no step.
|
|
25
|
+
*/
|
|
26
|
+
export declare function priceStepAt(price: number, config: MarketConfig): number | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* `price` on the step of its band: to the nearest step, or `'down'` / `'up'`.
|
|
29
|
+
* A market without a step leaves it as it is.
|
|
30
|
+
*/
|
|
31
|
+
export declare function roundToPriceStep(price: number, config: MarketConfig, mode?: 'nearest' | 'down' | 'up'): number;
|
|
32
|
+
/**
|
|
33
|
+
* The day's ceiling, floor and reference prices. With a price step, the
|
|
34
|
+
* ceiling rounds down and the floor up to a valid price; when one would land
|
|
35
|
+
* back on the reference it moves a step off it, and a reference of one step
|
|
36
|
+
* keeps the floor at the reference (the exchanges' rules).
|
|
37
|
+
*/
|
|
12
38
|
export declare function computePriceLimits(referencePrice: number, config: MarketConfig): {
|
|
13
39
|
ceiling: number;
|
|
14
40
|
floor: number;
|
|
15
41
|
reference: number;
|
|
16
42
|
} | null;
|
|
17
|
-
|
|
43
|
+
/**
|
|
44
|
+
* A copy of `config` for prices `factor` times larger (a power of ten):
|
|
45
|
+
* steps, bands, the reference price and the decimals follow; a contract's
|
|
46
|
+
* multiplier stays. `scaleMarketPrices(MARKET_HOSE, 1000)` reads prices in
|
|
47
|
+
* dong (25350) instead of thousands (25.35).
|
|
48
|
+
*/
|
|
49
|
+
export declare function scaleMarketPrices(config: MarketConfig, factor: number): MarketConfig;
|
|
50
|
+
/**
|
|
51
|
+
* The session `now` falls in: by the clock of `timeZone` (a market's
|
|
52
|
+
* `timeZone`), or of this computer without one. Null outside them all, and
|
|
53
|
+
* for a time zone it doesn't know. By the time of day only: weekends and
|
|
54
|
+
* holidays are yours to tell.
|
|
55
|
+
*/
|
|
56
|
+
export declare function getCurrentSession(sessions: TradingSession[], now?: number, timeZone?: string): TradingSession | null;
|
|
57
|
+
/**
|
|
58
|
+
* The last trading day of the VN30 futures contract of `month` (1–12): the
|
|
59
|
+
* third Thursday, or the trading day before it when that is a holiday
|
|
60
|
+
* (`isHoliday` gets `YYYY-MM-DD`). As `YYYY-MM-DD`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function vn30fLastTradingDay(year: number, month: number, isHoliday?: (day: string) => boolean): string;
|
|
63
|
+
/**
|
|
64
|
+
* The VN30 futures contracts listed at `now`: this month's (until its last
|
|
65
|
+
* trading day), the next month's, and the last months of the two quarters
|
|
66
|
+
* after that.
|
|
67
|
+
*/
|
|
68
|
+
export declare function vn30fContracts(now: number, isHoliday?: (day: string) => boolean): VN30FContract[];
|
|
18
69
|
//# sourceMappingURL=presets.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../../src/market/presets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../../src/market/presets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAiB,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAK/C;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,iBAOvB,CAAC;AAMF,eAAO,MAAM,aAAa,EAAE,cAAc,EAMzC,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,cAAc,EAMxC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,cAAc,EAI1C,CAAC;AAEF,eAAO,MAAM,cAA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AK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM,CAU7G;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,GAAG,aAAa,EAAE,CAoBjG"}
|
package/dist/market/types.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
export type MarketType = 'crypto' | 'stock' | 'forex';
|
|
1
|
+
export type MarketType = 'crypto' | 'stock' | 'forex' | 'futures';
|
|
2
2
|
export type StockExchange = 'HOSE' | 'HNX' | 'UPCOM' | 'NYSE' | 'NASDAQ' | string;
|
|
3
|
+
/** From `from` up to the next band, prices move in steps of `step`. */
|
|
4
|
+
export interface PriceStepBand {
|
|
5
|
+
from: number;
|
|
6
|
+
step: number;
|
|
7
|
+
}
|
|
3
8
|
export interface MarketConfig {
|
|
4
9
|
type: MarketType;
|
|
5
10
|
exchange?: StockExchange;
|
|
@@ -7,6 +12,15 @@ export interface MarketConfig {
|
|
|
7
12
|
pricePrecision?: number;
|
|
8
13
|
volumeUnit?: number;
|
|
9
14
|
priceStep?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Steps that depend on the price, lowest band first (HOSE: 10, 50 or 100
|
|
17
|
+
* dong). Prices below the first band use `priceStep`.
|
|
18
|
+
*/
|
|
19
|
+
priceSteps?: readonly PriceStepBand[];
|
|
20
|
+
/** The exchange's IANA time zone, which its session times are in. */
|
|
21
|
+
timeZone?: string;
|
|
22
|
+
/** Currency per point of a futures contract (VN30F: 100,000 dong). */
|
|
23
|
+
contractMultiplier?: number;
|
|
10
24
|
priceLimits?: {
|
|
11
25
|
enabled: boolean;
|
|
12
26
|
ceilingPercent?: number;
|
|
@@ -20,7 +34,8 @@ export interface TradingSession {
|
|
|
20
34
|
name: string;
|
|
21
35
|
startTime: string;
|
|
22
36
|
endTime: string;
|
|
23
|
-
|
|
37
|
+
/** `preOpen` / `preClose`: the opening and closing auctions; `postClose`: trading after the close. */
|
|
38
|
+
type: 'preOpen' | 'continuous' | 'preClose' | 'postClose' | 'closed';
|
|
24
39
|
}
|
|
25
40
|
export interface MarketColorScheme {
|
|
26
41
|
up: string;
|
|
@@ -35,4 +50,13 @@ export interface PriceLimitInfo {
|
|
|
35
50
|
floor: number;
|
|
36
51
|
reference: number;
|
|
37
52
|
}
|
|
53
|
+
/** One listed VN30 index futures contract. */
|
|
54
|
+
export interface VN30FContract {
|
|
55
|
+
/** `VN30F` with the year and month of expiry: `VN30F2611`. */
|
|
56
|
+
symbol: string;
|
|
57
|
+
year: number;
|
|
58
|
+
month: number;
|
|
59
|
+
/** Its last trading day, `YYYY-MM-DD`. */
|
|
60
|
+
lastTradingDay: string;
|
|
61
|
+
}
|
|
38
62
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/market/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/market/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;AAElE,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAElF,uEAAuE;AACvE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,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