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

Conversation

aarmoa
Copy link
Contributor

@aarmoa aarmoa commented Aug 10, 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:
Implementation of a new Injective perpetual connector.
The new connector does not require Gateway (pure Python connector) and has been implemented to trade with delegated accounts (ie: the trading account trades in representation of a granter account, that is the one having the funds).

The PR also includes a refactoring to support MARKET orders in both the spot and perpetual connectors when using delegated accounts.

In order to use delegated accounts to trade it is necessary to perform a gran onchain. To send the grant transaction please use the script file hummingbot/connector/exchange/injective_v2/account_delegation_script.py.

Tests performed by the developer:
Created unit tests for all new components.
Tested the connector by running perpetual market making strategies.

Tips for QA testing:
Configure a delegate trading account and test the connector using perpetual strategies.

PRP: https://snapshot.org/#/hbot-prp.eth/proposal/0x7caf486af6d79e38e60b41dd315ad103d437311c57b40386d122b6df373f776c

abel and others added 22 commits August 4, 2023 17:55
…nd trade updates. Also added logic to process orders, trades and balances events.
…account id for both spot and perpetual markets
… the changes added to the Injective data sources when implementing the perpetual markets for delegate accounts
…hen there are no market orders, or no limit orders
…turn trading rules and fees for spot and derivative markets
…to feat/injective_perpetual_with_delegation
…e intention is to simplify the account configuration for the user.
…aults

Feat/injective perpetual offchain vaults
…to feat/injective_perpetual_with_delegation
@rapcmia
Copy link
Contributor

rapcmia commented Aug 18, 2023

  • Test latest 8a11d7a2ce0f and overview on the PR ✅
  • Setup source and build docker image ✅
  • Ran connect command shows injective_v2_perpetual
  • Connect injective_v2_perpetual
    • When setting up network, main_network is selected as default
    • When setting up node, lb is selected as default
    • For account configuration, there is another option read_only_account
      • When read_only_account is used:
        image
        • Checked README, no instructions related to read_only_account
        • No changes on connector status injective_v2_perpetual
        • injective_v2 also now supports the account config

Ran tests on testnet

  • Run account_delegation_script
    image
    • Getting AttributeError: 'tuple' object has no attribute to 'encode'

Steps to reproduce:

  • Add market_ids for testnet exchange
  • Run delegation script

Ran tests on mainnet

  • Mainnet: 4BDF05E89974E86D4BCC84FC90E5F15E71242677A0BEFD6EF623F268AAEE7D43 (INJ/USDT PERP) ✅
  • Connected wallet ✅
  • Setup simple Perp-MM
    • Started ok but with some errors on creating orders:
        RuntimeError: Transaction simulation failure (<AioRpcError of RPC that terminated with:
            status = StatusCode.UNKNOWN
            details = "Stream removed"
            debug_error_string = "UNKNOWN:Error received from peer  {grpc_message:"Stream removed", grpc_status:2, created_time:"2023-08-18T19:14:10.14372+08:00"}"
      

Note: Connector good to be approve once delegation script on testnet is fix. If dev note its a configuration issue, must will check again 🙇🏼

@aarmoa
Copy link
Contributor Author

aarmoa commented Aug 21, 2023

Hello @rapcmia, thank you for the comments.
The read-only account type was added only to allow Hummingbot to get public information from the connector even when it has not been configured by the user yet (for example to get the trading pairs). It can be used to configure the connector, but it will never work because it only provides access to the information that does not require credentials. I added this explanation to the README file.

The error you are experiencing with testnet is due to a problem with the load balanced (lb) testnet nodes. I have added the possibility to use the sentry testnet node, that is working correctly.

@rapcmia
Copy link
Contributor

rapcmia commented Aug 21, 2023

PR update


Setup simple PERP-mm to check testnet using sentry

  • Ran connect injective_v2_perpetual using sentry as node ✅
    image
    • Adding ths behavior when doin preliminary checks, Exchange recovers after few seconds ✅
  • Run balance display wallet assets from granter
  • Start strategy
    • Got an error Failed to fetch trade updates..Received http2 header with status: 503
      2023-08-21 13:07:26,289 - 7069 - hummingbot.connector.derivative.injective_v2_perpetual.injective_v2_perpetual_derivative.InjectiveV2PerpetualDerivative - WARNING - Failed to fetch trade updates. Error: <AioRpcError of RPC that terminated with:
          status = StatusCode.UNAVAILABLE
          details = "Received http2 header with status: 503"
          debug_error_string = "UNKNOWN:Error received from peer  {created_time:"2023-08-21T13:07:26.288853+08:00", grpc_status:14, grpc_message:"Received http2 header with status: 503"}"
      >
      Traceback (most recent call last):
        File "/Users/rapcomia/github/hummingbot/6521/hummingbot/connector/derivative/injective_v2_perpetual/injective_v2_perpetual_derivative.py", line 816, in _update_orders_fills
          trade_updates = await self._data_source.perpetual_trade_updates(market_ids=all_market_ids, start_time=start_time)
        File "/Users/rapcomia/github/hummingbot/6521/hummingbot/connector/exchange/injective_v2/data_sources/injective_data_source.py", line 586, in perpetual_trade_updates
          trades_response = await self.query_executor.get_derivative_trades(
        File "/Users/rapcomia/github/hummingbot/6521/hummingbot/connector/exchange/injective_v2/injective_query_executor.py", line 288, in get_derivative_trades
          response = await self._sdk_client.get_derivative_trades(
        File "/Users/rapcomia/anaconda3/envs/hummingbot/lib/python3.10/site-packages/pyinjective/async_client.py", line 844, in get_derivative_trades
          return await self.stubDerivativeExchange.Trades(req)
        File "/Users/rapcomia/anaconda3/envs/hummingbot/lib/python3.10/site-packages/grpc/aio/_call.py", line 306, in __await__
          raise _create_rpc_error(
      grpc.aio._call.AioRpcError: <AioRpcError of RPC that terminated with:
          status = StatusCode.UNAVAILABLE
          details = "Received http2 header with status: 503"
          debug_error_string = "UNKNOWN:Error received from peer  {created_time:"2023-08-21T13:07:26.288853+08:00", grpc_status:14, grpc_message:"Received http2 header with status: 503"}"
      >
      
    • Observed:
      • Order successfully created and cancel base on txns submitted here
      • There are instances of network status disconnection resulting to:
        • failed and unexpected fetch trade orders
        • Cancellation of order stuck or delayed
        • When network status reconnected, orders are cancelled successfully
      • Ran the bot for few hours to check:
        • Position open and close, unfortunately not able to due to testnet market movements

Note:

  • We are assuming these errors are related to the testnet exchange. When this happens, the connector still recovers from it.
  • Currently running for few hours to observe pending tests, once completed PR should be good to be approve, thank you

Attached logs for reference
logs_perp-injectiv-v2.log

Copy link
Contributor

@rapcmia rapcmia left a comment

Choose a reason for hiding this comment

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

LGTM

  • Setup connector without the need of Gateway
  • Account delegation script works for mainnet and testnet
    • Testnet now has option to use "sentry"
  • Connect wallet successful and balance shows assets of the granter
  • Connect wallet to mainnet and testnet ok
  • Setting up the connector defaults to mainnet settings and use must remove base on preference.
  • Account configuration now has another option read_account, info available on README
  • Setup simple PerpMM
  • (mainnet) There are still noticeable issues found on mainnet similar to spot
  • (testnet)
    • Observe orders are successfully created and cancelled
    • Also there are instances of network getting disconnected causing orders fetch failed but connector recovers after few minutes
    • Not able to open and close position due to testnet markets but observed working just fine.
  • Docker build ok

Note:

  • Connector has been tested base on bronze standard and should work ok. Community can prcoeed with using the connector at ease else open a ticket and have injective team to look and fix.

Copy link
Contributor

@cardosofede cardosofede left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for adding the position to the missing places

@cardosofede cardosofede merged commit 9ab9981 into hummingbot:development Aug 21, 2023
2 checks passed
@aarmoa aarmoa deleted the feat/injective_perpetual_with_delegation branch August 21, 2023 16:45
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.

None yet

3 participants