@flexemarkets/fm-sdk 0.0.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.
@@ -0,0 +1,128 @@
1
+ /** Flexemarkets domain models. */
2
+ export interface Person {
3
+ id: number;
4
+ accountId: number;
5
+ firstName: string | null;
6
+ lastName: string | null;
7
+ email: string | null;
8
+ roles: string[];
9
+ accountOwner: boolean;
10
+ createdDate: string | null;
11
+ lastModifiedDate: string | null;
12
+ }
13
+ export interface Account {
14
+ id: number | null;
15
+ name: string | null;
16
+ description: string | null;
17
+ owner: Person | null;
18
+ approval: boolean;
19
+ approvalDescription: string | null;
20
+ createdDate: string | null;
21
+ lastModifiedDate: string | null;
22
+ }
23
+ export interface Token {
24
+ requestUrl: string | null;
25
+ person: Person | null;
26
+ account: Account | null;
27
+ token: string | null;
28
+ }
29
+ export interface Security {
30
+ marketId: number;
31
+ units: number;
32
+ availableUnits: number;
33
+ canBuy: boolean;
34
+ canSell: boolean;
35
+ }
36
+ export interface Holding {
37
+ marketplaceId: number;
38
+ sessionId: number;
39
+ allocationId: number;
40
+ ownerId: number;
41
+ name: string | null;
42
+ cash: number;
43
+ availableCash: number;
44
+ securities: Security[];
45
+ }
46
+ export declare function getSecurity(holding: Holding, marketId: number): Security;
47
+ export declare function holdingUnits(holding: Holding): number[];
48
+ export interface Market {
49
+ id: number;
50
+ marketplaceId: number;
51
+ name: string | null;
52
+ description: string | null;
53
+ symbol: string | null;
54
+ privateMarket: boolean;
55
+ priceMinimum: number;
56
+ priceMaximum: number;
57
+ priceTick: number;
58
+ unitMinimum: number;
59
+ unitMaximum: number;
60
+ unitTick: number;
61
+ }
62
+ export declare function priceRound(market: Market, price: number): number;
63
+ export interface Marketplace {
64
+ id: number;
65
+ name: string | null;
66
+ description: string | null;
67
+ markets: Market[];
68
+ }
69
+ export declare const SESSION_STATE_INIT = "INIT";
70
+ export declare const SESSION_STATE_OPEN = "OPEN";
71
+ export declare const SESSION_STATE_PAUSED = "PAUSED";
72
+ export declare const SESSION_STATE_CLOSED = "CLOSED";
73
+ export interface Session {
74
+ marketplaceId: number;
75
+ allocationId: number;
76
+ id: number;
77
+ original: number;
78
+ state: string | null;
79
+ name: string | null;
80
+ description: string | null;
81
+ openDate: string | null;
82
+ closeDate: string | null;
83
+ }
84
+ export declare const ORDER_TYPE_LIMIT = "LIMIT";
85
+ export declare const ORDER_TYPE_CANCEL = "CANCEL";
86
+ export declare const ORDER_SIDE_BUY = "BUY";
87
+ export declare const ORDER_SIDE_SELL = "SELL";
88
+ export interface Order {
89
+ id: number;
90
+ original: number;
91
+ supplier: number;
92
+ consumer: number | null;
93
+ type: string | null;
94
+ side: string | null;
95
+ units: number;
96
+ price: number;
97
+ ownerId: number | null;
98
+ marketplaceId: number;
99
+ sessionId: number;
100
+ symbol: string | null;
101
+ marketId: number;
102
+ ownerTarget: string | null;
103
+ clientDescription: string | null;
104
+ createdDate: string | null;
105
+ lastModifiedDate: string | null;
106
+ }
107
+ export interface ClientConnection {
108
+ marketplaceId: number;
109
+ connectionId: number;
110
+ ownerId: number;
111
+ established: string | null;
112
+ terminated: string | null;
113
+ description: string | null;
114
+ }
115
+ export interface Version {
116
+ version: number;
117
+ }
118
+ export interface ApiRoot {
119
+ links: Record<string, string>;
120
+ }
121
+ export declare function getLink(root: ApiRoot, name: string): string | undefined;
122
+ export interface ConflictFailure {
123
+ status: string | null;
124
+ error: string | null;
125
+ message: string | null;
126
+ path: string | null;
127
+ suggestedName: string | null;
128
+ }
package/dist/types.js ADDED
@@ -0,0 +1,27 @@
1
+ /** Flexemarkets domain models. */
2
+ export function getSecurity(holding, marketId) {
3
+ const s = holding.securities.find((s) => s.marketId === marketId);
4
+ if (!s)
5
+ throw new Error(`Security for market ID ${marketId} not found.`);
6
+ return s;
7
+ }
8
+ export function holdingUnits(holding) {
9
+ return [...holding.securities]
10
+ .sort((a, b) => a.marketId - b.marketId)
11
+ .map((s) => s.units);
12
+ }
13
+ export function priceRound(market, price) {
14
+ return Math.min(Math.max(price - (price % market.priceTick), market.priceMinimum), market.priceMaximum);
15
+ }
16
+ export const SESSION_STATE_INIT = "INIT";
17
+ export const SESSION_STATE_OPEN = "OPEN";
18
+ export const SESSION_STATE_PAUSED = "PAUSED";
19
+ export const SESSION_STATE_CLOSED = "CLOSED";
20
+ export const ORDER_TYPE_LIMIT = "LIMIT";
21
+ export const ORDER_TYPE_CANCEL = "CANCEL";
22
+ export const ORDER_SIDE_BUY = "BUY";
23
+ export const ORDER_SIDE_SELL = "SELL";
24
+ export function getLink(root, name) {
25
+ return root.links[name];
26
+ }
27
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAmDlC,MAAM,UAAU,WAAW,CAAC,OAAgB,EAAE,QAAgB;IAC5D,MAAM,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;IAClE,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAQ,aAAa,CAAC,CAAC;IACzE,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC3C,OAAO,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;SAC3B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;SACvC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC;AAiBD,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,KAAa;IACtD,OAAO,IAAI,CAAC,GAAG,CACb,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,EACjE,MAAM,CAAC,YAAY,CACpB,CAAC;AACJ,CAAC;AASD,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AACzC,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AACzC,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AAC7C,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AAc7C,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AACxC,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAC1C,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC;AACpC,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AAuCtC,MAAM,UAAU,OAAO,CAAC,IAAa,EAAE,IAAY;IACjD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@flexemarkets/fm-sdk",
3
+ "version": "0.0.0",
4
+ "description": "Flexemarkets TypeScript SDK",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "scripts": {
19
+ "ticker": "tsx src/ticker.ts",
20
+ "build": "tsc",
21
+ "check": "tsc --noEmit",
22
+ "prepublishOnly": "npm run build"
23
+ },
24
+ "keywords": [
25
+ "flexemarkets",
26
+ "trading",
27
+ "api",
28
+ "sdk",
29
+ "websocket"
30
+ ],
31
+ "author": "Flexemarkets <support@flexemarkets.com>",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/flexemarkets/fm-sdk.git",
36
+ "directory": "sdks/typescript"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/flexemarkets/fm-sdk/issues"
40
+ },
41
+ "homepage": "https://github.com/flexemarkets/fm-sdk#readme",
42
+ "dependencies": {
43
+ "ws": "^8.18.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/ws": "^8.5.13",
47
+ "tsx": "^4.19.0",
48
+ "typescript": "^5.6.0"
49
+ }
50
+ }