Skip to content

Commit 5024164

Browse files
authored
Merge pull request #9 from aarmoa/feat/injective_perpetual_offchain_vaults
Feat/injective perpetual offchain vaults
2 parents 42465b0 + 9b5c596 commit 5024164

File tree

12 files changed

+3315
-94
lines changed

12 files changed

+3315
-94
lines changed

hummingbot/client/config/config_helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ def get_default_str_repr(self, attr_name: str) -> str:
228228
default_str = ""
229229
elif isinstance(default, (List, Tuple)):
230230
default_str = ",".join(default)
231+
elif isinstance(default, BaseClientModel):
232+
default_str = default.Config.title
231233
else:
232234
default_str = str(default)
233235
return default_str

hummingbot/connector/derivative/injective_v2_perpetual/injective_v2_perpetual_derivative.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ async def cancel_all(self, timeout_seconds: float) -> List[CancellationResult]:
266266
failed_cancellations = [CancellationResult(oid, False) for oid in incomplete_orders.keys()]
267267
return successful_cancellations + failed_cancellations
268268

269+
async def cancel_all_subaccount_orders(self):
270+
markets_ids = [await self.exchange_symbol_associated_to_pair(trading_pair=trading_pair)
271+
for trading_pair in self.trading_pairs]
272+
await self._data_source.cancel_all_subaccount_orders(perpetual_markets_ids=markets_ids)
273+
269274
async def check_network(self) -> NetworkStatus:
270275
"""
271276
Checks connectivity with the exchange using the API

hummingbot/connector/derivative/injective_v2_perpetual/injective_v2_perpetual_utils.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from hummingbot.connector.exchange.injective_v2.injective_v2_utils import (
99
ACCOUNT_MODES,
1010
NETWORK_MODES,
11-
InjectiveDelegatedAccountMode,
1211
InjectiveMainnetNetworkMode,
12+
InjectiveReadOnlyAccountMode,
1313
)
1414
from hummingbot.core.data_type.trade_fee import TradeFeeSchema
1515

@@ -37,12 +37,7 @@ class InjectiveConfigMap(BaseConnectorConfigMap):
3737
),
3838
)
3939
account_type: Union[tuple(ACCOUNT_MODES.values())] = Field(
40-
default=InjectiveDelegatedAccountMode(
41-
private_key="0000000000000000000000000000000000000000000000000000000000000001", # noqa: mock
42-
subaccount_index=0,
43-
granter_address="inj10e0525sfrf53yh2aljmm3sn9jq5njk7lwfmzjf", # noqa: mock
44-
granter_subaccount_index=0,
45-
),
40+
default=InjectiveReadOnlyAccountMode(),
4641
client_data=ClientFieldData(
4742
prompt=lambda cm: f"Select the type of account configuration ({'/'.join(list(ACCOUNT_MODES.keys()))})",
4843
prompt_on_new=True,

hummingbot/connector/exchange/injective_v2/data_sources/injective_data_source.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,23 @@ async def cancel_orders(
532532

533533
return results
534534

535+
async def cancel_all_subaccount_orders(
536+
self,
537+
spot_markets_ids: Optional[List[str]] = None,
538+
perpetual_markets_ids: Optional[List[str]] = None,
539+
):
540+
spot_markets_ids = spot_markets_ids or []
541+
perpetual_markets_ids = perpetual_markets_ids or []
542+
543+
delegated_message = self._all_subaccount_orders_cancel_message(
544+
spot_markets_ids=spot_markets_ids,
545+
derivative_markets_ids=perpetual_markets_ids,
546+
)
547+
548+
result = await self._send_in_transaction(messages=[delegated_message])
549+
if result["rawLog"] != "[]":
550+
raise ValueError(f"Error sending the order cancel transaction ({result['rawLog']})")
551+
535552
async def spot_trade_updates(self, market_ids: List[str], start_time: float) -> List[TradeUpdate]:
536553
done = False
537554
skip = 0
@@ -749,6 +766,14 @@ def _order_cancel_message(
749766
) -> any_pb2.Any:
750767
raise NotImplementedError
751768

769+
@abstractmethod
770+
def _all_subaccount_orders_cancel_message(
771+
self,
772+
spot_markets_ids: List[str],
773+
derivative_markets_ids: List[str]
774+
) -> any_pb2.Any:
775+
raise NotImplementedError
776+
752777
@abstractmethod
753778
def _generate_injective_order_data(self, order: GatewayInFlightOrder, market_id: str) -> injective_exchange_tx_pb.OrderData:
754779
raise NotImplementedError

hummingbot/connector/exchange/injective_v2/data_sources/injective_grantee_data_source.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(
8383
self._is_trading_account_initialized = False
8484
self._markets_initialization_lock = asyncio.Lock()
8585
self._spot_market_info_map: Optional[Dict[str, InjectiveSpotMarket]] = None
86-
self._derivative_market_info_map: Optional[Dict[str, InjectiveSpotMarket]] = None
86+
self._derivative_market_info_map: Optional[Dict[str, InjectiveDerivativeMarket]] = None
8787
self._spot_market_and_trading_pair_map: Optional[Mapping[str, str]] = None
8888
self._derivative_market_and_trading_pair_map: Optional[Mapping[str, str]] = None
8989
self._tokens_map: Optional[Dict[str, InjectiveToken]] = None
@@ -589,6 +589,25 @@ def _order_cancel_message(
589589
)
590590
return delegated_message
591591

592+
def _all_subaccount_orders_cancel_message(
593+
self,
594+
spot_markets_ids: List[str],
595+
derivative_markets_ids: List[str]
596+
) -> any_pb2.Any:
597+
composer = self.composer
598+
599+
message = composer.MsgBatchUpdateOrders(
600+
sender=self.portfolio_account_injective_address,
601+
subaccount_id=self.portfolio_account_subaccount_id,
602+
spot_market_ids_to_cancel_all=spot_markets_ids,
603+
derivative_market_ids_to_cancel_all=derivative_markets_ids,
604+
)
605+
delegated_message = composer.MsgExec(
606+
grantee=self.trading_account_injective_address,
607+
msgs=[message]
608+
)
609+
return delegated_message
610+
592611
def _generate_injective_order_data(self, order: GatewayInFlightOrder, market_id: str) -> injective_exchange_tx_pb.OrderData:
593612
order_data = self.composer.OrderData(
594613
market_id=market_id,

0 commit comments

Comments
 (0)