Created
September 7, 2022 06:49
-
-
Save discountry/42566e35dcda969be178e01005e45e4e to your computer and use it in GitHub Desktop.
how to calculate market order lock volume.
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
| FUSE = '0.9'.to_d | |
| def estimate_required_funds(price_levels) | |
| required_funds = Account::ZERO | |
| expected_volume = volume | |
| start_from, _ = price_levels.first | |
| filled_at = start_from | |
| until expected_volume.zero? || price_levels.empty? | |
| level_price, level_volume = price_levels.shift | |
| filled_at = level_price | |
| v = [expected_volume, level_volume].min | |
| required_funds += yield level_price, v | |
| expected_volume -= v | |
| end | |
| raise "Market is not deep enough" unless expected_volume.zero? | |
| raise "Volume too large" if (filled_at-start_from).abs/start_from > FUSE | |
| required_funds | |
| end | |
| LOCKING_BUFFER_FACTOR = '1.1'.to_d | |
| def compute_locked | |
| case ord_type | |
| when 'limit' | |
| price*volume | |
| when 'market' | |
| funds = estimate_required_funds(Global[currency].asks) {|p, v| p*v } | |
| funds*LOCKING_BUFFER_FACTOR | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment