tradingview-webhooks-bot icon indicating copy to clipboard operation
tradingview-webhooks-bot copied to clipboard

Bitmex testnet

Open alperoguz opened this issue 4 years ago • 2 comments

Hello, When I try to use webhook with Bitmex testnet API key, it says:

ccxt.base.errors.BadSymbol: bitmex does not have market symbol XBTUSD

I searched some and found same issues and suggestions on ccxt. But, still could not solve yet:

https://github.com/ccxt/ccxt/issues/3920

I'd be glad if you guide me about that.

thank you

alperoguz avatar Dec 02 '20 05:12 alperoguz

Hey, sorry for the very late reply. Have you tried BTCUSD? IIRC I had similar issues and it was due to the symbol being something I didn't expect it to be.

robswc avatar Dec 13 '20 23:12 robswc

Hi robswc,

Yes, I tried BTC, BTCUSD, XBT, XBTUSD, but no luck.

You can see output below. I successfully fetching data from API. I have exactly 0.02587309 BTC in testnet wallet. But, you can see error at bottom.

127.0.0.1 - - [04/Dec/2020 23:31:48] "POST /webhook HTTP/1.0" 500 - [Alert Received] POST Received: {'type': 'market', 'side': 'buy', 'amount': 500, 'symbol': 'XBTUSD', 'price': 'None', 'key': '90fca5b4d2cb27eedaa22cd2d6b'} {'info': [{'account': 332853, 'currency': 'XBt', 'riskLimit': 1000000000000, 'prevState': '', 'state': '', 'action': '', 'amount': 2587309, 'pendingCredit': 0, 'pendingDebit': 0, 'confirmedDebit': 0, 'prevRealisedPnl': 0, 'prevUnrealisedPnl': 0, 'grossComm': 0, 'grossOpenCost': 0, 'grossOpenPremium': 0, 'grossExecCost': 0, 'grossMarkValue': 0, 'riskValue': 0, 'taxableMargin': 0, 'initMargin': 0, 'maintMargin': 0, 'sessionMargin': 0, 'targetExcessMargin': 0, 'varMargin': 0, 'realisedPnl': 0, 'unrealisedPnl': 0, 'indicativeTax': 0, 'unrealisedProfit': 0, 'syntheticMargin': None, 'walletBalance': 2587309, 'marginBalance': 2587309, 'marginBalancePcnt': 1, 'marginLeverage': 0, 'marginUsedPcnt': 0, 'excessMargin': 2587309, 'excessMarginPcnt': 1, 'availableMargin': 2587309, 'withdrawableMargin': 2587309, 'timestamp': '2020-12-02T12:00:01.669Z', 'grossLastValue': 0, 'commission': None}], 'BTC': {'free': 0.02587309, 'used': 0.0, 'total': 0.02587309}, 'free': {'BTC': 0.02587309}, 'used': {'BTC': 0.0}, 'total': {'BTC': 0.02587309}} Sending: XBTUSD market buy 500 None [2020-12-04 23:31:55,583] ERROR in app: Exception on /webhook [POST] Traceback (most recent call last): File "/home/alper/.local/share/virtualenvs/tradingview-webhooks-bot-i9G-o2s2/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/home/alper/.local/share/virtualenvs/tradingview-webhooks-bot-i9G-o2s2/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/alper/.local/share/virtualenvs/tradingview-webhooks-bot-i9G-o2s2/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/alper/.local/share/virtualenvs/tradingview-webhooks-bot-i9G-o2s2/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/home/alper/.local/share/virtualenvs/tradingview-webhooks-bot-i9G-o2s2/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/home/alper/.local/share/virtualenvs/tradingview-webhooks-bot-i9G-o2s2/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "webhook-bot.py", line 39, in webhook send_order(data) File "/home/alper/tv-master/tradingview-webhooks-bot/actions.py", line 55, in send_order order = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], calc_price(data['price'])) File "/home/alper/.local/share/virtualenvs/tradingview-webhooks-bot-i9G-o2s2/lib/python3.8/site-packages/ccxt/bitmex.py", line 1253, in create_order market = self.market(symbol) File "/home/alper/.local/share/virtualenvs/tradingview-webhooks-bot-i9G-o2s2/lib/python3.8/site-packages/ccxt/base/exchange.py", line 1818, in market raise BadSymbol('{} does not have market symbol {}'.format(self.id, symbol)) ccxt.base.errors.BadSymbol: bitmex does not have market symbol XBTUSD 127.0.0.1 - - [04/Dec/2020 23:31:55] "POST /webhook HTTP/1.0" 500 -

Also, I digged in ccxt issue page a bit* and added below lines to actions.py. Basicly, changed kraken with bitmex, added ApiKey and its secret, if section for testnet url:

def send_order(data):
    """
    This function sends the order to the exchange using ccxt.
    :param data: python dict, with keys as the API parameters.
    :return: the response from the exchange.
    """

    # Replace kraken with your exchange of choice.
    exchange = ccxt.bitmex({
        # Inset your API key and secrets for exchange in question.
        'apiKey': 'ZSGFq...........',
        'secret': 'IgqmKF................',
        'enableRateLimit': True,
    })

    # alper: Bitmex testnet url:
    if 'test' in exchange.urls:
        exchange.urls['api'] = exchange.urls['test'] # ←----- switch the base URL to testnet
    print(exchange.fetch_balance())

(*): https://github.com/ccxt/ccxt/issues/3920 https://github.com/ccxt/ccxt/issues/5717

thanks again

alperoguz avatar Dec 22 '20 14:12 alperoguz