Skip to content

Commit

Permalink
testing engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Praashh committed Oct 22, 2024
1 parent 65b0ca9 commit c8fa5a0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
9 changes: 5 additions & 4 deletions apps/server/src/controllers/order/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ type TPlaceOrder = {
};
export const placeHandler = AsyncWrapper(
async (req: Request<{}, {}, TPlaceOrder>, res) => {
const { event_id, l1_expected_price, l1_order_quantity, offer_type } =
req.body;
let orderId = generateOrderId();
const { event_id, l1_expected_price, l1_order_quantity, offer_type } = req.body;

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

const order = {
[orderId]: {
event_id: event_id,
Expand All @@ -28,7 +29,7 @@ export const placeHandler = AsyncWrapper(
},
};
await addToOrderQueue(order);
redisClient.publishMessage("123", order);
redisClient.publishMessage(orderId, order);
let response = new SuccessResponse("Order placed successfully", 201);
return res.status(201).json(response);
}
Expand Down
1 change: 1 addition & 0 deletions packages/order-queue/src/classes/RedisManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class RedisManager {

constructor() {
this.client = createClient();
console.log("Redis connected log inside Redis Manager")
this.client.connect();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/zod/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const userZodSchema = z.object({
export const intiateOrderZodSchema = z.object({
event_id: z.number(),
l1_expected_price: z.number().min(0.1, {
message: "Order quantity must be a positive integer",
message: "Order price must be a positive integer",
}),
l1_order_quantity: z.number().min(0.1, {
message: "Order quantity must be a positive integer",
Expand Down
18 changes: 18 additions & 0 deletions services/engine/logs/server.log
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,21 @@
[ 2024-10-20 22:50:18 ] - info - WORKER | Starting order worker
[ 2024-10-20 23:47:55 ] - info - WORKER | Starting order worker
[ 2024-10-20 23:52:25 ] - info - WORKER | Starting order worker
[ 2024-10-22 11:00:20 ] - info - WORKER | Starting order worker
[ 2024-10-22 11:00:53 ] - info - WORKER | Starting order worker
[ 2024-10-22 11:02:50 ] - info - WORKER | Starting order worker
[ 2024-10-22 13:10:53 ] - info - WORKER | Starting order worker
[ 2024-10-22 13:11:49 ] - info - WORKER | Starting order worker
[ 2024-10-22 13:13:59 ] - info - WORKER | Starting order worker
[ 2024-10-22 13:14:16 ] - info - WORKER | Starting order worker
[ 2024-10-22 13:30:29 ] - info - WORKER | Starting order worker
[ 2024-10-22 13:38:17 ] - info - WORKER | Starting order worker
[ 2024-10-22 13:39:42 ] - info - WORKER | Starting order worker
[ 2024-10-22 13:40:03 ] - info - WORKER | Starting order worker
[ 2024-10-22 13:40:17 ] - info - WORKER | Starting order worker
[ 2024-10-22 13:40:30 ] - info - WORKER | Starting order worker
[ 2024-10-22 16:06:21 ] - info - WORKER | Starting order worker
[ 2024-10-22 23:26:09 ] - info - WORKER | Starting order worker
[ 2024-10-22 23:28:24 ] - info - WORKER | Starting order worker
[ 2024-10-22 23:28:41 ] - info - WORKER | Starting order worker
[ 2024-10-22 23:39:45 ] - info - WORKER | Starting order worker
8 changes: 4 additions & 4 deletions services/engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
6. Test Cases
*/

import { createClient } from "@repo/order-queue";
import { RedisManager } from "@repo/order-queue";
import { Engine } from "./trade/Engine";
import {Orderbook} from "./trade/Orderbook"


async function main() {
const engine = new Engine();
const redisClient = createClient();
await redisClient.connect();
const redis = new RedisManager();
const redisClient = redis.getClient();
console.log("connected to redis");

while (true) {
const response = await redisClient.rPop("messages" as string)
const response = await redisClient.lPop("ORDER_QUEUE")
if (!response) {

} else {
Expand Down

0 comments on commit c8fa5a0

Please sign in to comment.