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 perpetual with delegation #6521

Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d1b7736
(feat) Implemented Injective V2 order book data source with its tests
Jul 27, 2023
7468152
(feat) Added logic in Injective v2 connector to create and cancel ord…
Jul 31, 2023
3eb7595
(feat) Added logic in Injective V2 perpetual connector to get order a…
Aug 3, 2023
3f1a524
(feat) Added logic to process position updates in Injective V2 perpet…
Aug 4, 2023
5d35af9
(fix) Fix for order creation in delegate accounts to use the full sub…
Aug 4, 2023
df1f8bb
Merge branch 'feat/injective_spot_offline_vaults' of https://github.c…
Aug 5, 2023
81bae58
(fix) Solved issues after merging the latest changes from the Injecti…
Aug 5, 2023
e1ad256
(fix) Added fix in order candidate to avoid amount adjustment when cu…
Aug 7, 2023
6c6aaf5
(feat) Added logic in the delegate account data source to support MAR…
Aug 8, 2023
2fae026
(fix) Added support for MARKET orders in the derivatives Injective v2…
Aug 8, 2023
9f87776
(fix) Refactored the offchain vault data source to be compatible with…
Aug 9, 2023
6bf3406
(fix) Fixed the calculation of order hashes to support the scenario w…
Aug 9, 2023
3b9a79f
(fix) Refactored injective data source to have separate methods to re…
Aug 9, 2023
748febc
(fix) Changed stream processors to regenerate a stream channel when i…
Aug 10, 2023
42465b0
Merge branch 'development' of https://github.com/aarmoa/hummingbot in…
Aug 10, 2023
060ffde
(feat) Added support for off-chain vaults trading in Injective V2 Per…
Aug 14, 2023
cea2b56
(feat) Added new type of account mode for Injective for read-only. Th…
Aug 14, 2023
86026f0
(fix) Fix string representation of configuration models
Aug 14, 2023
9b5c596
(feat) Added logic in Injective v2 connectors to cancel all orders fo…
Aug 15, 2023
5024164
Merge pull request #9 from aarmoa/feat/injective_perpetual_offchain_v…
aarmoa Aug 16, 2023
dfea808
Merge branch 'development' of https://github.com/aarmoa/hummingbot in…
Aug 17, 2023
8a11d7a
(fix) Solved Flake8 error
Aug 17, 2023
19f0154
Merge branch 'development' into feat/injective_perpetual_with_delegation
rapcmia Aug 21, 2023
57631c1
(feat) Allow the connection to the "sentry" testnet node
Aug 21, 2023
ae24fd7
Merge branch 'feat/injective_perpetual_with_delegation' of https://gi…
Aug 21, 2023
dbe2a64
Merge branch 'development' into feat/injective_perpetual_with_delegation
rapcmia Aug 21, 2023
b2b5a6c
(fix) Fixed failing tests
Aug 21, 2023
16e750a
Merge branch 'feat/injective_perpetual_with_delegation' of https://gi…
Aug 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Expand Up @@ -25,7 +25,7 @@ jobs:
if: env.GIT_DIFF
run: |
echo ${{ env.GIT_DIFF }}
echo "{is_set}={true}" >> $GITHUB_OUTPUT
echo "::set-output name=is_set::true"

build_hummingbot:
name: Hummingbot build + stable tests
Expand Down
4 changes: 3 additions & 1 deletion hummingbot/client/config/config_helpers.py
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 Expand Up @@ -809,7 +811,7 @@ def save_to_yml_legacy(yml_path: str, cm: Dict[str, ConfigVar]):
data = yaml_parser.load(stream) or {}
for key in cm:
cvar = cm.get(key)
if type(cvar.value) == Decimal:
if isinstance(cvar.value, Decimal):
data[key] = float(cvar.value)
else:
data[key] = cvar.value
Expand Down
1 change: 1 addition & 0 deletions hummingbot/connector/connector_status.py
Expand Up @@ -62,6 +62,7 @@
'vertex': 'bronze',
'vertex_testnet': 'bronze',
'injective_v2': 'bronze',
'injective_v2_perpetual': 'bronze',
}

warning_messages = {
Expand Down
@@ -0,0 +1,4 @@
## Injective v2 Perpetual

This is a perpetual connector created by **[Injective Labs](https://injectivelabs.org/)**.
The description and configuration steps for the perpetual connector are identical to the spot connector. Please check the README file in the Injective v2 spot connector folder.
@@ -0,0 +1,14 @@
from hummingbot.connector.exchange.injective_v2 import injective_constants as CONSTANTS

EXCHANGE_NAME = "injective_v2_perpetual"

DEFAULT_DOMAIN = ""
TESTNET_DOMAIN = "testnet"

TRANSACTIONS_CHECK_INTERVAL = CONSTANTS.TRANSACTIONS_CHECK_INTERVAL

RATE_LIMITS = CONSTANTS.RATE_LIMITS

ORDER_STATE_MAP = CONSTANTS.ORDER_STATE_MAP

ORDER_NOT_FOUND_ERROR_MESSAGE = CONSTANTS.ORDER_NOT_FOUND_ERROR_MESSAGE
@@ -0,0 +1,93 @@
import asyncio
from typing import TYPE_CHECKING, Any, Dict, List, Optional

from hummingbot.connector.derivative.injective_v2_perpetual import injective_constants as CONSTANTS
from hummingbot.connector.exchange.injective_v2.data_sources.injective_data_source import InjectiveDataSource
from hummingbot.core.data_type.funding_info import FundingInfo, FundingInfoUpdate
from hummingbot.core.data_type.order_book_message import OrderBookMessage
from hummingbot.core.data_type.perpetual_api_order_book_data_source import PerpetualAPIOrderBookDataSource
from hummingbot.core.event.event_forwarder import EventForwarder
from hummingbot.core.event.events import MarketEvent, OrderBookDataSourceEvent

if TYPE_CHECKING:
from hummingbot.connector.derivative.injective_v2_perpetual.injective_v2_perpetual_derivative import (
InjectiveV2Dericative,
)


class InjectiveV2PerpetualAPIOrderBookDataSource(PerpetualAPIOrderBookDataSource):

def __init__(
self,
trading_pairs: List[str],
connector: "InjectiveV2Dericative",
data_source: InjectiveDataSource,
domain: str = CONSTANTS.DEFAULT_DOMAIN,
):
super().__init__(trading_pairs=trading_pairs)
self._ev_loop = asyncio.get_event_loop()
self._connector = connector
self._data_source = data_source
self._domain = domain
self._forwarders = []
self._configure_event_forwarders()

async def get_funding_info(self, trading_pair: str) -> FundingInfo:
market_id = await self._connector.exchange_symbol_associated_to_pair(trading_pair=trading_pair)
funding_info = await self._data_source.funding_info(market_id=market_id)

return funding_info

async def get_last_traded_prices(self, trading_pairs: List[str], domain: Optional[str] = None) -> Dict[str, float]:
return await self._connector.get_last_traded_prices(trading_pairs=trading_pairs)

async def listen_for_subscriptions(self):
# Subscriptions to streams is handled by the data_source
# Here we just make sure the data_source is listening to the streams
market_ids = [await self._connector.exchange_symbol_associated_to_pair(trading_pair=trading_pair)
for trading_pair in self._trading_pairs]
await self._data_source.start(market_ids=market_ids)

async def _order_book_snapshot(self, trading_pair: str) -> OrderBookMessage:
symbol = await self._connector.exchange_symbol_associated_to_pair(trading_pair=trading_pair)
snapshot = await self._data_source.perpetual_order_book_snapshot(market_id=symbol, trading_pair=trading_pair)
return snapshot

async def _parse_order_book_diff_message(self, raw_message: OrderBookMessage, message_queue: asyncio.Queue):
# In Injective 'raw_message' is not a raw message, but the OrderBookMessage with type Trade created
# by the data source
message_queue.put_nowait(raw_message)

async def _parse_trade_message(self, raw_message: OrderBookMessage, message_queue: asyncio.Queue):
# In Injective 'raw_message' is not a raw message, but the OrderBookMessage with type Trade created
# by the data source
message_queue.put_nowait(raw_message)

async def _parse_funding_info_message(self, raw_message: Dict[str, Any], message_queue: asyncio.Queue):
# In Injective 'raw_message' is not a raw message, but the FundingInfoUpdate created
# by the data source
message_queue.put_nowait(raw_message)

def _configure_event_forwarders(self):
event_forwarder = EventForwarder(to_function=self._process_order_book_event)
self._forwarders.append(event_forwarder)
self._data_source.add_listener(
event_tag=OrderBookDataSourceEvent.DIFF_EVENT, listener=event_forwarder
)

event_forwarder = EventForwarder(to_function=self._process_public_trade_event)
self._forwarders.append(event_forwarder)
self._data_source.add_listener(event_tag=OrderBookDataSourceEvent.TRADE_EVENT, listener=event_forwarder)

event_forwarder = EventForwarder(to_function=self._process_funding_info_event)
self._forwarders.append(event_forwarder)
self._data_source.add_listener(event_tag=MarketEvent.FundingInfo, listener=event_forwarder)

def _process_order_book_event(self, order_book_diff: OrderBookMessage):
self._message_queue[self._diff_messages_queue_key].put_nowait(order_book_diff)

def _process_public_trade_event(self, trade_update: OrderBookMessage):
self._message_queue[self._trade_messages_queue_key].put_nowait(trade_update)

def _process_funding_info_event(self, funding_info_update: FundingInfoUpdate):
self._message_queue[self._funding_info_messages_queue_key].put_nowait(funding_info_update)