I'm using the Bull library for managing job queues in a fast-paced cryptocurrency exchange application. I have two types of tasks: "create order" and "cancel order". If an order with the same ID already exists in the exchange, I don't want to create a new order with the same ID. ${coin}-${side}
Instead, I would like to retrieve the existing order's information and status to make decisions based on that. If my price is not match new order, then I will cancel and create new order.
Here are the key points of the problem I'm trying to solve:
I tried to use the available Bull library APIs to retrieve the information and status of an existing order. However, I'm facing issues when querying the status of a completed order using the isCompleted() method. This prevents me from correctly retrieving the status of a completed order. I would like to resolve this issue and be able to query the status of a completed order successfully.
When an order is canceled, I want to consider the "create order" task as completed. This approach allows me to prioritize incoming price quotes from various sources. If an order is canceled, I assume the "create order" task related to that order is completed, and I can proceed with the next create order task.
My goal is to send the generated values to the exchange within a very short timeframe, preferably within 1 second. However, I need the ability to adjust the speed of sending the values. This is crucial for developing a fast cryptocurrency exchange application.
I would like to solve the challenge of keeping the latest updated versions of my generated values in the exchange. It seems that the Last In, First Out (LIFO) concept is relevant here. My intention is to efficiently manage the processing speed of the incoming values to match the requirements of a high-speed cryptocurrency exchange.
I kindly request assistance in resolving this issue. How can I resend a task with the same ID after it is completed using the Bull library? Any guidance or suggestions would be greatly appreciated.
Sender area;
async function exchangeCreateOrder(coin, amount, price, side) {
try {
const prevOrder = await createOrderChain.getJob(`${side}-${coin}`);
const isCompleted = await prevOrder.isCompleted();
if (isCompleted) {
await isCompleted.remove();
const gonderilen = await createOrderChain.add(
{ coin, amount, price, side },
{
jobId: `${side}-${coin}`,
}
);
ololog.bgYellow(`CREATE ${side} ${coin} p: ${price}, a: ${amount}`);
} else {
ololog.bgRed("no prevOrder ");
}
} catch (e) {
console.log(
`ERROR EXC CREATE ${side} ORDER - ${coin}, price: ${price}, amount: ${amount}`,
e
);
}
}
My worker;
createOrderChain.process(async (job, done) => {
const { coin, side, amount, price } = job.data;
try {
const newOrder = await exc.createOrder(
coin + "/USDT",
"limit",
side,
amount,
price
);
ololog.bgYellow("OK");
done(null, newOrder);
} catch (e) {
ololog.bgRed("Create Error", e);
done(e);
}
});
what I really want to ask is, am I choosing the right technologies for this job? what do i actually have to do? I think I'm dealing with the HFT issue here. I would like to get help from experienced developers. thanks.