@bhargav16exdd/cex 1.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,100 @@
1
+ export declare enum MarketType {
2
+ spot = "spot",
3
+ perp = "perp"
4
+ }
5
+ export declare enum OrderType {
6
+ limit = "limit",
7
+ market = "market"
8
+ }
9
+ export type SidePerp = "short" | "long";
10
+ export type SideSpot = "ask" | "bid";
11
+ export interface FillType {
12
+ makerID: string;
13
+ takerID: string;
14
+ makerSide: string;
15
+ takerSide: string;
16
+ makerOrderID: string;
17
+ takerOrderID: string;
18
+ quantity: number;
19
+ symbol: string;
20
+ market: string;
21
+ price: number;
22
+ }
23
+ export interface OrderEntityType {
24
+ orderId: string;
25
+ side: SidePerp | SideSpot;
26
+ type: OrderType;
27
+ price: number;
28
+ quantity: number;
29
+ filledQuantity: number;
30
+ status: OrderStatus;
31
+ userId: string;
32
+ symbol: string;
33
+ market: string;
34
+ }
35
+ export type OrderStatus = "open" | "cancelled" | "partialfill" | "closed";
36
+ export type EngineCommandType = "reset" | "create_order" | "cancel_order" | "get_open_order" | "get_depth" | "init_user_balance" | "get_user_balance" | "update_user_balance" | "update_user_stock" | "get_user_stock_quantity" | "get_open_contract" | "create_stock_entity";
37
+ export declare enum EngineCommandEnum {
38
+ reset = "reset",
39
+ CREATE_ORDER = "create_order",
40
+ CANCEL_ORDER = "cancel_order",
41
+ GET_OPEN_ORDERS = "get_open_order",
42
+ GET_DEPTH = "get_depth",
43
+ INIT_USER_BALANCE = "init_user_balance",
44
+ GET_USER_BALANCE = "get_user_balance",
45
+ GET_USER_STOCK_QUANTITY = "get_user_stock_quantity",
46
+ UPDATE_USER_BALANCE = "update_user_balance",
47
+ UPDATE_USER_STOCK = "update_user_stock",
48
+ GET_OPEN_CONTRACT = "get_open_contract",
49
+ CREATE_STOCK_ENTITY = "create_stock_entity"
50
+ }
51
+ export interface EngineRequestType {
52
+ transactionId: string;
53
+ responseQueue: string;
54
+ type: EngineCommandType;
55
+ payload: Record<string, unknown>;
56
+ }
57
+ export interface EngineResponseType {
58
+ transactionId: string;
59
+ ok: boolean;
60
+ data?: unknown;
61
+ error?: string;
62
+ }
63
+ export declare enum EngineType {
64
+ spot = "spot",
65
+ perp = "perp"
66
+ }
67
+ export declare enum AdapterMessageType {
68
+ APPEND_ONLY = "append_only",
69
+ INSERT = "insert",
70
+ UPDATE = "update"
71
+ }
72
+ export declare enum AdapterEntityType {
73
+ FILL = "fill",
74
+ ORDER = "order",
75
+ CONTRACT = "contract"
76
+ }
77
+ export interface AdapterRequestType {
78
+ messageType: AdapterMessageType;
79
+ payload: any;
80
+ entityType: AdapterEntityType;
81
+ }
82
+ export interface ClientWsRequest {
83
+ type: "PING" | "SUBSCRIBE";
84
+ payload: {
85
+ topic: string;
86
+ };
87
+ }
88
+ export interface ClientWsResponse {
89
+ type: "PONG" | "DEPTH";
90
+ payload: ClientWsResponsePayload | {};
91
+ }
92
+ export interface ClientWsResponsePayload {
93
+ topic: string;
94
+ updateId: number;
95
+ asks: Array<Array<string>>;
96
+ bids: Array<Array<string>>;
97
+ }
98
+ export interface EngineWsMessage extends ClientWsResponsePayload {
99
+ }
100
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,oBAAY,UAAU;IACpB,IAAI,SAAS;IACb,IAAI,SAAS;CACd;AAED,oBAAY,SAAS;IACpB,KAAK,UAAU;IACf,MAAM,WAAW;CACjB;AAED,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AACxC,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,KAAK,CAAC;AAErC,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAC,MAAM,CAAC;IACjB,SAAS,EAAC,MAAM,CAAC;IACj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MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,oBAAY,UAAU;IACpB,IAAI,SAAS;IACb,IAAI,SAAS;CACd;AAGD,oBAAY,kBAAkB;IAC5B,WAAW,gBAAgB;IAC3B,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAED,oBAAY,iBAAiB;IAC3B,IAAI,SAAS;IACb,KAAK,UAAU;IACf,QAAQ,aAAa;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAC,kBAAkB,CAAA;IAC9B,OAAO,EAAC,GAAG,CAAA;IACX,UAAU,EAAC,iBAAiB,CAAA;CAC7B;AASD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAG,MAAM,GAAG,WAAW,CAAC;IAC5B,OAAO,EAAG;QACR,KAAK,EAAG,MAAM,CAAA;KACf,CAAA;CACF;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAG,MAAM,GAAG,OAAO,CAAC;IACxB,OAAO,EAAG,uBAAuB,GAAG,EAAE,CAAA;CACvC;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAC,MAAM,CAAC;IACb,QAAQ,EAAC,MAAM,CAAC;IAChB,IAAI,EAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1B,IAAI,EAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;CAC1B;AAID,MAAM,WAAW,eAAgB,SAAQ,uBAAuB;CAAG"}
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdapterEntityType = exports.AdapterMessageType = exports.EngineType = exports.EngineCommandEnum = exports.OrderType = exports.MarketType = void 0;
4
+ /*
5
+ -------------- GLOBAL TYPES ----------------
6
+ NOTE : USE MARKET ENUMS AS SMALL ONLY
7
+ --------------------------------------------
8
+ */
9
+ var MarketType;
10
+ (function (MarketType) {
11
+ MarketType["spot"] = "spot";
12
+ MarketType["perp"] = "perp";
13
+ })(MarketType || (exports.MarketType = MarketType = {}));
14
+ var OrderType;
15
+ (function (OrderType) {
16
+ OrderType["limit"] = "limit";
17
+ OrderType["market"] = "market";
18
+ })(OrderType || (exports.OrderType = OrderType = {}));
19
+ var EngineCommandEnum;
20
+ (function (EngineCommandEnum) {
21
+ EngineCommandEnum["reset"] = "reset";
22
+ EngineCommandEnum["CREATE_ORDER"] = "create_order";
23
+ EngineCommandEnum["CANCEL_ORDER"] = "cancel_order";
24
+ EngineCommandEnum["GET_OPEN_ORDERS"] = "get_open_order";
25
+ EngineCommandEnum["GET_DEPTH"] = "get_depth";
26
+ EngineCommandEnum["INIT_USER_BALANCE"] = "init_user_balance";
27
+ EngineCommandEnum["GET_USER_BALANCE"] = "get_user_balance";
28
+ EngineCommandEnum["GET_USER_STOCK_QUANTITY"] = "get_user_stock_quantity";
29
+ EngineCommandEnum["UPDATE_USER_BALANCE"] = "update_user_balance";
30
+ EngineCommandEnum["UPDATE_USER_STOCK"] = "update_user_stock";
31
+ EngineCommandEnum["GET_OPEN_CONTRACT"] = "get_open_contract";
32
+ EngineCommandEnum["CREATE_STOCK_ENTITY"] = "create_stock_entity";
33
+ })(EngineCommandEnum || (exports.EngineCommandEnum = EngineCommandEnum = {}));
34
+ var EngineType;
35
+ (function (EngineType) {
36
+ EngineType["spot"] = "spot";
37
+ EngineType["perp"] = "perp";
38
+ })(EngineType || (exports.EngineType = EngineType = {}));
39
+ var AdapterMessageType;
40
+ (function (AdapterMessageType) {
41
+ AdapterMessageType["APPEND_ONLY"] = "append_only";
42
+ AdapterMessageType["INSERT"] = "insert";
43
+ AdapterMessageType["UPDATE"] = "update";
44
+ })(AdapterMessageType || (exports.AdapterMessageType = AdapterMessageType = {}));
45
+ var AdapterEntityType;
46
+ (function (AdapterEntityType) {
47
+ AdapterEntityType["FILL"] = "fill";
48
+ AdapterEntityType["ORDER"] = "order";
49
+ AdapterEntityType["CONTRACT"] = "contract";
50
+ })(AdapterEntityType || (exports.AdapterEntityType = AdapterEntityType = {}));
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;;EAIE;AACF,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,2BAAa,CAAA;IACb,2BAAa,CAAA;AACf,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB;AAED,IAAY,SAGX;AAHD,WAAY,SAAS;IACpB,4BAAe,CAAA;IACf,8BAAiB,CAAA;AAClB,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AA4DD,IAAY,iBAgBX;AAhBD,WAAY,iBAAiB;IAC3B,oCAAe,CAAA;IACf,kDAA6B,CAAA;IAC7B,kDAA6B,CAAA;IAC7B,uDAAkC,CAAA;IAElC,4CAAuB,CAAA;IAEvB,4DAAuC,CAAA;IACvC,0DAAqC,CAAA;IACrC,wEAAmD,CAAA;IACnD,gEAA2C,CAAA;IAC3C,4DAAuC,CAAA;IAEvC,4DAAuC,CAAA;IACvC,gEAA2C,CAAA;AAC7C,CAAC,EAhBW,iBAAiB,iCAAjB,iBAAiB,QAgB5B;AAiBD,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,2BAAa,CAAA;IACb,2BAAa,CAAA;AACf,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB;AAGD,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,iDAA2B,CAAA;IAC3B,uCAAiB,CAAA;IACjB,uCAAiB,CAAA;AACnB,CAAC,EAJW,kBAAkB,kCAAlB,kBAAkB,QAI7B;AAED,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,kCAAa,CAAA;IACb,oCAAe,CAAA;IACf,0CAAqB,CAAA;AACvB,CAAC,EAJW,iBAAiB,iCAAjB,iBAAiB,QAI5B"}
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@bhargav16exdd/cex",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "license": "ISC",
6
+ "module": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "author": "",
10
+ "scripts": {
11
+ "build":"tsc",
12
+ "dev" : "tsc --watch"
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "^6.0.3"
16
+ }
17
+ }
package/src/index.ts ADDED
@@ -0,0 +1,159 @@
1
+ /*
2
+ -------------- GLOBAL TYPES ----------------
3
+ NOTE : USE MARKET ENUMS AS SMALL ONLY
4
+ --------------------------------------------
5
+ */
6
+ export enum MarketType {
7
+ spot = "spot",
8
+ perp = "perp"
9
+ }
10
+
11
+ export enum OrderType {
12
+ limit = "limit",
13
+ market = "market"
14
+ }
15
+
16
+ export type SidePerp = "short" | "long";
17
+ export type SideSpot = "ask" | "bid";
18
+
19
+ export interface FillType {
20
+ makerID: string;
21
+ takerID: string;
22
+ makerSide:string;
23
+ takerSide:string;
24
+ makerOrderID: string;
25
+ takerOrderID: string;
26
+ quantity: number;
27
+ symbol: string;
28
+ market: string;
29
+ price:number;
30
+ }
31
+
32
+ export interface OrderEntityType {
33
+ orderId:string,
34
+
35
+ side: SidePerp | SideSpot,
36
+ type:OrderType,
37
+
38
+ price:number,
39
+ quantity:number,
40
+ filledQuantity:number,
41
+
42
+ status:OrderStatus
43
+
44
+ userId:string,
45
+
46
+ symbol:string,
47
+ market:string,
48
+ }
49
+
50
+ export type OrderStatus = "open" | "cancelled" | "partialfill" | "closed"
51
+
52
+ /*
53
+ ---- ENGINE REQUEST AND RESPONSE TYPES -----
54
+ --------------------------------------------
55
+ */
56
+ export type EngineCommandType =
57
+ | "reset"
58
+ | "create_order"
59
+ | "cancel_order"
60
+ | "get_open_order"
61
+
62
+ | "get_depth"
63
+
64
+ | "init_user_balance"
65
+ | "get_user_balance"
66
+ | "update_user_balance"
67
+ | "update_user_stock"
68
+ | "get_user_stock_quantity"
69
+
70
+ | "get_open_contract"
71
+ | "create_stock_entity"
72
+
73
+
74
+ export enum EngineCommandEnum {
75
+ reset = "reset",
76
+ CREATE_ORDER = "create_order",
77
+ CANCEL_ORDER = "cancel_order",
78
+ GET_OPEN_ORDERS = "get_open_order",
79
+
80
+ GET_DEPTH = "get_depth",
81
+
82
+ INIT_USER_BALANCE = "init_user_balance",
83
+ GET_USER_BALANCE = "get_user_balance",
84
+ GET_USER_STOCK_QUANTITY = "get_user_stock_quantity",
85
+ UPDATE_USER_BALANCE = "update_user_balance",
86
+ UPDATE_USER_STOCK = "update_user_stock",
87
+
88
+ GET_OPEN_CONTRACT = "get_open_contract",
89
+ CREATE_STOCK_ENTITY = "create_stock_entity",
90
+ }
91
+
92
+
93
+ export interface EngineRequestType {
94
+ transactionId: string;
95
+ responseQueue: string;
96
+ type: EngineCommandType;
97
+ payload: Record<string, unknown>;
98
+ }
99
+
100
+ export interface EngineResponseType {
101
+ transactionId: string;
102
+ ok: boolean;
103
+ data?: unknown;
104
+ error?: string;
105
+ }
106
+
107
+ export enum EngineType {
108
+ spot = "spot",
109
+ perp = "perp"
110
+ }
111
+
112
+
113
+ export enum AdapterMessageType {
114
+ APPEND_ONLY = "append_only",
115
+ INSERT = "insert",
116
+ UPDATE = "update",
117
+ }
118
+
119
+ export enum AdapterEntityType {
120
+ FILL = "fill",
121
+ ORDER = "order",
122
+ CONTRACT = "contract"
123
+ }
124
+
125
+ export interface AdapterRequestType {
126
+ messageType:AdapterMessageType
127
+ payload:any
128
+ entityType:AdapterEntityType
129
+ }
130
+
131
+ /*
132
+ ---- WEBSOCKET REQUEST AND RESPONSE TYPES -----
133
+ -----------------------------------------------
134
+ */
135
+
136
+ //CLIENT TO WS SERVER TYPES
137
+
138
+ export interface ClientWsRequest {
139
+ type : "PING" | "SUBSCRIBE",
140
+ payload : {
141
+ topic : string
142
+ }
143
+ }
144
+
145
+ export interface ClientWsResponse {
146
+ type: "PONG" | "DEPTH",
147
+ payload : ClientWsResponsePayload | {}
148
+ }
149
+
150
+ export interface ClientWsResponsePayload {
151
+ topic:string,
152
+ updateId:number,
153
+ asks:Array<Array<string>>,
154
+ bids:Array<Array<string>>
155
+ }
156
+
157
+ // ENGINE TO WS SERVER TYPES
158
+
159
+ export interface EngineWsMessage extends ClientWsResponsePayload {}
package/tsconfig.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ // Visit https://aka.ms/tsconfig to read more about this file
3
+ "compilerOptions": {
4
+ // File Layout
5
+ "rootDir": "./src",
6
+ "outDir": "./dist",
7
+
8
+ // Environment Settings
9
+ // See also https://aka.ms/tsconfig/module
10
+ "module": "nodenext",
11
+ "target": "esnext",
12
+ "types": [],
13
+ // For nodejs:
14
+ // "lib": ["esnext"],
15
+ // "types": ["node"],
16
+ // and npm install -D @types/node
17
+
18
+ // Other Outputs
19
+ "sourceMap": true,
20
+ "declaration": true,
21
+ "declarationMap": true,
22
+ "emitDeclarationOnly": true,
23
+
24
+ // Stricter Typechecking Options
25
+ "noUncheckedIndexedAccess": true,
26
+ "exactOptionalPropertyTypes": true,
27
+
28
+ // Style Options
29
+ // "noImplicitReturns": true,
30
+ // "noImplicitOverride": true,
31
+ // "noUnusedLocals": true,
32
+ // "noUnusedParameters": true,
33
+ // "noFallthroughCasesInSwitch": true,
34
+ // "noPropertyAccessFromIndexSignature": true,
35
+
36
+ // Recommended Options
37
+ "strict": true,
38
+ "jsx": "react-jsx",
39
+ "verbatimModuleSyntax": false,
40
+ "isolatedModules": true,
41
+ "noUncheckedSideEffectImports": true,
42
+ "moduleDetection": "force",
43
+ "skipLibCheck": true,
44
+ }
45
+ }