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 #81

Merged
merged 61 commits into from
Apr 20, 2023

Conversation

petioptrv
Copy link
Contributor

@petioptrv petioptrv commented Apr 5, 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 the Injective Perpetual Gateway connector.

Tests performed by the developer:

  • Unit tests added for the new code.
  • Manually tested the functionality.

Tips for QA testing:

Please test that the newly introduced endpoints for the clob perpetual Injective connector work as expected.

Link to client PR: hummingbot/hummingbot#6200
Link to PRP: https://snapshot.org/#/hbot-prp.eth/proposal/0x1e36039ae9ff72c133b2bcf4e7c3aa66b25693b195ac3e5c31ab7fe3f813d745

@rapcmia
Copy link
Contributor

rapcmia commented Apr 12, 2023

PR update:

  • Tested local using WSL Ubuntu20.04
  • Tested w/ Feat/injective perp hummingbot#6200
  • Installation and gateway setup successful
  • Run gateway list, confirm injective_perpetual is available
    image
  • Test endpoints using Curl
    • Port and add wallet ✅
    • Noticed that injective_post_perp_order.json is not available on the requests folder
      image
        ## post PERP order
        curl -s -X POST -k --key $GATEWAY_KEY --cert $GATEWAY_CERT -H "Content-Type: application/json" -d "$(envsubst < ./requests/injective_post_perp_order.json)" https://localhost:15888/clob/orders | jq
      
    • get markets
      image
      • Not all markets in future are showing on exchange
      • Endpoint display the same we have on client, missing pairs are LUNA-UST, BAYC-WETH, OSMO-USDT and SOL-USDT
      • This is the same with get tickers
    • post PERP order ✅
      image
    • get orders:
      image
      • Confirmed orders are successfully created
      • Confirmed orders shows success on txhash with orderId
      • Get orders endpoint does not display any of it
      • This affects the delete PERP order endpoint and batch orders. It seems its able to get the order or market id yet does not display any of active orders with it resulting to orders stuck on exchange and not cancelled not tested on client
        image

Pending:

  • Clob batch orders
  • Check exchange position behavior
  • Other endpoints
  • Crosscheck with client's expected behavior

@rapcmia
Copy link
Contributor

rapcmia commented Apr 17, 2023

Hi @petioptrv, good day to you. Would it be possible to know the next possible update? Thank you 🙇🏼

@petioptrv
Copy link
Contributor Author

Hi @rapcmia, I'll look into all this right now

@petioptrv
Copy link
Contributor Author

@rapcmia, I've pinged the Injective team for assistance with the trading pairs anomaly. I suspect that Helix is filtering out those pairs for some reason.

Also, I pushed the missing json file in this commit.

Tagging @vic-en

@petioptrv
Copy link
Contributor Author

@rapcmia, I've received confirmation from the injective team that this is a decision that they've made to exclude those markets from the Helix app. They are, however, still available to trade on the injective chain.

@nikspz
Copy link
Contributor

nikspz commented Apr 17, 2023

Hi @petioptrv , upon checking get orders, and delete PERP commands not fixed yet (no commit was provided to fix the issue)

I did some initial tests:

for INJ-USDT was able to place buy order to OPEN, failed to place sell order (bot can't see INJ balance maybe)
also successfully refreshing buy orders to OPEN (no stuck orders on exchange)
successfully cancelled buy order to OPEN after stop command

for ETH-USDT bot don't place any order to OPEN, no buy/sell order

inj-usdt-injperp.zip
ethusdt-injperp.zip

upd: Upon crosschecking with Ralph, stil waiting for the fix for get orders, and delete PERP mentioned above

@petioptrv
Copy link
Contributor Author

petioptrv commented Apr 18, 2023

@nikspz, the get and delete were added after-the-fact via comment edit. We will be addressing those today.

for INJ-USDT was able to place buy order to OPEN, failed to place sell order (bot can't see INJ balance maybe)

This is normal. The INJ/USDT PERP contract is collateralized in USDT, so the USDT balance is the only one that counts here. If most of the balance was used to create the long position open order, then there may have not been sufficient USDT for the short position open order. The logs reflect that.

for ETH-USDT bot don't place any order to OPEN, no buy/sell order

USDT should be the collateral here too. There were no attempts to place orders on two of the runs... This still seems to me like Perp MM is deciding not to place orders, but logs are missing to clarify why. Have you tried using another strategy here or reducing the order size? If this persists, I can add debug statements in Perp MM to see why it decides not to place orders.

Btw, I believe we can take this part of the conversation to the client PR since the changes will likely be committed there. The gateway get and delete will be addressed by commit on this PR.

@petioptrv
Copy link
Contributor Author

petioptrv commented Apr 18, 2023

@rapcmia, actually, the market ID, in this case, is the hash address of the INJ/USDT PERP market. I don't think you can see the order has (order ID) using the explorer approach. You can use the Gateway get command though.

curl -s -X GET -k --key $GATEWAY_KEY --cert $GATEWAY_CERT "https://localhost:15888/clob/perp/orders?chain=injective&network=mainnet&connector=injective_perpetual&market=INJ-USDT&address=$INJECTIVE_SUBACCOUNTID"

This will give you all orders for the account and market up to a certain number of orders. You can get the orderHash from that information. This will work for both get and delete.

@nicolasbaum
Copy link

@rapcmia, actually, the market ID, in this case, is the hash address of the INJ/USDT PERP market. I don't think you can see the order has (order ID) using the explorer approach. You can use the Gateway get command though.

curl -s -X GET -k --key $GATEWAY_KEY --cert $GATEWAY_CERT "https://localhost:15888/clob/perp/orders?chain=injective&network=mainnet&connector=injective_perpetual&market=INJ-USDT&address=$INJECTIVE_SUBACCOUNTID"

This will give you all orders for the account and market up to a certain number of orders. You can get the orderHash from that information. This will work for both get and delete.

Hi @petioptrv, I just got confirmation that there are and will be multiple markets with same ticker, making it harder to distinguish each one of them. Wanted to check with you if you are using the unique market id as key to index markets.
image

@nikspz
Copy link
Contributor

nikspz commented Apr 18, 2023

@petioptrv

got orders lost events during the bot run again, usually lost after

logs.zip

ERROR - Unhandled error in background task: <AioRpcError of RPC that terminated with:
	status = StatusCode.NOT_FOUND
	details = "object not found"details = "object not found"

Tried to test Client side, set up tight spreads to OPEN/CLOSE position firstly was able to OPEN and CLOSE few positions according or close to take profit (0.2)/ stop loss(0.15) spread set up:

image

injper04.18.2023.zip
logs_injper1804.log

Then I ran client little bit and its stuck with creating stop loss 😬
restarted the bot, bot was able to retrieve position 👍
and created/fill order to CLOSE position ( closed with price was worse then set up by strategy)
but after order refresh time created only buy order to OPEN
then after bot stopped, order stuck on the exchange 🙄

image

tried another strategy,
bot is trying place 2 orders to OPEN,
return Unhandled error in background task: No update for order for sell OPEN order.
then after order refresh time bot tries to cancel sell OPEN order, but there's no order on the exchange

https://www.loom.com/share/1ab64c35055243599d4a06be17140e7c

@petioptrv
Copy link
Contributor Author

The above issues have been addressed in the client PR.

Copy link
Contributor

@fengtality fengtality left a comment

Choose a reason for hiding this comment

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

LGTM - I will add a commit after this is merged to create a new CLOB Perp section in Swagger docs

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.

7 participants