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

Error while connecting with websocket #248

Open
Abubakar672 opened this issue Oct 2, 2023 · 0 comments
Open

Error while connecting with websocket #248

Abubakar672 opened this issue Oct 2, 2023 · 0 comments

Comments

@Abubakar672
Copy link

Abubakar672 commented Oct 2, 2023

I am following BITMEX this example https://github.com/BitMEX/api-connectors/tree/master/official-ws/python
but i am facing the following issue as defined below.

Error Log:

2023-10-02 11:04:05,797 - bitmex_websocket - INFO - Connecting to ws://wss.testnet.bitmex.com/?subscribe=execution:XBTETH,instrument:XBTETH,margin,order:XBTETH,orderBookL2:XBTETH,position:XBTETH,quote:XBTETH,trade:XBTETH
2023-10-02 11:04:05,798 - bitmex_websocket - INFO - Authenticating with API Key.
2023-10-02 11:04:05,802 - bitmex_websocket - ERROR - Error : [Errno 8] nodename nor servname provided, or not known
2023-10-02 11:04:05,802 - websocket - ERROR - error from callback <bound method BitMEXWebsocket.__on_error of <bitmex_websocket.BitMEXWebsocket object at 0x1006ab550>>: [Errno 8] nodename nor servname provided, or not known

Code:

from bitmex_websocket import BitMEXWebsocket
import logging
from time import sleep
apiKey = 'myapikeyhere'
apiSecret = 'mysecretkeyhere'
def run():
    logger = setup_logger()
    ws = BitMEXWebsocket(endpoint="ws://wss.testnet.bitmex.com/",
                         symbol="XBTETH", api_key=apiKey, api_secret=apiSecret)

    # logger.info("Instrument data: %s" % ws.get_instrument())
    # Run forever
    while (ws.ws.sock.connected):
        # logger.info("Ticker: %s" % ws.get_ticker())
        # if ws.api_key:
        # logger.info("Funds: %s" % ws.funds())
        # logger.info("Market Depth: %s" % ws.market_depth())
        logger.info("Recent Trades: %s\n\n" % ws.recent_trades())
        sleep(5)
def setup_logger():
    # Prints logger info to terminal
    logger = logging.getLogger()
    # Change this to DEBUG if you want a lot more info
    logger.setLevel(logging.INFO)
    ch = logging.StreamHandler()
    # create formatter
    formatter = logging.Formatter(
        "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
    # add formatter to ch
    ch.setFormatter(formatter)
    logger.addHandler(ch)
    return logger

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

No branches or pull requests

1 participant