|
| 1 | +import math |
1 | 2 | from decimal import Decimal |
2 | 3 |
|
3 | 4 | import pytest |
|
13 | 14 | DERIVATIVE_ORDER_CANCELATION_GAS_LIMIT, |
14 | 15 | DERIVATIVE_ORDER_CREATION_GAS_LIMIT, |
15 | 16 | EXTERNAL_TRANSFER_GAS_LIMIT, |
| 17 | + GTB_ORDERS_GAS_MULTIPLIER, |
16 | 18 | INCREASE_POSITION_MARGIN_TRANSFER_GAS_LIMIT, |
17 | 19 | POST_ONLY_BINARY_OPTIONS_ORDER_CREATION_GAS_LIMIT, |
18 | 20 | POST_ONLY_DERIVATIVE_ORDER_CREATION_GAS_LIMIT, |
@@ -498,6 +500,44 @@ def test_estimation_for_create_spot_limit_order(self, basic_composer, inj_usdt_s |
498 | 500 |
|
499 | 501 | assert expected_gas_cost == estimator.gas_limit() |
500 | 502 |
|
| 503 | + def test_estimation_for_create_gtb_spot_limit_order(self, basic_composer, inj_usdt_spot_market): |
| 504 | + composer = basic_composer |
| 505 | + market_id = inj_usdt_spot_market.id |
| 506 | + |
| 507 | + message = composer.msg_create_spot_limit_order_v2( |
| 508 | + market_id=market_id, |
| 509 | + sender="senders", |
| 510 | + subaccount_id="subaccount_id", |
| 511 | + fee_recipient="fee_recipient", |
| 512 | + price=Decimal("7.523"), |
| 513 | + quantity=Decimal("0.01"), |
| 514 | + order_type="BUY", |
| 515 | + expiration_block=1234567, |
| 516 | + ) |
| 517 | + estimator = GasHeuristicsGasLimitEstimator.for_message(message=message) |
| 518 | + |
| 519 | + expected_gas_cost = math.ceil(Decimal(SPOT_ORDER_CREATION_GAS_LIMIT) * Decimal(GTB_ORDERS_GAS_MULTIPLIER)) |
| 520 | + |
| 521 | + assert expected_gas_cost == estimator.gas_limit() |
| 522 | + |
| 523 | + po_order_message = composer.msg_create_spot_limit_order_v2( |
| 524 | + market_id=market_id, |
| 525 | + sender="senders", |
| 526 | + subaccount_id="subaccount_id", |
| 527 | + fee_recipient="fee_recipient", |
| 528 | + price=Decimal("7.523"), |
| 529 | + quantity=Decimal("0.01"), |
| 530 | + order_type="BUY_PO", |
| 531 | + expiration_block=1234567, |
| 532 | + ) |
| 533 | + estimator = GasHeuristicsGasLimitEstimator.for_message(message=po_order_message) |
| 534 | + |
| 535 | + expected_gas_cost = math.ceil( |
| 536 | + Decimal(POST_ONLY_SPOT_ORDER_CREATION_GAS_LIMIT) * Decimal(GTB_ORDERS_GAS_MULTIPLIER) |
| 537 | + ) |
| 538 | + |
| 539 | + assert expected_gas_cost == estimator.gas_limit() |
| 540 | + |
501 | 541 | def test_estimation_for_create_spot_market_order(self, basic_composer, inj_usdt_spot_market): |
502 | 542 | composer = basic_composer |
503 | 543 | market_id = inj_usdt_spot_market.id |
@@ -569,6 +609,46 @@ def test_estimation_for_create_derivative_limit_order(self, basic_composer, btc_ |
569 | 609 |
|
570 | 610 | assert expected_gas_cost == estimator.gas_limit() |
571 | 611 |
|
| 612 | + def test_estimation_for_create_gtb_derivative_limit_order(self, basic_composer, btc_usdt_perp_market): |
| 613 | + composer = basic_composer |
| 614 | + market_id = btc_usdt_perp_market.id |
| 615 | + |
| 616 | + message = composer.msg_create_derivative_limit_order_v2( |
| 617 | + market_id=market_id, |
| 618 | + sender="senders", |
| 619 | + subaccount_id="subaccount_id", |
| 620 | + fee_recipient="fee_recipient", |
| 621 | + price=Decimal("7.523"), |
| 622 | + quantity=Decimal("0.01"), |
| 623 | + margin=Decimal("7.523") * Decimal("0.01"), |
| 624 | + order_type="BUY", |
| 625 | + expiration_block=1234567, |
| 626 | + ) |
| 627 | + estimator = GasHeuristicsGasLimitEstimator.for_message(message=message) |
| 628 | + |
| 629 | + expected_gas_cost = math.ceil(Decimal(DERIVATIVE_ORDER_CREATION_GAS_LIMIT) * Decimal(GTB_ORDERS_GAS_MULTIPLIER)) |
| 630 | + |
| 631 | + assert expected_gas_cost == estimator.gas_limit() |
| 632 | + |
| 633 | + po_order_message = composer.msg_create_derivative_limit_order_v2( |
| 634 | + market_id=market_id, |
| 635 | + sender="senders", |
| 636 | + subaccount_id="subaccount_id", |
| 637 | + fee_recipient="fee_recipient", |
| 638 | + price=Decimal("7.523"), |
| 639 | + quantity=Decimal("0.01"), |
| 640 | + margin=Decimal("7.523") * Decimal("0.01"), |
| 641 | + order_type="BUY_PO", |
| 642 | + expiration_block=1234567, |
| 643 | + ) |
| 644 | + estimator = GasHeuristicsGasLimitEstimator.for_message(message=po_order_message) |
| 645 | + |
| 646 | + expected_gas_cost = math.ceil( |
| 647 | + Decimal(POST_ONLY_DERIVATIVE_ORDER_CREATION_GAS_LIMIT) * Decimal(GTB_ORDERS_GAS_MULTIPLIER) |
| 648 | + ) |
| 649 | + |
| 650 | + assert expected_gas_cost == estimator.gas_limit() |
| 651 | + |
572 | 652 | def test_estimation_for_create_derivative_market_order(self, basic_composer, btc_usdt_perp_market): |
573 | 653 | composer = basic_composer |
574 | 654 | market_id = btc_usdt_perp_market.id |
@@ -641,6 +721,48 @@ def test_estimation_for_create_binary_options_limit_order(self, basic_composer, |
641 | 721 |
|
642 | 722 | assert expected_gas_cost == estimator.gas_limit() |
643 | 723 |
|
| 724 | + def test_estimation_for_create_gtb_binary_options_limit_order(self, basic_composer, first_match_bet_market): |
| 725 | + composer = basic_composer |
| 726 | + market_id = first_match_bet_market.id |
| 727 | + |
| 728 | + message = composer.msg_create_binary_options_limit_order_v2( |
| 729 | + market_id=market_id, |
| 730 | + sender="senders", |
| 731 | + subaccount_id="subaccount_id", |
| 732 | + fee_recipient="fee_recipient", |
| 733 | + price=Decimal("0.5"), |
| 734 | + quantity=Decimal("10"), |
| 735 | + margin=Decimal("0.5") * Decimal("10"), |
| 736 | + order_type="BUY", |
| 737 | + expiration_block=1234567, |
| 738 | + ) |
| 739 | + estimator = GasHeuristicsGasLimitEstimator.for_message(message=message) |
| 740 | + |
| 741 | + expected_gas_cost = math.ceil( |
| 742 | + Decimal(BINARY_OPTIONS_ORDER_CREATION_GAS_LIMIT) * Decimal(GTB_ORDERS_GAS_MULTIPLIER) |
| 743 | + ) |
| 744 | + |
| 745 | + assert expected_gas_cost == estimator.gas_limit() |
| 746 | + |
| 747 | + po_order_message = composer.msg_create_binary_options_limit_order_v2( |
| 748 | + market_id=market_id, |
| 749 | + sender="senders", |
| 750 | + subaccount_id="subaccount_id", |
| 751 | + fee_recipient="fee_recipient", |
| 752 | + price=Decimal("0.5"), |
| 753 | + quantity=Decimal("10"), |
| 754 | + margin=Decimal("0.5") * Decimal("10"), |
| 755 | + order_type="BUY_PO", |
| 756 | + expiration_block=1234567, |
| 757 | + ) |
| 758 | + estimator = GasHeuristicsGasLimitEstimator.for_message(message=po_order_message) |
| 759 | + |
| 760 | + expected_gas_cost = math.ceil( |
| 761 | + Decimal(POST_ONLY_BINARY_OPTIONS_ORDER_CREATION_GAS_LIMIT) * Decimal(GTB_ORDERS_GAS_MULTIPLIER) |
| 762 | + ) |
| 763 | + |
| 764 | + assert expected_gas_cost == estimator.gas_limit() |
| 765 | + |
644 | 766 | def test_estimation_for_create_binary_options_market_order(self, basic_composer, first_match_bet_market): |
645 | 767 | composer = basic_composer |
646 | 768 | market_id = first_match_bet_market.id |
|
0 commit comments