ccxt / ccxt

A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
https://docs.ccxt.com
MIT License
32.65k stars 7.49k forks source link

Execution of limit order on Kraken Futures Exchange generates error: `AttributeError: 'float' object has no attribute 'lower'` while subscribed to orders and my_trades #19009

Open silverbald opened 1 year ago

silverbald commented 1 year ago

Operating System

macOS Ventura 13.5

Programming Languages

Python

CCXT Version

4.0.75

Description

Execution of limit order on Kraken Futures Exchange generates error:

AttributeError: 'float' object has no attribute 'lower'`

while subscribed to:

watch_orders(self.symbol)
watch_my_trades(self.symbol)

FULL ERROR in attachment FULL_ERROR.txt

Code

import asyncio
import os
import traceback

import ccxt.pro

class KrakenFutures:

    def __init__(self, symbol):
        self.symbol = f'{symbol}:USD'
        self.kfws = ccxt.pro.krakenfutures({
            'enableRateLimit': True,
            'secret': os.environ['KF_SECRET'],
            'apiKey': os.environ['KF_APIKEY']
        })
        self.kfws.verbose = True

    def start_websocket(self):
        asyncio.run(self.main_ws_loop())

    async def main_ws_loop(self):
        await self.kfws.load_markets()
        while True:
            try:
                loops = [
                    self.__watch_my_trades(),
                    self.__watch_orders()
                ]
                await asyncio.gather(*loops)
            except Exception:
                print(traceback.format_exc())
                break
        await self.kfws.close()

    async def __watch_orders(self):
        while True:
            r = await self.kfws.watch_orders(self.symbol)
            print(f"on_orders: {r}")

    async def __watch_my_trades(self):
        while True:
            r = await self.kfws.watch_my_trades(self.symbol)
            print(f"on_my_trades: {r}")

if __name__ == '__main__':
    exchange = KrakenFutures("XRP/USD")
    exchange.start_websocket()
carlosmiei commented 1 year ago

Hello @silverbald, Did the exception come from watchOrders or watchMYTrades ? is it possible to share a stacktrace of the error?

silverbald commented 1 year ago

Hello @silverbald, Did the exception come from watchOrders or watchMYTrades ? is it possible to share a stacktrace of the error?

Hi @carlosmiei Sure. All the stack trace is in attached file FULL_ERROR.txt (in the 1st message in this thread) with all the logs and on the end you have stacktrace (I'm copying it below). It is starting with watch_my_trades but then it goes to watch_orders

Traceback (most recent call last):
  File "/Users/xxxxx/Documents/projects/ccxt/test.py", line 37, in main_ws_loop
    await asyncio.gather(*loops)
  File "/Users/xxxxx/Documents/projects/ccxt/test.py", line 70, in __watch_my_trades
    r = await self.kfws.watch_my_trades(self.symbol)
  File "/Users/xxxxx/.local/share/virtualenvs/ccxt-c3hOdmRG/lib/python3.9/site-packages/ccxt/pro/krakenfutures.py", line 231, in watch_my_trades
    trades = await self.subscribe_private(name, messageHash, params)
  File "/Users/xxxxx/.local/share/virtualenvs/ccxt-c3hOdmRG/lib/python3.9/site-packages/ccxt/pro/krakenfutures.py", line 135, in subscribe_private
    return await self.watch(url, messageHash, request, messageHash)
  File "/Users/xxxxx/Documents/projects/ccxt/test.py", line 65, in __watch_orders
    r = await self.kfws.watch_orders(self.symbol)
  File "/Users/xxxxx/.local/share/virtualenvs/ccxt-c3hOdmRG/lib/python3.9/site-packages/ccxt/pro/krakenfutures.py", line 210, in watch_orders
    orders = await self.subscribe_private(name, messageHash, params)
  File "/Users/xxxxx/.local/share/virtualenvs/ccxt-c3hOdmRG/lib/python3.9/site-packages/ccxt/pro/krakenfutures.py", line 135, in subscribe_private
    return await self.watch(url, messageHash, request, messageHash)
  File "/Users/xxxxx/.local/share/virtualenvs/ccxt-c3hOdmRG/lib/python3.9/site-packages/ccxt/async_support/base/ws/fast_client.py", line 27, in handler
    self.handle_message(message)
  File "/Users/xxxxx/.local/share/virtualenvs/ccxt-c3hOdmRG/lib/python3.9/site-packages/ccxt/async_support/base/ws/aiohttp_client.py", line 32, in handle_message
    self.handle_text_or_binary_message(message.data)
  File "/Users/xxxxx/.local/share/virtualenvs/ccxt-c3hOdmRG/lib/python3.9/site-packages/ccxt/async_support/base/ws/aiohttp_client.py", line 27, in handle_text_or_binary_message
    self.on_message_callback(self, decoded)
  File "/Users/xxxxx/.local/share/virtualenvs/ccxt-c3hOdmRG/lib/python3.9/site-packages/ccxt/pro/krakenfutures.py", line 1217, in handle_message
    return method(client, message)
  File "/Users/xxxxx/.local/share/virtualenvs/ccxt-c3hOdmRG/lib/python3.9/site-packages/ccxt/pro/krakenfutures.py", line 491, in handle_order
    previousOrder['filled'] = Precise.string_add(previousOrder['filled'], self.number_to_string(trade['amount']))
  File "/Users/xxxxx/.local/share/virtualenvs/ccxt-c3hOdmRG/lib/python3.9/site-packages/ccxt/base/precise.py", line 215, in string_add
    return str(Precise(string1).add(Precise(string2)))
  File "/Users/xxxxx/.local/share/virtualenvs/ccxt-c3hOdmRG/lib/python3.9/site-packages/ccxt/base/precise.py", line 18, in __init__
    number = number.lower()
AttributeError: 'float' object has no attribute 'lower'