Skip to content
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

Feat/injective w batch update #302

Closed

Conversation

petioptrv
Copy link

@petioptrv petioptrv commented Jan 23, 2023

Before submitting this PR, please make sure:

  • Your code builds clean without any errors or warnings
  • You are using approved title ("feat/", "fix/", "docs/", "refactor/")

A description of the changes proposed in the pull request:

This PR introduces batch order creation and cancelation for the client.

The functionality is implemented with backward compatibility.

The Injective connector is refactored to provide this enhanced order management.

Tests performed by the developer:

Added tests for the new functionality.

Tips for QA testing:

Please test that each exchange works with a normal PMM strategy, as well as with the new batch_order_update.py script. The script strategy has four phases:

  1. Two orders are placed successfully.
  2. Then the orders are canceled successfully.
  3. After that, two more orders are attempted; one order is placed successfully and one order fails due to the amount being zero. Here, the bot should log the failed event appropriately.
  4. Finally, the existing order is canceled.

The script begins by setting some global variables

CONNECTOR = "okx"
TRADING_PAIR = combine_to_hb_trading_pair(base="BTC", quote="USDT")
AMOUNT = Decimal("0.0001")
ORDERS_INTERVAL = 10
PRICE_OFFSET_RATIO = Decimal("0.1")  # 10%

The ORDERS_INTERVAL variable is the number of ticks (seconds) between each of the script phases. The PRICE_OFFSET_RATIO variable sets the orders' prices at 10% from the current mid-market price.

vic-en and others added 10 commits January 14, 2023 23:14
# Conflicts:
#	hummingbot/connector/gateway/amm/gateway_evm_amm.py
#	hummingbot/connector/test_support/exchange_connector_test.py
…date

# Conflicts:
#	hummingbot/connector/gateway/clob_spot/data_sources/injective/injective_api_data_source.py
- Splits batch order updating into batch order creation and batch order cancelation methods.
- Updates the rest of the `ExchangePyBase` class to take full advantage of the new methods.
- Adds tests for the new functionality.
@petioptrv petioptrv requested a review from a team January 23, 2023 13:41
@petioptrv
Copy link
Author

petioptrv commented Jan 23, 2023

@CoinAlpha/qa-team, please note that Injective will be failing, as with the parent PR, so no need to test Injective for now, but the rest of the exchanges can be tested.

Copy link

@aarmoa aarmoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petioptrv let's coordinate a meeting to discuss the current approach.

Comment on lines +9 to +10
@dataclass
class Order:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need yet a new order class? Why can't we use LimitOrder or OrderCandidate as the class to represent an order between the strategy and the connector?


@dataclass
class PlaceOrderResult:
success: bool
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think success should not be a flag. It should be derived from the fact that there is or there is not an exception

Comment on lines +36 to +38
exchange_order_id: Optional[str]
trading_pair: str
misc_updates: Dict[str, Any] = field(default_factory=lambda: {})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only disclose information from the connector to the strategy that does not expose internal connector implementation. I think exchange_order_id and misc_updates should not be here

Comment on lines +47 to +48
misc_updates: Dict[str, Any] = field(default_factory=lambda: {})
not_found: bool = False
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think misc_updates should be disclosed to the strategy, at least not as the response to the cancel message (if we need any information in particular in the strategy should be included in the cancel event). The not_found condition shouldn't be here either (the strategy will receive an order failed event if the order is no longer valid)

Comment on lines +45 to +46
client_order_id: str
trading_pair: str
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to just include here an order object (an instance of the class we finally decide to use to communicate strategies and connectors)

@@ -1219,3 +1220,37 @@ async def clob_cancel_order(
"orderId": exchange_order_id,
}
return await self.api_request("delete", "clob/orders", request_payload)

async def clob_batch_order_update(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct to call the method batch_order_update? In the client the "update" term is in general reserved for when we look for updates on the status of a currently existing order. I don't think that apply to order creation. And for order cancelation we are not trying to update our local status with the server status. We are requesting an action on the order.

Comment on lines +706 to +711
cancelation_results = [
CancellationResult(order_id=cancel_order_result.client_order_id, success=cancel_order_result.success)
for cancel_order_result in cancel_order_results
]
for cancel_order_result in cancel_order_results:
if cancel_order_result.success:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a good idea to cycle the collection of cancel_order_results twice

@petioptrv petioptrv marked this pull request as draft January 27, 2023 05:51
@petioptrv
Copy link
Author

Converting this PR to draft in favour of this PR, which will be submitted to foundation.

@petioptrv petioptrv closed this Feb 16, 2023
@petioptrv petioptrv deleted the feat/injective_w_batch_update branch February 16, 2023 02:14
@james-hummingbot
Copy link

The gateway side is in this PR: CoinAlpha/gateway#4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed Test PR #302 - Failing to cancel order using the batch order script
5 participants