Skip to content

Commit

Permalink
Merge pull request #58 from Praashh/integration
Browse files Browse the repository at this point in the history
fix: create random eventID
  • Loading branch information
Praashh authored Nov 4, 2024
2 parents a0c3a96 + 62baa25 commit 527f4eb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
7 changes: 2 additions & 5 deletions apps/server/src/controllers/event/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
*
*/

import { AsyncWrapper } from "../../utils/asynCatch";
import { TEvent } from "@opinix/types";
import { Request, Response } from "express";
Expand All @@ -27,10 +23,11 @@ export const createEventHandler = AsyncWrapper(
let slug = slugify(title);

let eventCode = eventCodeGenerator();

// check if event already exists using the slug name
const isEventExists = await prisma.event.findFirst({
where: {
slug: slug,
slug:slug,
},
});
if (isEventExists) {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function randomFourDigitNumber() {
}

function eventCodeGenerator(): number {
return parseInt(Math.random().toString(36).substring(2, 8));
return Math.floor(Math.random() * 100000000)
}
function slugify(name: string) {
return (
Expand Down
2 changes: 2 additions & 0 deletions services/engine/logs/server.log
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
[ 2024-10-24 22:57:25 ] - info - WORKER | Starting order worker
[ 2024-11-02 12:30:12 ] - info - WORKER | Starting order worker
[ 2024-11-04 18:23:29 ] - info - WORKER | Starting order worker
40 changes: 19 additions & 21 deletions services/engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
TODOS:
1. Fake Liquidity []
2. setting base balancing [x]
3. go through again
4. TEST ENGINE ( Latency ) | shift it to RUST or GO if needed.
5. TYPES
6. Test Cases
3. go through again []
4. TEST ENGINE ( Latency ) | shift it to RUST or GO if needed.[]
5. TYPES [x]
6. Test Cases [x]
*/

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

import { Orderbook } from "./trade/Orderbook";

async function main() {
const engine = new Engine();
Expand All @@ -20,28 +19,27 @@ async function main() {
console.log("connected to redis");

while (true) {
const response = await redisClient.rPop("ORDER_QUEUE")
const res = JSON.parse(response!)
const response = await redisClient.rPop("ORDER_QUEUE");
const parsedRespnse = JSON.parse(response!);
if (!response) {
} else {
const t = res.type;
const mess = res.data;
if (mess.side === "buy") {
mess.side = "yes";

}else {
const type = parsedRespnse.type;
const responseMessage = parsedRespnse.data;
if (responseMessage.side === "buy") {
responseMessage.side = "yes";
} else {
mess.side = "no";
responseMessage.side = "no";
}
const message = {
type: mess.type,
data: mess
}
engine.processOrders({ message, clientId: t });
type: responseMessage.type,
data: responseMessage,
};
engine.processOrders({ message, clientId: type });
}
}

}

main();


export { Engine, Orderbook };
export { Engine, Orderbook };

0 comments on commit 527f4eb

Please sign in to comment.