Order matching logic sequencing issue [on hold]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0












$begingroup$


I have developed a trading exchange where orders are matched in real-time with least possible latency. The order matching service logic is functioning correctly. However, there's a minute error in the operation.



The sequence is wrong. To explain it below is the example of the order book.



Buy side:



Price =3 Qty =1
Price =2 Qty =1
Price =1 Qty =1


Now a user comes with a sell order of Qty=3 at price =1. In this case, all buy orders will execute, but in a sequence of:



First it will execute pending order with buy price of 3, then 2, and then 1.



My matching service executes the logic, but in reverse sequence. Below is the snippet of the code, can someone help ?



if (matchOrderRequest.getOrderType() == OrderType.BUY) 
{
optionalMatchOrder=orderRepository.findFirstByMarketAndOrderTypeAndPriceLessThanEqualOrderByPriceAscTimestampAsc(request.getMarket(), OrderType.SELL, request.getPrice());

}

else
{
optionalMatchOrder=orderRepository.findFirstByMarketAndOrderTypeAndPriceGreaterThanEqualOrderByPriceDescTimestampAsc(request.getMarket(), OrderType.BUY, request.getPrice());
}


There's a lot of logic after this, but it wouldn't make sense to post everything, but if anyone needs to know a little more, I can post it.










share|improve this question









New contributor




Kaushal Thakker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



put on hold as off-topic by Jamal 12 mins ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.
















  • $begingroup$
    May I know the reason why it is marked off topic? I do see the reason that code not implemented, but it's just part of the code where I assume the problem is. The entire project is too big to be posted here.
    $endgroup$
    – Kaushal Thakker
    10 mins ago


















0












$begingroup$


I have developed a trading exchange where orders are matched in real-time with least possible latency. The order matching service logic is functioning correctly. However, there's a minute error in the operation.



The sequence is wrong. To explain it below is the example of the order book.



Buy side:



Price =3 Qty =1
Price =2 Qty =1
Price =1 Qty =1


Now a user comes with a sell order of Qty=3 at price =1. In this case, all buy orders will execute, but in a sequence of:



First it will execute pending order with buy price of 3, then 2, and then 1.



My matching service executes the logic, but in reverse sequence. Below is the snippet of the code, can someone help ?



if (matchOrderRequest.getOrderType() == OrderType.BUY) 
{
optionalMatchOrder=orderRepository.findFirstByMarketAndOrderTypeAndPriceLessThanEqualOrderByPriceAscTimestampAsc(request.getMarket(), OrderType.SELL, request.getPrice());

}

else
{
optionalMatchOrder=orderRepository.findFirstByMarketAndOrderTypeAndPriceGreaterThanEqualOrderByPriceDescTimestampAsc(request.getMarket(), OrderType.BUY, request.getPrice());
}


There's a lot of logic after this, but it wouldn't make sense to post everything, but if anyone needs to know a little more, I can post it.










share|improve this question









New contributor




Kaushal Thakker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



put on hold as off-topic by Jamal 12 mins ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.
















  • $begingroup$
    May I know the reason why it is marked off topic? I do see the reason that code not implemented, but it's just part of the code where I assume the problem is. The entire project is too big to be posted here.
    $endgroup$
    – Kaushal Thakker
    10 mins ago














0












0








0





$begingroup$


I have developed a trading exchange where orders are matched in real-time with least possible latency. The order matching service logic is functioning correctly. However, there's a minute error in the operation.



The sequence is wrong. To explain it below is the example of the order book.



Buy side:



Price =3 Qty =1
Price =2 Qty =1
Price =1 Qty =1


Now a user comes with a sell order of Qty=3 at price =1. In this case, all buy orders will execute, but in a sequence of:



First it will execute pending order with buy price of 3, then 2, and then 1.



My matching service executes the logic, but in reverse sequence. Below is the snippet of the code, can someone help ?



if (matchOrderRequest.getOrderType() == OrderType.BUY) 
{
optionalMatchOrder=orderRepository.findFirstByMarketAndOrderTypeAndPriceLessThanEqualOrderByPriceAscTimestampAsc(request.getMarket(), OrderType.SELL, request.getPrice());

}

else
{
optionalMatchOrder=orderRepository.findFirstByMarketAndOrderTypeAndPriceGreaterThanEqualOrderByPriceDescTimestampAsc(request.getMarket(), OrderType.BUY, request.getPrice());
}


There's a lot of logic after this, but it wouldn't make sense to post everything, but if anyone needs to know a little more, I can post it.










share|improve this question









New contributor




Kaushal Thakker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




I have developed a trading exchange where orders are matched in real-time with least possible latency. The order matching service logic is functioning correctly. However, there's a minute error in the operation.



The sequence is wrong. To explain it below is the example of the order book.



Buy side:



Price =3 Qty =1
Price =2 Qty =1
Price =1 Qty =1


Now a user comes with a sell order of Qty=3 at price =1. In this case, all buy orders will execute, but in a sequence of:



First it will execute pending order with buy price of 3, then 2, and then 1.



My matching service executes the logic, but in reverse sequence. Below is the snippet of the code, can someone help ?



if (matchOrderRequest.getOrderType() == OrderType.BUY) 
{
optionalMatchOrder=orderRepository.findFirstByMarketAndOrderTypeAndPriceLessThanEqualOrderByPriceAscTimestampAsc(request.getMarket(), OrderType.SELL, request.getPrice());

}

else
{
optionalMatchOrder=orderRepository.findFirstByMarketAndOrderTypeAndPriceGreaterThanEqualOrderByPriceDescTimestampAsc(request.getMarket(), OrderType.BUY, request.getPrice());
}


There's a lot of logic after this, but it wouldn't make sense to post everything, but if anyone needs to know a little more, I can post it.







java mongodb spring






share|improve this question









New contributor




Kaushal Thakker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Kaushal Thakker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 11 mins ago







Kaushal Thakker













New contributor




Kaushal Thakker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 19 mins ago









Kaushal ThakkerKaushal Thakker

11




11




New contributor




Kaushal Thakker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Kaushal Thakker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Kaushal Thakker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by Jamal 12 mins ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.







put on hold as off-topic by Jamal 12 mins ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.












  • $begingroup$
    May I know the reason why it is marked off topic? I do see the reason that code not implemented, but it's just part of the code where I assume the problem is. The entire project is too big to be posted here.
    $endgroup$
    – Kaushal Thakker
    10 mins ago


















  • $begingroup$
    May I know the reason why it is marked off topic? I do see the reason that code not implemented, but it's just part of the code where I assume the problem is. The entire project is too big to be posted here.
    $endgroup$
    – Kaushal Thakker
    10 mins ago
















$begingroup$
May I know the reason why it is marked off topic? I do see the reason that code not implemented, but it's just part of the code where I assume the problem is. The entire project is too big to be posted here.
$endgroup$
– Kaushal Thakker
10 mins ago




$begingroup$
May I know the reason why it is marked off topic? I do see the reason that code not implemented, but it's just part of the code where I assume the problem is. The entire project is too big to be posted here.
$endgroup$
– Kaushal Thakker
10 mins ago










0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Список кардиналов, возведённых папой римским Каликстом III

Deduzione

Mysql.sock missing - “Can't connect to local MySQL server through socket”