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

feat(kucoinfutures): add watchPositions and upgrade ast-transpiler to v0.0.46 #22169

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

pcriadoperez
Copy link
Contributor

@pcriadoperez pcriadoperez commented Apr 16, 2024

Include ast-transpiler upgrade that fixes delete in csharp

@pcriadoperez pcriadoperez changed the title feat(kucoinfutures): add watchPositions feat(kucoinfutures): add watchPositions and upgrade ast-transpiler to v0.0.46 Apr 17, 2024
@carlosmiei
Copy link
Collaborator

@pcriadoperez hum

 p kucoinfutures watchPositions
Python v3.11.7
CCXT v4.2.99
kucoinfutures.watchPositions()
[]
Traceback (most recent call last):
  File "/Users/cjg/Git/ccxt9/ccxt/examples/py/cli.py", line 249, in <module>
    asyncio.run(main())
  File "/opt/homebrew/Cellar/[email protected]/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/cjg/Git/ccxt9/ccxt/examples/py/cli.py", line 228, in main
    result = await result
             ^^^^^^^^^^^^
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/pro/kucoinfutures.py", line 386, in watch_positions
    newPosition = await self.subscribe(url, messageHash, topic, None, self.extend(request, params))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/pro/kucoinfutures.py", line 150, in subscribe
    return await self.watch(url, messageHash, message, subscriptionHash, subscription)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/async_support/base/ws/fast_client.py", line 26, in handler
    self.handle_message(message)
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/async_support/base/ws/aiohttp_client.py", line 34, in handle_message
    self.handle_text_or_binary_message(message.data)
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/async_support/base/ws/aiohttp_client.py", line 29, in handle_text_or_binary_message
    self.on_message_callback(self, decoded)
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/pro/kucoinfutures.py", line 1049, in handle_message
    method(client, message)
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/pro/kucoinfutures.py", line 997, in handle_subject
    method(client, message)
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/pro/kucoinfutures.py", line 519, in handle_position
    position = self.extend(currentPosition, newPosition)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/base/exchange.py", line 963, in extend
    result.update(arg)
TypeError: 'NoneType' object is not iterable
kucoinfutures requires to release all resources with an explicit call to the .close() coroutine. If you are using the exchange instance with async coroutines, add `await exchange.close()` to your code into a p

@carlosmiei
Copy link
Collaborator

fixed one issue, but found another crash

Traceback (most recent call last):
  File "/Users/cjg/Git/ccxt9/ccxt/examples/py/cli.py", line 249, in <module>
    asyncio.run(main())
  File "/opt/homebrew/Cellar/[email protected]/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/cjg/Git/ccxt9/ccxt/examples/py/cli.py", line 228, in main
    result = await result
             ^^^^^^^^^^^^
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/pro/kucoinfutures.py", line 386, in watch_positions
    newPosition = await self.subscribe(url, messageHash, topic, None, self.extend(request, params))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/pro/kucoinfutures.py", line 150, in subscribe
    return await self.watch(url, messageHash, message, subscriptionHash, subscription)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/async_support/base/ws/fast_client.py", line 26, in handler
    self.handle_message(message)
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/async_support/base/ws/aiohttp_client.py", line 34, in handle_message
    self.handle_text_or_binary_message(message.data)
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/async_support/base/ws/aiohttp_client.py", line 29, in handle_text_or_binary_message
    self.on_message_callback(self, decoded)
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/pro/kucoinfutures.py", line 1051, in handle_message
    method(client, message)
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/pro/kucoinfutures.py", line 999, in handle_subject
    method(client, message)
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/pro/kucoinfutures.py", line 523, in handle_position
    cache.append(position)
  File "/Users/cjg/Git/ccxt9/ccxt/python/ccxt/async_support/base/ws/cache.py", line 140, in append
    if item['id'] in by_id:
       ~~~~^^^^^^
KeyError: 'id'

@pcriadoperez
Copy link
Contributor Author

good catch, it seems it was using the wrong type of array cache and was happening only when the position didn't exist in the first fetchPositons.

This also raised the issue I'm seeing we aren't handling the cache correctly for all non-hedged positions when newUpdates is false. I'll update the ArrayCache changes to this PR, so it serves as a working example, and once merged can check and fix the other exchanges.

@carlosmiei
Copy link
Collaborator

@pcriadoperez you're missing updating the c# side here

@carlosmiei
Copy link
Collaborator

@pcriadoperez is this relevant for this pr?
image

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

Successfully merging this pull request may close these issues.

None yet

2 participants