-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from Praashh/matching/engine
[feat]: order matching engine
- Loading branch information
Showing
12 changed files
with
899 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ coverage | |
# Turbo | ||
.turbo | ||
|
||
# Snapshot | ||
snapshot.json | ||
|
||
# Vercel | ||
.vercel | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { RedisClientType, createClient } from "redis"; | ||
import { DbMessage, MessageToApi, WsMessage } from "@opinix/types"; | ||
|
||
export class RedisManager { | ||
private client: RedisClientType; | ||
private static instance: RedisManager; | ||
|
||
constructor() { | ||
this.client = createClient(); | ||
this.client.connect(); | ||
} | ||
|
||
public static getInstance() { | ||
if (!this.instance) { | ||
this.instance = new RedisManager(); | ||
} | ||
return this.instance; | ||
} | ||
|
||
public pushMessage(message: DbMessage) { | ||
this.client.lPush("db_processor", JSON.stringify(message)); | ||
} | ||
|
||
public publishMessage(channel: string, message: WsMessage) { | ||
this.client.publish(channel, JSON.stringify(message)); | ||
} | ||
|
||
public sendToApi(clientId: string, message: MessageToApi) { | ||
this.client.publish(clientId, JSON.stringify(message)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { addToOrderQueue } from "./queues/orderQueue"; | ||
import { createClient } from "redis"; | ||
import orderWorker from "./queues/orderProcessor"; | ||
import { logger } from "@opinix/logger"; | ||
import { RedisManager } from "./classes/RedisManager"; | ||
const startWorker = async () => { | ||
logger.info("WORKER | Starting order worker"); | ||
orderWorker; | ||
}; | ||
|
||
startWorker(); | ||
export { addToOrderQueue }; | ||
export { addToOrderQueue, RedisManager, createClient }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ 2024-10-20 11:49:07 ] - [32minfo[39m - WORKER | Starting order worker | ||
[ 2024-10-20 11:49:07 ] - [32minfo[39m - SERVER | REDIS: Connected to Redis | ||
[ 2024-10-20 11:49:07 ] - [32minfo[39m - SERVER | REDIS: Redis connection is ready to start execution | ||
[ 2024-10-20 11:51:33 ] - [32minfo[39m - WORKER | Starting order worker | ||
[ 2024-10-20 11:51:33 ] - [32minfo[39m - SERVER | REDIS: Connected to Redis | ||
[ 2024-10-20 11:51:33 ] - [32minfo[39m - SERVER | REDIS: Redis connection is ready to start execution | ||
[ 2024-10-20 12:56:25 ] - [32minfo[39m - WORKER | Starting order worker | ||
[ 2024-10-20 12:56:25 ] - [32minfo[39m - SERVER | REDIS: Connected to Redis | ||
[ 2024-10-20 12:56:25 ] - [32minfo[39m - SERVER | REDIS: Redis connection is ready to start execution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,32 @@ | ||
export const ORDERBOOK = {}; | ||
/* | ||
TODOS: | ||
1. Fake Liquidity | ||
2. setting base balancing | ||
3. Login go through again | ||
4. TEST ENGINE ( Latency ) | shift it to RUST or GO if needed. | ||
5. TYPES | ||
6. Test Cases | ||
*/ | ||
|
||
import { createClient } from "@repo/order-queue"; | ||
import { Engine } from "./trade/Engine"; | ||
|
||
|
||
async function main() { | ||
const engine = new Engine(); | ||
const redisClient = createClient(); | ||
await redisClient.connect(); | ||
console.log("connected to redis"); | ||
|
||
while (true) { | ||
const response = await redisClient.rPop("messages" as string) | ||
if (!response) { | ||
|
||
} else { | ||
engine.processOrders(JSON.parse(response)); | ||
} | ||
} | ||
|
||
} | ||
|
||
main(); |
Oops, something went wrong.