Skip to content

Commit

Permalink
Merge pull request #55 from Praashh/testcases
Browse files Browse the repository at this point in the history
[chore]: added engine test cases
  • Loading branch information
Praashh authored Oct 22, 2024
2 parents 410c673 + c8fa5a0 commit 13f1275
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 267 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ coverage
# Turbo
.turbo

# logs
logs

# Snapshot
snapshot.json

Expand Down
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
14 changes: 9 additions & 5 deletions services/engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +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 All @@ -29,4 +30,7 @@ async function main() {

}

main();
main();


export {Engine, Orderbook};
Loading

0 comments on commit 13f1275

Please sign in to comment.