Skip to content

Commit

Permalink
Merge pull request hummingbot#9 from aarmoa/feat/injective_perpetual_…
Browse files Browse the repository at this point in the history
…offchain_vaults

Feat/injective perpetual offchain vaults
  • Loading branch information
aarmoa authored Aug 16, 2023
2 parents 42465b0 + 9b5c596 commit 5024164
Show file tree
Hide file tree
Showing 12 changed files with 3,315 additions and 94 deletions.
2 changes: 2 additions & 0 deletions hummingbot/client/config/config_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def get_default_str_repr(self, attr_name: str) -> str:
default_str = ""
elif isinstance(default, (List, Tuple)):
default_str = ",".join(default)
elif isinstance(default, BaseClientModel):
default_str = default.Config.title
else:
default_str = str(default)
return default_str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ async def cancel_all(self, timeout_seconds: float) -> List[CancellationResult]:
failed_cancellations = [CancellationResult(oid, False) for oid in incomplete_orders.keys()]
return successful_cancellations + failed_cancellations

async def cancel_all_subaccount_orders(self):
markets_ids = [await self.exchange_symbol_associated_to_pair(trading_pair=trading_pair)
for trading_pair in self.trading_pairs]
await self._data_source.cancel_all_subaccount_orders(perpetual_markets_ids=markets_ids)

async def check_network(self) -> NetworkStatus:
"""
Checks connectivity with the exchange using the API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from hummingbot.connector.exchange.injective_v2.injective_v2_utils import (
ACCOUNT_MODES,
NETWORK_MODES,
InjectiveDelegatedAccountMode,
InjectiveMainnetNetworkMode,
InjectiveReadOnlyAccountMode,
)
from hummingbot.core.data_type.trade_fee import TradeFeeSchema

Expand Down Expand Up @@ -37,12 +37,7 @@ class InjectiveConfigMap(BaseConnectorConfigMap):
),
)
account_type: Union[tuple(ACCOUNT_MODES.values())] = Field(
default=InjectiveDelegatedAccountMode(
private_key="0000000000000000000000000000000000000000000000000000000000000001", # noqa: mock
subaccount_index=0,
granter_address="inj10e0525sfrf53yh2aljmm3sn9jq5njk7lwfmzjf", # noqa: mock
granter_subaccount_index=0,
),
default=InjectiveReadOnlyAccountMode(),
client_data=ClientFieldData(
prompt=lambda cm: f"Select the type of account configuration ({'/'.join(list(ACCOUNT_MODES.keys()))})",
prompt_on_new=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,23 @@ async def cancel_orders(

return results

async def cancel_all_subaccount_orders(
self,
spot_markets_ids: Optional[List[str]] = None,
perpetual_markets_ids: Optional[List[str]] = None,
):
spot_markets_ids = spot_markets_ids or []
perpetual_markets_ids = perpetual_markets_ids or []

delegated_message = self._all_subaccount_orders_cancel_message(
spot_markets_ids=spot_markets_ids,
derivative_markets_ids=perpetual_markets_ids,
)

result = await self._send_in_transaction(messages=[delegated_message])
if result["rawLog"] != "[]":
raise ValueError(f"Error sending the order cancel transaction ({result['rawLog']})")

async def spot_trade_updates(self, market_ids: List[str], start_time: float) -> List[TradeUpdate]:
done = False
skip = 0
Expand Down Expand Up @@ -749,6 +766,14 @@ def _order_cancel_message(
) -> any_pb2.Any:
raise NotImplementedError

@abstractmethod
def _all_subaccount_orders_cancel_message(
self,
spot_markets_ids: List[str],
derivative_markets_ids: List[str]
) -> any_pb2.Any:
raise NotImplementedError

@abstractmethod
def _generate_injective_order_data(self, order: GatewayInFlightOrder, market_id: str) -> injective_exchange_tx_pb.OrderData:
raise NotImplementedError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(
self._is_trading_account_initialized = False
self._markets_initialization_lock = asyncio.Lock()
self._spot_market_info_map: Optional[Dict[str, InjectiveSpotMarket]] = None
self._derivative_market_info_map: Optional[Dict[str, InjectiveSpotMarket]] = None
self._derivative_market_info_map: Optional[Dict[str, InjectiveDerivativeMarket]] = None
self._spot_market_and_trading_pair_map: Optional[Mapping[str, str]] = None
self._derivative_market_and_trading_pair_map: Optional[Mapping[str, str]] = None
self._tokens_map: Optional[Dict[str, InjectiveToken]] = None
Expand Down Expand Up @@ -589,6 +589,25 @@ def _order_cancel_message(
)
return delegated_message

def _all_subaccount_orders_cancel_message(
self,
spot_markets_ids: List[str],
derivative_markets_ids: List[str]
) -> any_pb2.Any:
composer = self.composer

message = composer.MsgBatchUpdateOrders(
sender=self.portfolio_account_injective_address,
subaccount_id=self.portfolio_account_subaccount_id,
spot_market_ids_to_cancel_all=spot_markets_ids,
derivative_market_ids_to_cancel_all=derivative_markets_ids,
)
delegated_message = composer.MsgExec(
grantee=self.trading_account_injective_address,
msgs=[message]
)
return delegated_message

def _generate_injective_order_data(self, order: GatewayInFlightOrder, market_id: str) -> injective_exchange_tx_pb.OrderData:
order_data = self.composer.OrderData(
market_id=market_id,
Expand Down
Loading

0 comments on commit 5024164

Please sign in to comment.