-
Notifications
You must be signed in to change notification settings - Fork 15
LWDEV-10476 Pre-trade control: configurable max value and calculated max volume #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
barsukovskii
wants to merge
7
commits into
master
Choose a base branch
from
LWDEV-10476
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3c11a76
LWDEV-10476 Pre-trade control: configurable max value and calculated …
barsukovskii 88774b6
Merge remote-tracking branch 'origin/master' into LWDEV-10476
barsukovskii 6f0f171
Merge remote-tracking branch 'origin/master' into LWDEV-10476
barsukovskii 3513983
Merge remote-tracking branch 'origin/master' into LWDEV-10476
barsukovskii b06b22d
LWDEV-10476 log error in case of invalid market order
barsukovskii 10e8800
Merge remote-tracking branch 'origin/master' into LWDEV-10476
barsukovskii 1351fda
Merge remote-tracking branch 'origin/master' into LWDEV-10476
barsukovskii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/com/lykke/matching/engine/daos/order/MaxOrderVolumeInfo.kt
This file contains hidden or 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,16 @@ | ||
| package com.lykke.matching.engine.daos.order | ||
|
|
||
| import com.lykke.matching.engine.utils.NumberUtils | ||
| import java.math.BigDecimal | ||
|
|
||
| class MaxOrderVolumeInfo(private val maxValue: BigDecimal, | ||
| private val midPrice: BigDecimal) { | ||
|
|
||
| val maxVolume: BigDecimal = NumberUtils.divideWithMaxScale(maxValue, midPrice) | ||
|
|
||
| override fun toString(): String { | ||
| return "maxValue=${NumberUtils.roundForPrint(maxValue)}, " + | ||
| "midPrice=${NumberUtils.roundForPrint(midPrice)}, " + | ||
| "maxVolume=${NumberUtils.roundForPrint(maxVolume)}" | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,6 +1,7 @@ | ||
| package com.lykke.matching.engine.order.process | ||
|
|
||
| import com.lykke.matching.engine.balance.BalanceException | ||
| import com.lykke.matching.engine.daos.AssetPair | ||
| import com.lykke.matching.engine.daos.LimitOrder | ||
| import com.lykke.matching.engine.daos.WalletOperation | ||
| import com.lykke.matching.engine.daos.order.OrderTimeInForce | ||
|
|
@@ -45,14 +46,15 @@ class LimitOrderProcessor(private val limitOrderInputValidator: LimitOrderInputV | |
| if (preProcessorValidationResult != null && !preProcessorValidationResult.isValid) { | ||
| return preProcessorValidationResult | ||
| } | ||
| val assetPair = orderContext.executionContext.assetPairsById[orderContext.order.assetPairId] | ||
| // fixme: input validator will be moved from the business thread after multilimit order context release | ||
| val inputValidationResult = performInputValidation(orderContext) | ||
| return if (!inputValidationResult.isValid) inputValidationResult else performBusinessValidation(orderContext) | ||
| val inputValidationResult = performInputValidation(orderContext, assetPair) | ||
| return if (!inputValidationResult.isValid) inputValidationResult else performBusinessValidation(orderContext, assetPair!!) | ||
| } | ||
|
|
||
| private fun performInputValidation(orderContext: LimitOrderExecutionContext): OrderValidationResult { | ||
| private fun performInputValidation(orderContext: LimitOrderExecutionContext, | ||
| assetPair: AssetPair?): OrderValidationResult { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why asset pair is moved to the parameter ? |
||
| val order = orderContext.order | ||
| val assetPair = orderContext.executionContext.assetPairsById[order.assetPairId] | ||
| val baseAsset = assetPair?.let { orderContext.executionContext.assetsById[assetPair.baseAssetId] } | ||
| try { | ||
| limitOrderInputValidator.validateLimitOrder(applicationSettingsHolder.isTrustedClient(order.clientId), | ||
|
|
@@ -66,13 +68,15 @@ class LimitOrderProcessor(private val limitOrderInputValidator: LimitOrderInputV | |
| return OrderValidationResult(true) | ||
| } | ||
|
|
||
| private fun performBusinessValidation(orderContext: LimitOrderExecutionContext): OrderValidationResult { | ||
| private fun performBusinessValidation(orderContext: LimitOrderExecutionContext, | ||
| assetPair: AssetPair): OrderValidationResult { | ||
| val order = orderContext.order | ||
| try { | ||
| limitOrderBusinessValidator.performValidation(applicationSettingsHolder.isTrustedClient(order.clientId), | ||
| order, | ||
| orderContext.availableLimitAssetBalance!!, | ||
| orderContext.limitVolume!!, | ||
| assetPair, | ||
| orderContext.executionContext.orderBooksHolder.getChangedCopyOrOriginalOrderBook(order.assetPairId), | ||
| orderContext.executionContext.date, | ||
| orderContext.executionContext.getOrderBookTotalSize()) | ||
|
|
@@ -129,10 +133,7 @@ class LimitOrderProcessor(private val limitOrderInputValidator: LimitOrderInputV | |
| private fun matchOrder(orderContext: LimitOrderExecutionContext): ProcessedOrder { | ||
| val executionContext = orderContext.executionContext | ||
| val order = orderContext.order | ||
| val orderBook = executionContext.orderBooksHolder.getChangedCopyOrOriginalOrderBook(order.assetPairId) | ||
| val matchingResult = matchingEngine.match(order, | ||
| orderBook.getOrderBook(!order.isBuySide()), | ||
| executionContext.messageId, | ||
| orderContext.availableLimitAssetBalance!!, | ||
| applicationSettingsHolder.limitOrderPriceDeviationThreshold(order.assetPairId), | ||
| executionContext = executionContext) | ||
|
|
||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package com.lykke.matching.engine.services | |
|
|
||
| import com.lykke.matching.engine.daos.LimitOrder | ||
| import com.lykke.matching.engine.services.utils.AbstractAssetOrderBook | ||
| import com.lykke.matching.engine.utils.NumberUtils | ||
| import java.math.BigDecimal | ||
| import java.util.* | ||
| import java.util.concurrent.PriorityBlockingQueue | ||
|
|
@@ -47,6 +48,13 @@ open class AssetOrderBook(assetId: String) : AbstractAssetOrderBook(assetId) { | |
| fun getAskPrice() = askOrderBook.peek()?.price ?: BigDecimal.ZERO | ||
| fun getBidPrice() = bidOrderBook.peek()?.price ?: BigDecimal.ZERO | ||
|
|
||
| fun getMidPrice(): BigDecimal? { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add test for this method |
||
| return if (!NumberUtils.equalsIgnoreScale(BigDecimal.ZERO, getAskPrice()) && !NumberUtils.equalsIgnoreScale(BigDecimal.ZERO, getBidPrice())) { | ||
| NumberUtils.divideWithMaxScale(getAskPrice() + getBidPrice(), BigDecimal.valueOf(2)) | ||
| } else | ||
| null | ||
| } | ||
|
|
||
| fun leadToNegativeSpread(order: LimitOrder): Boolean { | ||
| val book = getOrderBook(!order.isBuySide()) | ||
| if (book.isEmpty()) { | ||
|
|
||
This file contains hidden or 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
12 changes: 6 additions & 6 deletions
12
src/main/kotlin/com/lykke/matching/engine/services/validators/MarketOrderValidator.kt
This file contains hidden or 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,13 +1,13 @@ | ||
| package com.lykke.matching.engine.services.validators | ||
|
|
||
| import com.lykke.matching.engine.daos.v2.FeeInstruction | ||
| import com.lykke.matching.engine.daos.MarketOrder | ||
| import com.lykke.matching.engine.daos.LimitOrder | ||
| import com.lykke.matching.engine.daos.fee.v2.NewFeeInstruction | ||
| import java.util.concurrent.PriorityBlockingQueue | ||
|
|
||
| import com.lykke.matching.engine.daos.v2.FeeInstruction | ||
| import com.lykke.matching.engine.services.AssetOrderBook | ||
|
|
||
| interface MarketOrderValidator { | ||
| fun performValidation(order: MarketOrder, orderBook: PriorityBlockingQueue<LimitOrder>, | ||
| feeInstruction: FeeInstruction?, feeInstructions: List<NewFeeInstruction>?) | ||
| fun performValidation(order: MarketOrder, | ||
| orderBook: AssetOrderBook, | ||
| feeInstruction: FeeInstruction?, | ||
| feeInstructions: List<NewFeeInstruction>?) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there option to configure max volume on back office ? if yes - we should create a ticket to remove it. Also, maybe we should perform dictionary table cleanup - remove unused max volume column?