gateway icon indicating copy to clipboard operation
gateway copied to clipboard

Ref - Token not supported

Open noemk2 opened this issue 1 year ago • 4 comments

Describe the bug When I run a script (arbt_ref.py) or a POST to /amm/price I can't get the price also think that wNear or USDC.e is not displayed because when making a get request to chain/tokens there is an error

arbt_ref.py

from decimal import Decimal
from typing import Dict

import pandas as pd

from hummingbot.client.ui.interface_utils import format_df_for_printout
from hummingbot.connector.connector_base import ConnectorBase
from hummingbot.data_feed.amm_gateway_data_feed import AmmGatewayDataFeed
from hummingbot.strategy.script_strategy_base import ScriptStrategyBase
from hummingbot.core.data_type.common import OrderType, PriceType, TradeType


class AMMDataFeedExample(ScriptStrategyBase):
    amm_data_feed_ref = AmmGatewayDataFeed(
        connector_chain_network="ref_near_mainnet",
        trading_pairs={"wNEAR-USDC.e"},
        order_amount_in_base=Decimal("1"),
    )

    markets = {"binance_paper_trade": {"BTC-USDT"}}

    def __init__(self, connectors: Dict[str, ConnectorBase]):
        super().__init__(connectors)
        self.amm_data_feed_ref.start()

    def on_stop(self):
        self.amm_data_feed_ref.stop()

    def on_tick(self):
        rows = []

        rows.extend(dict(price)
                    for token, price in self.amm_data_feed_ref.price_dict.items())

        price_ref = rows[0]["sell_price"]

        self.notify_hb_app_with_timestamp(price_ref)
        pass

output:

Error: {'message': 'Price query failed: Token not supported: wNEAR', 'httpErrorCode': 500, 'errorCode': 1013, 'stack': 'Error: Price query failed: Token not supported: wNEAR\n    at /home/gateway/dist/src/connectors/ref/ref.controllers.js:49:23\n    at Generator.throw (<anonymous>)\n    at rejected (/home/gateway/dist/src/connectors/ref/ref.controllers.js:6:65)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)'}

Steps To Reproduce

  • Execute arbt_ref.py on Hummingbot or make a POST request to /amm/price using Postman.

Screenshots on hummingbot: Screenshot from 2024-01-21 14-08-23 on postman POST request /amm/price: Screenshot from 2024-01-21 14-19-33 on postman GET request /chain/tokens: Screenshot from 2024-01-21 14-37-11

Release version // 1.23.0

Attachments // It is important that you attach the required files for us to be able to investigate the issue. // Please attach the chain.yml file from your gateway "conf" folder, e.g ethereum.yml

near.yml

networks:
  mainnet:
    chainID: 0
    nodeURL: https://rpc.mainnet.near.org
    tokenListType: FILE
    nativeCurrencySymbol: NEAR
    tokenListSource: /home/gateway/conf/lists/near_tokens.json
    gasPriceRefreshInterval: 60
  testnet:
    chainID: 0
    nodeURL: https://rpc.testnet.near.org
    tokenListType: FILE
    tokenListSource: /home/gateway/conf/lists/near_testnet_tokens.json
    nativeCurrencySymbol: NEAR
    gasPriceRefreshInterval: 60

gasLimitTransaction: 3000000000000
manualGasPrice: 0

noemk2 avatar Jan 21 '24 19:01 noemk2

I'm not familiar with how tokens on Near work, but you should check out the entry for wNEAR in the default NEAR list https://github.com/hummingbot/gateway/blob/main/src/templates/lists/near_tokens.json and see if there's an issue with it.

fengtality avatar Jan 23 '24 22:01 fengtality

I'm not familiar with how tokens on Near work, but you should check out the entry for wNEAR in the default NEAR list https://github.com/hummingbot/gateway/blob/main/src/templates/lists/near_tokens.json and see if there's an issue with it.

I have resolved the reported issue: the problem : gateway/src/chains/near/near.base.ts the funtion getTokenList() was error because no sopported asyn/await .. i think

Solve : new function getTokenList() with then()

  async getTokenList(
    tokenListSource: string,
    tokenListType: TokenListType
  ): Promise<any> {
    // console.log(tokenListSource, tokenListType);

    return new Promise((resolve, reject) => {
      if (tokenListType === 'URL') {
        axios.get(tokenListSource)
          .then(response => {
            // console.log(response.data);
            resolve(response.data);
          })
          .catch(error => {
            reject(error);
          });
      } else {
        fs.readFile(tokenListSource, 'utf8')
          .then(data => {
            const jsonData = JSON.parse(data);
            console.log(jsonData);
            resolve(jsonData);
          })
          .catch(error => {
            reject(error);
          });
      }
    });
  } 

noemk2 avatar Feb 16 '24 00:02 noemk2

looks like you just replaced using async/await with using the axios library. but every other connector uses async/await pattern, and they work. we shouldn't be introducing new paradigms into basic operations like fetching data unless absolutely needed.

fengtality avatar Feb 16 '24 00:02 fengtality

I don't think the issue is because of async/await. You should implement getTokens() function in near.controllers.ts since there is no getTokens() function there hence the error for chain/tokens request.

mlguys avatar Feb 16 '24 01:02 mlguys