Skip to content

Commit

Permalink
Merge pull request #56 from Praashh/wss-singleton
Browse files Browse the repository at this point in the history
Wss singleton and tooling
  • Loading branch information
Praashh authored Oct 25, 2024
2 parents 13f1275 + 38db642 commit dd4a2b7
Show file tree
Hide file tree
Showing 43 changed files with 493 additions and 2,721 deletions.
3 changes: 1 addition & 2 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"start": "node dist/index.js",
"build": "npx esbuild ./src/index.ts --bundle --platform=node --outfile=dist/index.js",
"dev": "nodemon src/index.ts"
"dev": "npm run build && npm run start"
},
"keywords": [],
"author": "",
Expand All @@ -30,7 +30,6 @@
"ioredis": "^5.4.1",
"jsonwebtoken": "^9.0.2",
"morgan": "^1.10.0",
"nodemon": "^3.1.7",
"prisma": "^5.20.0",
"uuid": "^10.0.0",
"winston": "^3.15.0",
Expand Down
40 changes: 21 additions & 19 deletions apps/server/src/controllers/order/index.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
import { addToOrderQueue } from "@repo/order-queue";
import { AsyncWrapper } from "../../utils/asynCatch";
import { generateOrderId } from "../../utils/utils";
import { SuccessResponse } from "../../utils/wrappers/success.res";
import { EOrderType } from "@opinix/types";
import { sides } from "@opinix/types";
import { Request } from "express";
import { RedisManager } from "@repo/order-queue";
import { v4 as uuid4 } from "uuid";

let redisClient = RedisManager.getInstance();
type TPlaceOrder = {
type TPlaceOrderReq = {
event_id: number;
l1_expected_price: number;
l1_order_quantity: number;
offer_type: EOrderType;
offer_type: sides;
userid: string
};

export const placeHandler = AsyncWrapper(
async (req: Request<{}, {}, TPlaceOrder>, res) => {
const { event_id, l1_expected_price, l1_order_quantity, offer_type } = req.body;
async (req: Request<{}, {}, TPlaceOrderReq>, res) => {
const { event_id, l1_expected_price, l1_order_quantity, offer_type, userid } = req.body;

// TODO: check Authorize the user

const orderId = generateOrderId();
console.log(orderId);

const order = {
[orderId]: {
event_id: event_id,
l1_expected_price: l1_expected_price,
l1_order_quantity: l1_order_quantity,
offer_type: offer_type,
const data = {
type: uuid4(),
data: {
market: event_id,
price: l1_expected_price,
type: "CREATE_ORDER", // type of the order , TODO: need to fix this
quantity: l1_order_quantity,
side: offer_type,
userId: userid.toString(),
},
};
await addToOrderQueue(order);
redisClient.publishMessage(orderId, order);

await addToOrderQueue(data);
let response = new SuccessResponse("Order placed successfully", 201);
return res.status(201).json(response);
}
Expand Down
Loading

0 comments on commit dd4a2b7

Please sign in to comment.