hyperliquid-dex / hyperliquid-python-sdk

SDK for Hyperliquid API trading with Python.
MIT License
238 stars 97 forks source link

bugs on the testnet #46

Closed welann closed 3 months ago

welann commented 3 months ago

i want to use this sdk to buy GUNJB on testnet

this is the basic infomation:

{
      "name": "GUNJB",
      "szDecimals": 1,
      "weiDecimals": 6,
      "index": 840,
      "tokenId": "0x89195524233334221317c6df04a07459",
      "isCanonical": false,
      "evmContract": null,
      "fullName": null
}

then i want to find the real name to buy it

    {
      "tokens": [
        840,
        0
      ],
      "name": "@794",
      "index": 794,
      "isCanonical": false
    }

@794 looks like the right one and this is my code:

info = Info(baseurl, True)
print(json.dumps(info.all_mids()["@794"]))
order_result = exchange.order(
        str("@794"),
        True,
        sz=1000,
        limit_px=0.020030,
        order_type={"limit": {"tif": "Ioc"}},
    )

however, the price shows correctly, but the order failed

"0.02003"
{'status': 'ok', 'response': {'type': 'order', 'data': {'statuses': [{'error': 'Order price cannot be more than 80% away from the reference price'}]}}}

and finally, i find the reason: in exchange.py , self.coin_to_asset will convert @xx to asset id on mainnet, asset id is 10000+xx

    "@27": 10027,
    "@28": 10028,
    "@29": 10029,
    "@30": 10030,
    "@31": 10031,
    "@32": 10032,
    "@33": 10033,
    "@34": 10034,
    "@35": 10035,
    "@36": 10036

but on testnet is not, 10715 is the newest and biggest one

    "@782": 10706,
    "@783": 10707,
    "@785": 10708,
    "@786": 10709,
    "@787": 10710,
    "@789": 10711,
    "@791": 10712,
    "@792": 10713,
    "@793": 10714,
    "@794": 10715

this is what i capture on chrome dev mode: image

i don't konw how to get 10794 using this sdk

so can anybody help me ?

traderben commented 3 months ago

I've been responding to your questions in discord so closing this as a duplicate question