@homaiohq/napi-quickfix 0.1.0 → 0.2.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/CMakeLists.txt +5 -1
- package/README.md +235 -18
- package/cpp/acceptor_wrap.cpp +253 -19
- package/cpp/acceptor_wrap.h +60 -1
- package/cpp/addon.cpp +10 -6
- package/cpp/application_bridge.cpp +114 -30
- package/cpp/application_bridge.h +57 -4
- package/cpp/data_dictionary_wrap.cpp +89 -3
- package/cpp/data_dictionary_wrap.h +27 -5
- package/cpp/engine_common.h +108 -0
- package/cpp/engine_workers.h +99 -18
- package/cpp/field_map_ops.h +492 -0
- package/cpp/group_wrap.cpp +221 -0
- package/cpp/group_wrap.h +76 -0
- package/cpp/initiator_wrap.cpp +262 -25
- package/cpp/initiator_wrap.h +37 -2
- package/cpp/message_wrap.cpp +171 -78
- package/cpp/message_wrap.h +47 -5
- package/cpp/session_op_gate.h +201 -0
- package/cpp/session_static.cpp +139 -12
- package/cpp/session_wrap.cpp +438 -0
- package/cpp/session_wrap.h +144 -0
- package/dist/cjs/acceptor.d.ts +0 -1
- package/dist/cjs/acceptor.js +0 -1
- package/dist/cjs/application.d.ts +0 -1
- package/dist/cjs/application.js +0 -1
- package/dist/cjs/data-dictionary.d.ts +21 -3
- package/dist/cjs/data-dictionary.js +32 -4
- package/dist/cjs/engine.d.ts +42 -4
- package/dist/cjs/engine.js +50 -5
- package/dist/cjs/enums.d.ts +48 -14
- package/dist/cjs/enums.js +20 -25
- package/dist/cjs/field-value.d.ts +12 -0
- package/dist/cjs/field-value.js +40 -0
- package/dist/cjs/generated/fields.d.ts +0 -1
- package/dist/cjs/generated/fields.js +0 -1
- package/dist/cjs/generated/values.d.ts +8548 -0
- package/dist/cjs/generated/values.js +8580 -0
- package/dist/cjs/group.d.ts +126 -0
- package/dist/cjs/group.js +185 -0
- package/dist/cjs/index.d.ts +26 -5
- package/dist/cjs/index.js +28 -28
- package/dist/cjs/initiator.d.ts +0 -1
- package/dist/cjs/initiator.js +0 -1
- package/dist/cjs/message.d.ts +129 -5
- package/dist/cjs/message.js +146 -9
- package/dist/cjs/native.d.ts +179 -17
- package/dist/cjs/native.js +0 -1
- package/dist/cjs/session-id.d.ts +12 -1
- package/dist/cjs/session-id.js +21 -1
- package/dist/cjs/session-settings.d.ts +0 -1
- package/dist/cjs/session-settings.js +0 -1
- package/dist/cjs/session.d.ts +213 -0
- package/dist/cjs/session.js +337 -0
- package/dist/esm/acceptor.d.ts +0 -1
- package/dist/esm/acceptor.js +0 -1
- package/dist/esm/application.d.ts +0 -1
- package/dist/esm/application.js +0 -1
- package/dist/esm/data-dictionary.d.ts +21 -3
- package/dist/esm/data-dictionary.js +32 -4
- package/dist/esm/engine.d.ts +42 -4
- package/dist/esm/engine.js +51 -6
- package/dist/esm/enums.d.ts +48 -14
- package/dist/esm/enums.js +14 -24
- package/dist/esm/field-value.d.ts +12 -0
- package/dist/esm/field-value.js +37 -0
- package/dist/esm/generated/fields.d.ts +0 -1
- package/dist/esm/generated/fields.js +0 -1
- package/dist/esm/generated/values.d.ts +8548 -0
- package/dist/esm/generated/values.js +8564 -0
- package/dist/esm/group.d.ts +126 -0
- package/dist/esm/group.js +181 -0
- package/dist/esm/index.d.ts +26 -5
- package/dist/esm/index.js +17 -26
- package/dist/esm/initiator.d.ts +0 -1
- package/dist/esm/initiator.js +0 -1
- package/dist/esm/message.d.ts +129 -5
- package/dist/esm/message.js +146 -9
- package/dist/esm/native.d.ts +179 -17
- package/dist/esm/native.js +0 -1
- package/dist/esm/session-id.d.ts +12 -1
- package/dist/esm/session-id.js +20 -1
- package/dist/esm/session-settings.d.ts +0 -1
- package/dist/esm/session-settings.js +0 -1
- package/dist/esm/session.d.ts +213 -0
- package/dist/esm/session.js +329 -0
- package/package.json +13 -1
- package/prebuilds/darwin-arm64/node.napi.node +0 -0
- package/prebuilds/darwin-x64/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/prebuilds/linux-x64/node.napi.musl.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/cpp/enums.cpp +0 -66
- package/dist/cjs/acceptor.d.ts.map +0 -1
- package/dist/cjs/acceptor.js.map +0 -1
- package/dist/cjs/application.d.ts.map +0 -1
- package/dist/cjs/application.js.map +0 -1
- package/dist/cjs/data-dictionary.d.ts.map +0 -1
- package/dist/cjs/data-dictionary.js.map +0 -1
- package/dist/cjs/engine.d.ts.map +0 -1
- package/dist/cjs/engine.js.map +0 -1
- package/dist/cjs/enums.d.ts.map +0 -1
- package/dist/cjs/enums.js.map +0 -1
- package/dist/cjs/generated/fields.d.ts.map +0 -1
- package/dist/cjs/generated/fields.js.map +0 -1
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/initiator.d.ts.map +0 -1
- package/dist/cjs/initiator.js.map +0 -1
- package/dist/cjs/message.d.ts.map +0 -1
- package/dist/cjs/message.js.map +0 -1
- package/dist/cjs/native.d.ts.map +0 -1
- package/dist/cjs/native.js.map +0 -1
- package/dist/cjs/session-id.d.ts.map +0 -1
- package/dist/cjs/session-id.js.map +0 -1
- package/dist/cjs/session-settings.d.ts.map +0 -1
- package/dist/cjs/session-settings.js.map +0 -1
- package/dist/esm/acceptor.d.ts.map +0 -1
- package/dist/esm/acceptor.js.map +0 -1
- package/dist/esm/application.d.ts.map +0 -1
- package/dist/esm/application.js.map +0 -1
- package/dist/esm/data-dictionary.d.ts.map +0 -1
- package/dist/esm/data-dictionary.js.map +0 -1
- package/dist/esm/engine.d.ts.map +0 -1
- package/dist/esm/engine.js.map +0 -1
- package/dist/esm/enums.d.ts.map +0 -1
- package/dist/esm/enums.js.map +0 -1
- package/dist/esm/generated/fields.d.ts.map +0 -1
- package/dist/esm/generated/fields.js.map +0 -1
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/initiator.d.ts.map +0 -1
- package/dist/esm/initiator.js.map +0 -1
- package/dist/esm/message.d.ts.map +0 -1
- package/dist/esm/message.js.map +0 -1
- package/dist/esm/native.d.ts.map +0 -1
- package/dist/esm/native.js.map +0 -1
- package/dist/esm/session-id.d.ts.map +0 -1
- package/dist/esm/session-id.js.map +0 -1
- package/dist/esm/session-settings.d.ts.map +0 -1
- package/dist/esm/session-settings.js.map +0 -1
package/dist/esm/engine.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { EventEmitter } from 'node:events';
|
|
|
8
8
|
import { type NativeEngineConstructor } from './native.js';
|
|
9
9
|
import { Message } from './message.js';
|
|
10
10
|
import { SessionID } from './session-id.js';
|
|
11
|
+
import { Session } from './session.js';
|
|
11
12
|
import type { ApplicationHandlers } from './application.js';
|
|
12
13
|
import type { SessionSettings } from './session-settings.js';
|
|
13
14
|
/** Options for constructing an {@link Initiator} or {@link Acceptor}. */
|
|
@@ -73,7 +74,11 @@ export declare abstract class Engine extends EventEmitter {
|
|
|
73
74
|
* Stop the engine.
|
|
74
75
|
*
|
|
75
76
|
* Runs off the main thread and resolves once shutdown completes, keeping the
|
|
76
|
-
* event loop free for any in-flight callbacks.
|
|
77
|
+
* event loop free for any in-flight callbacks. Once it settles the engine's
|
|
78
|
+
* sessions are destroyed. A `stop()` called while another is still in flight
|
|
79
|
+
* (even from a `'logout'` listener that stop fired) returns the same Promise,
|
|
80
|
+
* so it too settles only once the sessions are gone; the first call's
|
|
81
|
+
* `force` applies to both.
|
|
77
82
|
*
|
|
78
83
|
* @param force When `true`, aborts immediately instead of draining gracefully.
|
|
79
84
|
*
|
|
@@ -83,8 +88,42 @@ export declare abstract class Engine extends EventEmitter {
|
|
|
83
88
|
* ```
|
|
84
89
|
*/
|
|
85
90
|
stop(force?: boolean): Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Whether a session is logged on.
|
|
93
|
+
*
|
|
94
|
+
* With no argument: `true` if **any** of this engine's sessions is logged on.
|
|
95
|
+
* With a {@link SessionID}: `true` only if that session belongs to this engine
|
|
96
|
+
* and is logged on (`false`, not an error, for a foreign id). Always `false`
|
|
97
|
+
* before {@link Engine.start} and once {@link Engine.stop} has settled; while
|
|
98
|
+
* a graceful stop is still in progress it reports the live state.
|
|
99
|
+
*
|
|
100
|
+
* @throws {TypeError} if `sessionID` is given but is not a {@link SessionID}
|
|
101
|
+
* (it does not fall back to the engine-wide form).
|
|
102
|
+
*/
|
|
103
|
+
isLoggedOn(sessionID?: SessionID): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* The ids of the sessions this engine was configured with (every `[SESSION]`
|
|
106
|
+
* in its settings). Stable for the engine's lifetime, including after
|
|
107
|
+
* {@link Engine.stop}.
|
|
108
|
+
*/
|
|
109
|
+
getSessions(): SessionID[];
|
|
110
|
+
/**
|
|
111
|
+
* A handle on one of this engine's sessions.
|
|
112
|
+
*
|
|
113
|
+
* @returns The {@link Session}, or `undefined` if `sessionID` is not one of
|
|
114
|
+
* this engine's sessions or {@link Engine.stop} has settled (that destroys
|
|
115
|
+
* its sessions). While a stop is still in progress the sessions are alive,
|
|
116
|
+
* so a `'logout'` listener can still read e.g. the final sequence numbers.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* initiator.on('logon', (id) => {
|
|
121
|
+
* const session = initiator.getSession(id)!;
|
|
122
|
+
* console.log('next seq', session.getExpectedSenderNum());
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
getSession(sessionID: SessionID): Session | undefined;
|
|
88
127
|
/**
|
|
89
128
|
* Keep the Node.js event loop alive while the engine is running (default once
|
|
90
129
|
* started). Pair with {@link Engine.unref} to let a short script exit.
|
|
@@ -111,4 +150,3 @@ export interface Engine {
|
|
|
111
150
|
/** List the listeners registered for an event. */
|
|
112
151
|
listeners<E extends keyof EngineEvents>(event: E): Array<(...args: EngineEvents[E]) => void>;
|
|
113
152
|
}
|
|
114
|
-
//# sourceMappingURL=engine.d.ts.map
|
package/dist/esm/engine.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { EventEmitter } from 'node:events';
|
|
8
8
|
import { Message } from './message.js';
|
|
9
|
-
import { SessionID } from './session-id.js';
|
|
9
|
+
import { SessionID, toNativeSessionID } from './session-id.js';
|
|
10
|
+
import { Session } from './session.js';
|
|
10
11
|
/**
|
|
11
12
|
* Base class for the FIX session engines.
|
|
12
13
|
*
|
|
@@ -103,7 +104,11 @@ export class Engine extends EventEmitter {
|
|
|
103
104
|
* Stop the engine.
|
|
104
105
|
*
|
|
105
106
|
* Runs off the main thread and resolves once shutdown completes, keeping the
|
|
106
|
-
* event loop free for any in-flight callbacks.
|
|
107
|
+
* event loop free for any in-flight callbacks. Once it settles the engine's
|
|
108
|
+
* sessions are destroyed. A `stop()` called while another is still in flight
|
|
109
|
+
* (even from a `'logout'` listener that stop fired) returns the same Promise,
|
|
110
|
+
* so it too settles only once the sessions are gone; the first call's
|
|
111
|
+
* `force` applies to both.
|
|
107
112
|
*
|
|
108
113
|
* @param force When `true`, aborts immediately instead of draining gracefully.
|
|
109
114
|
*
|
|
@@ -115,9 +120,50 @@ export class Engine extends EventEmitter {
|
|
|
115
120
|
stop(force) {
|
|
116
121
|
return this.#native.stop(force);
|
|
117
122
|
}
|
|
118
|
-
/**
|
|
119
|
-
|
|
120
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Whether a session is logged on.
|
|
125
|
+
*
|
|
126
|
+
* With no argument: `true` if **any** of this engine's sessions is logged on.
|
|
127
|
+
* With a {@link SessionID}: `true` only if that session belongs to this engine
|
|
128
|
+
* and is logged on (`false`, not an error, for a foreign id). Always `false`
|
|
129
|
+
* before {@link Engine.start} and once {@link Engine.stop} has settled; while
|
|
130
|
+
* a graceful stop is still in progress it reports the live state.
|
|
131
|
+
*
|
|
132
|
+
* @throws {TypeError} if `sessionID` is given but is not a {@link SessionID}
|
|
133
|
+
* (it does not fall back to the engine-wide form).
|
|
134
|
+
*/
|
|
135
|
+
isLoggedOn(sessionID) {
|
|
136
|
+
return sessionID === undefined
|
|
137
|
+
? this.#native.isLoggedOn()
|
|
138
|
+
: this.#native.isLoggedOn(toNativeSessionID(sessionID, 'sessionID'));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The ids of the sessions this engine was configured with (every `[SESSION]`
|
|
142
|
+
* in its settings). Stable for the engine's lifetime, including after
|
|
143
|
+
* {@link Engine.stop}.
|
|
144
|
+
*/
|
|
145
|
+
getSessions() {
|
|
146
|
+
return this.#native.getSessions().map((h) => SessionID.fromNative(h));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* A handle on one of this engine's sessions.
|
|
150
|
+
*
|
|
151
|
+
* @returns The {@link Session}, or `undefined` if `sessionID` is not one of
|
|
152
|
+
* this engine's sessions or {@link Engine.stop} has settled (that destroys
|
|
153
|
+
* its sessions). While a stop is still in progress the sessions are alive,
|
|
154
|
+
* so a `'logout'` listener can still read e.g. the final sequence numbers.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* initiator.on('logon', (id) => {
|
|
159
|
+
* const session = initiator.getSession(id)!;
|
|
160
|
+
* console.log('next seq', session.getExpectedSenderNum());
|
|
161
|
+
* });
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
getSession(sessionID) {
|
|
165
|
+
const handle = this.#native.getSession(toNativeSessionID(sessionID, 'sessionID'));
|
|
166
|
+
return handle ? Session.fromNative(handle) : undefined;
|
|
121
167
|
}
|
|
122
168
|
/**
|
|
123
169
|
* Keep the Node.js event loop alive while the engine is running (default once
|
|
@@ -131,4 +177,3 @@ export class Engine extends EventEmitter {
|
|
|
131
177
|
this.#native.unref();
|
|
132
178
|
}
|
|
133
179
|
}
|
|
134
|
-
//# sourceMappingURL=engine.js.map
|
package/dist/esm/enums.d.ts
CHANGED
|
@@ -1,22 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FIX constants.
|
|
3
|
+
*
|
|
4
|
+
* - {@link FIELD} — field-name → tag-number (e.g. `FIELD.MsgType === 35`).
|
|
5
|
+
* Generated from QuickFIX's `FixFieldNumbers.h` (see `src/generated/fields.ts`),
|
|
6
|
+
* so it carries every `FIX::FIELD::*` name the bundled engine knows.
|
|
7
|
+
* - value groups such as {@link MsgType} and {@link Side} (e.g.
|
|
8
|
+
* `MsgType.Logon === 'A'`, `Side.Buy === '1'`) — one per field, generated from
|
|
9
|
+
* QuickFIX's `FixValues.h` (see `src/generated/values.ts`), so every
|
|
10
|
+
* `FIX::<Field>_<VALUE>` constant is here. {@link VALUES} holds all of them
|
|
11
|
+
* keyed by field name, and each group is also importable from
|
|
12
|
+
* `@homaiohq/napi-quickfix/values` without loading the native addon.
|
|
13
|
+
*
|
|
14
|
+
* Everything carries literal types and is frozen, so a misspelt name is a
|
|
15
|
+
* compile error and consumers cannot mutate the shared constant tables.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { FIELD, MsgType, enums } from '@homaiohq/napi-quickfix';
|
|
20
|
+
* msg.setField(FIELD.MsgType, MsgType.Logon);
|
|
21
|
+
* const side = enums.Side.Buy;
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import { FIELD } from './generated/fields.js';
|
|
25
|
+
import { type ValueGroups } from './generated/values.js';
|
|
1
26
|
export { FIELD, type FieldName } from './generated/fields.js';
|
|
2
|
-
|
|
27
|
+
export { VALUES, MsgType, Side, OrdType, TimeInForce, type ValueGroups, type ValueGroupName, } from './generated/values.js';
|
|
28
|
+
/**
|
|
29
|
+
* A single group of FIX constants widened to a string-indexed map (name → value).
|
|
30
|
+
*
|
|
31
|
+
* Every value group and {@link FIELD} is assignable to it, so use it where a group
|
|
32
|
+
* is looked up by a `string` key the compiler cannot narrow (a name read from
|
|
33
|
+
* configuration, say) instead of the literally-typed group itself:
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const group: EnumGroup = enums[name as ValueGroupName];
|
|
38
|
+
* const code = group[valueName];
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
3
41
|
export type EnumGroup = Readonly<Record<string, number | string>>;
|
|
4
|
-
/**
|
|
5
|
-
|
|
42
|
+
/**
|
|
43
|
+
* The full, frozen tree of FIX constants: every value group of {@link ValueGroups}
|
|
44
|
+
* plus the {@link FIELD} tag table.
|
|
45
|
+
*/
|
|
46
|
+
export type Enums = ValueGroups & {
|
|
47
|
+
readonly FIELD: typeof FIELD;
|
|
48
|
+
};
|
|
6
49
|
/**
|
|
7
50
|
* The complete tree of FIX constants (frozen), e.g. `enums.FIELD.MsgType`,
|
|
8
51
|
* `enums.MsgType.Logon`, `enums.Side.Buy`.
|
|
9
52
|
*
|
|
10
|
-
* `enums.FIELD` is the same table as {@link FIELD};
|
|
11
|
-
* the
|
|
53
|
+
* `enums.FIELD` is the same table as {@link FIELD}; every other member is the
|
|
54
|
+
* same object as the corresponding {@link VALUES} group.
|
|
12
55
|
*/
|
|
13
56
|
export declare const enums: Enums;
|
|
14
|
-
/** A group of numeric FIX constants (name → number). */
|
|
15
|
-
export type NumericEnumGroup = Readonly<Record<string, number>>;
|
|
16
|
-
/** A group of string-valued FIX constants (name → string), e.g. {@link MsgType}. */
|
|
17
|
-
export type StringEnumGroup = Readonly<Record<string, string>>;
|
|
18
|
-
/** MsgType values (strings), e.g. `MsgType.Logon === 'A'`. */
|
|
19
|
-
export declare const MsgType: StringEnumGroup;
|
|
20
|
-
/** Side values (strings), e.g. `Side.Buy === '1'`. */
|
|
21
|
-
export declare const Side: StringEnumGroup;
|
|
22
|
-
//# sourceMappingURL=enums.d.ts.map
|
package/dist/esm/enums.js
CHANGED
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
*
|
|
4
4
|
* - {@link FIELD} — field-name → tag-number (e.g. `FIELD.MsgType === 35`).
|
|
5
5
|
* Generated from QuickFIX's `FixFieldNumbers.h` (see `src/generated/fields.ts`),
|
|
6
|
-
* so it carries every `FIX::FIELD::*` name the bundled engine knows
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* so it carries every `FIX::FIELD::*` name the bundled engine knows.
|
|
7
|
+
* - value groups such as {@link MsgType} and {@link Side} (e.g.
|
|
8
|
+
* `MsgType.Logon === 'A'`, `Side.Buy === '1'`) — one per field, generated from
|
|
9
|
+
* QuickFIX's `FixValues.h` (see `src/generated/values.ts`), so every
|
|
10
|
+
* `FIX::<Field>_<VALUE>` constant is here. {@link VALUES} holds all of them
|
|
11
|
+
* keyed by field name, and each group is also importable from
|
|
12
|
+
* `@homaiohq/napi-quickfix/values` without loading the native addon.
|
|
10
13
|
*
|
|
11
|
-
* Everything
|
|
12
|
-
* constant tables.
|
|
14
|
+
* Everything carries literal types and is frozen, so a misspelt name is a
|
|
15
|
+
* compile error and consumers cannot mutate the shared constant tables.
|
|
13
16
|
*
|
|
14
17
|
* @example
|
|
15
18
|
* ```ts
|
|
@@ -19,27 +22,14 @@
|
|
|
19
22
|
* ```
|
|
20
23
|
*/
|
|
21
24
|
import { FIELD } from './generated/fields.js';
|
|
22
|
-
import {
|
|
25
|
+
import { VALUES } from './generated/values.js';
|
|
23
26
|
export { FIELD } from './generated/fields.js';
|
|
24
|
-
|
|
25
|
-
const out = {};
|
|
26
|
-
for (const key of Object.keys(source)) {
|
|
27
|
-
out[key] = Object.freeze({ ...source[key] });
|
|
28
|
-
}
|
|
29
|
-
// FIELD is already frozen (generated); reuse it rather than copying 6000+ keys.
|
|
30
|
-
out.FIELD = FIELD;
|
|
31
|
-
return Object.freeze(out);
|
|
32
|
-
}
|
|
27
|
+
export { VALUES, MsgType, Side, OrdType, TimeInForce, } from './generated/values.js';
|
|
33
28
|
/**
|
|
34
29
|
* The complete tree of FIX constants (frozen), e.g. `enums.FIELD.MsgType`,
|
|
35
30
|
* `enums.MsgType.Logon`, `enums.Side.Buy`.
|
|
36
31
|
*
|
|
37
|
-
* `enums.FIELD` is the same table as {@link FIELD};
|
|
38
|
-
* the
|
|
32
|
+
* `enums.FIELD` is the same table as {@link FIELD}; every other member is the
|
|
33
|
+
* same object as the corresponding {@link VALUES} group.
|
|
39
34
|
*/
|
|
40
|
-
export const enums =
|
|
41
|
-
/** MsgType values (strings), e.g. `MsgType.Logon === 'A'`. */
|
|
42
|
-
export const MsgType = (enums.MsgType ?? Object.freeze({}));
|
|
43
|
-
/** Side values (strings), e.g. `Side.Buy === '1'`. */
|
|
44
|
-
export const Side = (enums.Side ?? Object.freeze({}));
|
|
45
|
-
//# sourceMappingURL=enums.js.map
|
|
35
|
+
export const enums = /* @__PURE__ */ Object.freeze({ ...VALUES, FIELD });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire formatting of the `string | number` field values `Message` and `Group`
|
|
3
|
+
* accept.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A field value as FIX text. Strings pass through. A number keeps its shortest
|
|
7
|
+
* round-trip digits but is written without exponent notation, which FIX numeric
|
|
8
|
+
* fields do not allow (`1e-7` → `'0.0000001'`, `1e21` →
|
|
9
|
+
* `'1000000000000000000000'`, where `String` gives `'1e-7'` and `'1e+21'`).
|
|
10
|
+
* @throws `RangeError` for `NaN` and `±Infinity`, which have no FIX form.
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatFieldValue(value: string | number): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire formatting of the `string | number` field values `Message` and `Group`
|
|
3
|
+
* accept.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A field value as FIX text. Strings pass through. A number keeps its shortest
|
|
7
|
+
* round-trip digits but is written without exponent notation, which FIX numeric
|
|
8
|
+
* fields do not allow (`1e-7` → `'0.0000001'`, `1e21` →
|
|
9
|
+
* `'1000000000000000000000'`, where `String` gives `'1e-7'` and `'1e+21'`).
|
|
10
|
+
* @throws `RangeError` for `NaN` and `±Infinity`, which have no FIX form.
|
|
11
|
+
*/
|
|
12
|
+
export function formatFieldValue(value) {
|
|
13
|
+
if (typeof value !== 'number') {
|
|
14
|
+
return String(value);
|
|
15
|
+
}
|
|
16
|
+
if (!Number.isFinite(value)) {
|
|
17
|
+
throw new RangeError(`field value must be a finite number, got ${value}`);
|
|
18
|
+
}
|
|
19
|
+
const text = String(value);
|
|
20
|
+
const e = text.indexOf('e');
|
|
21
|
+
if (e === -1) {
|
|
22
|
+
return text;
|
|
23
|
+
}
|
|
24
|
+
// `[-]d[.ddd]e±n`: move the decimal point of the mantissa n places.
|
|
25
|
+
const sign = value < 0 ? '-' : '';
|
|
26
|
+
const mantissa = text.slice(sign.length, e);
|
|
27
|
+
const point = mantissa.indexOf('.');
|
|
28
|
+
const digits = mantissa.replace('.', '');
|
|
29
|
+
const at = (point === -1 ? mantissa.length : point) + Number(text.slice(e + 1));
|
|
30
|
+
if (at <= 0) {
|
|
31
|
+
return `${sign}0.${'0'.repeat(-at)}${digits}`;
|
|
32
|
+
}
|
|
33
|
+
if (at >= digits.length) {
|
|
34
|
+
return `${sign}${digits}${'0'.repeat(at - digits.length)}`;
|
|
35
|
+
}
|
|
36
|
+
return `${sign}${digits.slice(0, at)}.${digits.slice(at)}`;
|
|
37
|
+
}
|