Ccxt: Issues with asyncio

Created on 21 Aug 2017  Β·  60Comments  Β·  Source: ccxt/ccxt

There seems to be a lot of issues using asnycio class.

import ccxt.async as ccxt
gdax = ccxt.gdax()
print(asyncio.get_event_loop().run_until_complete(gdax.load_markets()))

Throws

ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f34fee189b0>

If i call fetch_balance()
I get:

  File "uvloop/loop.pyx", line 1203, in uvloop.loop.Loop.run_until_complete (uvloop/loop.c:25632)
  File ".venv/lib/python3.6/site-packages/ccxt/async/exchanges.py", line 8516, in fetch_balance
    balances = await self.privateGetAccounts()
  File "venv/lib/python3.6/site-packages/ccxt/async/exchanges.py", line 8678, in request
    response = await self.fetch(url, method, headers, body)
  File ".venv/lib/python3.6/site-packages/ccxt/async/exchange.py", line 85, in fetch
    async with session_method(url, data=body or None, headers=headers, timeout=(self.timeout / 1000)) as response:
  File ".venv/lib/python3.6/site-packages/aiohttp/client.py", line 603, in __aenter__
    self._resp = yield from self._coro
  File ".venv/lib/python3.6/site-packages/aiohttp/client.py", line 239, in _request
    resp = req.send(conn)
  File ".venv/lib/python3.6/site-packages/aiohttp/client_reqrep.py", line 401, in send
    writer.write_headers(status_line, self.headers)
  File ".venv/lib/python3.6/site-packages/aiohttp/http_writer.py", line 250, in write_headers
    [k + SEP + v + END for k, v in headers.items()])
  File ".venv/lib/python3.6/site-packages/aiohttp/http_writer.py", line 250, in <listcomp>
    [k + SEP + v + END for k, v in headers.items()])
TypeError: must be str, not bytes

It 's not attached to GDAX . I am afraid that it is an overall issue.
Good luck, hope that you can find the time.

All 60 comments

Hi, good to hear from you!
Thanks for posting this!

As for the unclosed client session – it's a known error, you can safely ignore it for now, it just complains about the session not being closed when you exit the application. We will fix it. Also, you're not using it correctly, as far as I see. You're not awaiting for the load_markets() result, instead you print the run_until_complete() return which will not return the markets to you. You should define an async function like this:

import ccxt.async as ccxt
async test_gdax():
    gdax = ccxt.gdax()
    print(await gdax.load_markets()) # print here
asyncio.get_event_loop().run_until_complete(test_gdax())) # no print here

As for the TypeError – can you please paste the code you use to call fetch_balance()? It may be the same issue with improper asyncio usage.

Check out this example (added it, as other users might also need it): https://github.com/kroitor/ccxt/blob/master/examples/py/async-basic.py

It should go async def in an upper example.It's a typo.
It doesn't require writing async def function.The code that I wrote will give you the same effect as yours.If you observe it closely it's the same thing.I just thought that unclosed is a bigger issue than it is :) .

As for the fetch_balance().

gdax = ccxt.gdax(**properly initilized**)
asyncio.get_event_loop().run_until_complete(gdax.fetch_balance())

@marinsokol5 yeah, i fixed the typos in the example, thx! No worries about the unclosed error.
As for gdax.fetch_balance() – is that repeatable with other exchanges? If you confirm, I will have to debug it for some time.

Yeah unfortuately it is but if they are all using the same method than maybe it is not that bad.
Exchanges that I tested and they failed are GDAX,Bitfinex and Kraken. Others that i tested have passed.

All the best.Hope to hear from you soon.
If you need someone to test it after debugging I am here :) .

Ok, I'll check that and post a snippet for a clean test here soon, thx!

@marinsokol5 can you try this one, please (works for me, but we need to localize the issue):

https://github.com/kroitor/ccxt/blob/master/examples/py/async-balance.py

# -*- coding: utf-8 -*-

import asyncio
import os
import sys

#------------------------------------------------------------------------------

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root)

#------------------------------------------------------------------------------

import ccxt.async as ccxt  # noqa: E402

#------------------------------------------------------------------------------

async def test():
    bittrex = ccxt.bittrex({
        'apiKey': "c5af1d0ceeaa4729ad87da1b05d9dfc3",
        'secret': "d055d8e47fdf4c3bbd0ec6c289ea8ffd",
        'verbose': True,
    })
    # no need to load_markets anymore (done automatically upon first call)
    print(await bittrex.fetch_balance())

#------------------------------------------------------------------------------

asyncio.get_event_loop().run_until_complete(test())

The problem was never with Bittrex.
Bittrex works fine for me.Just like it used to.
Is the new code in the latest ccxt version becouse GDAX still doesn't work?

The problem was never with Bittrex.

I'm sorry, I thought you have it repeatable for all exchanges. Will dig into GDAX now.

Is the new code in the latest ccxt version becouse GDAX still doesn't work?

I haven't uploaded the fix for this yet.

@marinsokol5 please update to the latest version 1.4.72 and try the following:

https://github.com/kroitor/ccxt/blob/master/examples/py/async-balance-gdax.py

# -*- coding: utf-8 -*-

import asyncio
import os
import sys

#------------------------------------------------------------------------------

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root)

#------------------------------------------------------------------------------

import ccxt.async as ccxt  # noqa: E402

#------------------------------------------------------------------------------

async def test():
    gdax = ccxt.gdax({
        'apiKey': "a43edfe629bc5991acc83a536ac6358e",
        'secret': "xOvq+iH8NT07TheFB/fmY3GcnMZMwP7Xct9zwWtAZxsCbJh8rxeEe/0BGxfbV2em7P9iqQD7/TJGqmsDO8B/kw==",
        'password': 'zdmj8o7byla',
        'verbose': True, # switch it to False if you don't want the HTTP log
    })
    # move gdax to sandbox
    gdax.urls['api'] = 'https://api-public.sandbox.gdax.com'
    print(await gdax.fetch_balance())

#------------------------------------------------------------------------------

asyncio.get_event_loop().run_until_complete(test())

Fixed the bytes β†’ str decoding issue there in GDAX. I think, you should not have a problem with that exchange anymore. But there may still be problems with the other exchanges. I will be happy, if you help listing the exchanges which are still vulnerable to this issue. Thanks!

I will check for bitfinex and kraken now.

GDAX fixed!

Ok, uploaded the fixes for bitfinex and for kraken as well. Please, update to version 1.4.73 and try the following:

https://github.com/kroitor/ccxt/blob/master/examples/py/async-balances.py

# -*- coding: utf-8 -*-

import asyncio
import os
import sys

#------------------------------------------------------------------------------

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root)

#------------------------------------------------------------------------------

import ccxt.async as ccxt  # noqa: E402

#------------------------------------------------------------------------------

async def test(exchange):
    print(await exchange.fetch_balance())

#------------------------------------------------------------------------------

kraken = ccxt.kraken({
    'apiKey': "hEvQNMDIeoCJbr7W/ZBb5CGOrx3G0lWF5B3zqa1JBxdZlEaL8EK+D0Mw",
    'secret': "JaE9wI6Nwgh5oRxiHcVxurwzwBxwc05W/qv/k1srGg4s3EYuXPpNkLLM5NYbbWpM8rCyijIeDavRuqWbU0ZV9A==",
    'verbose': True, # switch it to False if you don't want the HTTP log
})
bitfinex = ccxt.bitfinex({
    'apiKey': "4FlEDtxDl35gdEiobnfZ72vJeZteE4Bb7JdvqzjIjHq",
    'secret': "D4DXM8DZdHuAq9YptUsb42aWT1XBnGlIJgLi8a7tzFH",
    'verbose': True, # switch it to False if you don't want the HTTP log
})

[asyncio.ensure_future(test(exchange)) for exchange in [kraken, bitfinex]]
pending = asyncio.Task.all_tasks()
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(*pending))

If you don't have issues with these exchanges anymore, please close this issue. If this does not solve it, we will continue to work on this. If you still have problems with other exchanges later, feel free to reopen it or make a new one. Thanks!

Also, the unclosed session warning should be gone now.

Yeah Kraken is fixed and working great. Unclosed session too.

Bitfinex doesn't throw error while fetching balances.My bad.
I am trying to call one of it's methods that are automatically added as his attributes.
bitfinex.private_post_account_infos().
It throws
<class 'NameError'>: name 'ccxt' is not defined happened
Is it possible that it has something to do with class exchange.py

        async with session_method(url, data=body or None, headers=headers, timeout=(self.timeout / 1000)) as response:
            text = await response.text()
            error = None
            details = text if text else None
            if response.status == 429:
                error = ccxt.DDoSProtection
            elif response.status in [404, 409, 500, 501, 502, 521, 522, 525]:
                details = str(response.status) + ' ' + text
                error = ccxt.ExchangeNotAvailable
            elif response.status in [400, 403, 405, 503]:
                # special case to detect ddos protection
                reason = text
                ddos_protection = re.search('(cloudflare|incapsula)', reason, flags=re.IGNORECASE)
                if ddos_protection:
                    error = ccxt.DDoSProtection
                else:
                    error = ccxt.ExchangeNotAvailable
                    details = '(possible reasons: ' + ', '.join([
                        'invalid API keys',
                        'bad or old nonce',
                        'exchange is down or offline',
                        'on maintenance',
                        'DDoS protection',
                        'rate-limiting',
                        reason,
                    ]) + ')'
            elif response.status in [408, 504]:
                error = ccxt.RequestTimeout
            elif response.status in [401, 422, 511]:
                error = ccxt.AuthenticationError
            if error:
                self.raise_error(error, url, method, str(response.status), details)
        if self.verbose:
            print(method, url, "\nResponse:", headers, text)
        return self.handle_response(url, method, headers, text)

My PyCharm throws red at ccxt in code when and does not find it.

Ok, I'll take a look at what's going on with bitfinex custom methods and will report soon.

BTW, bitfinex still had that same issue as Kraken did, so a fix was necessary anyway. But your error is probably for some other reason, digging into it.

@marinsokol5 can you post a snippet showing how you call that method, including the params?

I'm trying, but cannot repeat the bitfinex problem with the following snippet:

https://github.com/kroitor/ccxt/blob/master/examples/py/async-bitfinex-private-post-account-infos.py

# -*- coding: utf-8 -*-

import asyncio
import os
import sys

#------------------------------------------------------------------------------

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root)

#------------------------------------------------------------------------------

import ccxt.async as ccxt  # noqa: E402

#------------------------------------------------------------------------------

async def test(exchange):
    print(await exchange.private_post_account_infos())

#------------------------------------------------------------------------------

bitfinex = ccxt.bitfinex({
    'apiKey': "4FlEDtxDl35gdEiobnfZ72vJeZteE4Bb7JdvqzjIjHq",
    'secret': "D4DXM8DZdHuAq9YptUsb42aWT1XBnGlIJgLi8a7tzFH",
    'verbose': True, # switch it to False if you don't want the HTTP log
})

[asyncio.ensure_future(test(exchange)) for exchange in [bitfinex]]
pending = asyncio.Task.all_tasks()
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(*pending))

Can you test this code on your side and report if it's working for you?

Yeah your code is working.
Strange.
Will check a bit more in the morning about bitfinex.
Still the error that I get must be some kind of left over in ccxt.
In line 1559: response = await self.fetch(url, method, headers, body)
It leads me to the class exchange.py and its method fetch
async def fetch(self, url, method='GET', headers=None, body=None):
where every error calls unexisting ccxt
example error = ccxt.ExchangeNotAvailable.

Moreover:
This is what liqui throws at me

liqui=ccxt.liqui(***)
print(asyncio.get_event_loop().run_until_complete(liqui.fetch_balance())
  File "uvloop/loop.pyx", line 1203, in uvloop.loop.Loop.run_until_complete (uvloop/loop.c:25632)
  File "python3.6/site-packages/ccxt/async/exchanges.py", line 3786, in fetch_balance
    response = await self.privatePostGetInfo()
  File "python3.6/site-packages/ccxt/async/exchanges.py", line 10450, in request
    response = await self.fetch(url, method, headers, body)
  File "python3.6/site-packages/ccxt/async/exchange.py", line 89, in fetch
    async with session_method(url, data=body or None, headers=headers, timeout=(self.timeout / 1000)) as response:
  File "python3.6/site-packages/aiohttp/client.py", line 603, in __aenter__
    self._resp = yield from self._coro
  File "python3.6/site-packages/aiohttp/client.py", line 239, in _request
    resp = req.send(conn)
  File "python3.6/site-packages/aiohttp/client_reqrep.py", line 401, in send
    writer.write_headers(status_line, self.headers)
  File "python3.6/site-packages/aiohttp/http_writer.py", line 250, in write_headers
    [k + SEP + v + END for k, v in headers.items()])
  File "python3.6/site-packages/aiohttp/http_writer.py", line 250, in <listcomp>
    [k + SEP + v + END for k, v in headers.items()])
TypeError: must be str, not int
2017-08-21 23:10:32,079 [ERROR] asyncio {connector.py:__del__:64}: Unclosed connection
client_connection: Connection<('api.liqui.io', 443, True)>

The exact same thing with as with Liqui is with Bitstamp.

Ok, I'll fix it for Liqui and Bitstamp as well, thanks for the update.

As for the bitfinex.private_post_accounts_infos(), if you want me to help, you will have to write your environment and how you run code, because I could not reproduce this issue yet. Maybe a version difference (Python or environment), and a fix inside ccxt may be needed indeed for your environment. Basically, it looks like it's a env-related issue, but I will fix it if you paste some more info:

  • a full stacktrace of the problematic code
  • the code itself (not a single line ;)
  • the version numbers for your software packages
  • how you start it

At least, until I reproduce it, I'm blind, I need to know in more detail what you do and what you get in return.

I will add an explicit import of those exception classes, maybe that's the case. Will upload in a couple of minutes.

Ok, I made a couple of changes with those imports, you can update to 1.4.77, try and see if the errors are gone. Otherwise I will not be very useful without more information from yourself. Will stand by for your feedback. Thx!

Version 1.4.8 of ccxt.

Problem with Bitstamp is still here.So like Liqui in upper comment.Calling fetch_balance throws

[k + SEP + v + END for k, v in headers.items()])
TypeError: must be str, not int

Liqui now upon calling fetch_balance throws

  File "python3.6/site-packages/ccxt/async/exchanges.py", line 3795, in fetch_balance
    response = await self.privatePostGetInfo()
  File "python3.6/site-packages/ccxt/async/exchanges.py", line 10458, in request
    'Sign': self.decode(signature),
  File "python3.6/site-packages/ccxt/exchange.py", line 515, in decode
    return string.decode()
AttributeError: 'str' object has no attribute 'decode'

The problem with wrong import is now fixed!Thank you for that.
Now the AuthentificationError is thrown.
Hmm wasn't there an explanation before what might have gone wrong coming along with the error? Might just be my bad memory.
Anyway if you want to reproduce the error.

bitfinex = ccxt.bitfinex({
    'apiKey': "4FlEDtxDl35gdE4fdefZ72vJeZteE4Bb7JdvqzjIjHq",
    'secret': "D4DXM8DZdHuAq9YptUsb42aWT1XBnGlIJgLi8a7tzFH",
})
asyncio.get_event_loop().run_until_complete(bitfinex.fetch_balance())

This is your api key with one or two numbers changed so that it throws an error.

Problem with Bitstamp is still here.So like Liqui in upper comment.

Can you please paste the full stacktrace?

Liqui now upon calling fetch_balance throws

That's strange, but I will fix it.

Now the AuthentificationError is thrown. Hmm wasn't there an explanation before what might have gone wrong coming along with the error? Might just be my bad memory.

You memory is fine, it only shows up in certain situations.

Anyway if you want to reproduce the error.

Well, if you try wrong credentials it should throw AuthenticationError and it does as expected right? So... that last one about bitfinex I didn't fully understand.

Ok, Liqui should now work normally, in 1.4.81+.
As far as I understand, Bitfinex is also working normally (according to the previously pasted code)?
Which one is left? Bitstamp?

The bitfinex code was just here to represent that the error message coming along with Authentification error seems a bit shorter than before.

Bitstamp code that trows an error at me:

bitstamp=ccxt.bitstamp(**)
print(asyncio.get_event_loop().run_until_complete(bitstamp.fetch_balance())

Bitstamp stack trace

  File "uvloop/loop.pyx", line 1203, in uvloop.loop.Loop.run_until_complete (uvloop/loop.c:25632)
  File "/python3.6/site-packages/ccxt/async/exchanges.py", line 2780, in fetch_balance
    balance = await self.privatePostBalance()
  File "/python3.6/site-packages/ccxt/async/exchanges.py", line 2844, in request
    response = await self.fetch(url, method, headers, body)
  File "/python3.6/site-packages/ccxt/async/exchange.py", line 99, in fetch
    async with session_method(url, data=body or None, headers=headers, timeout=(self.timeout / 1000)) as response:
  File "/python3.6/site-packages/aiohttp/client.py", line 603, in __aenter__
    self._resp = yield from self._coro
  File "/python3.6/site-packages/aiohttp/client.py", line 239, in _request
    resp = req.send(conn)
  File "python3.6/site-packages/aiohttp/client_reqrep.py", line 401, in send
    writer.write_headers(status_line, self.headers)
  File "python3.6/site-packages/aiohttp/http_writer.py", line 250, in write_headers
    [k + SEP + v + END for k, v in headers.items()])
  File "python3.6/site-packages/aiohttp/http_writer.py", line 250, in <listcomp>
    [k + SEP + v + END for k, v in headers.items()])
TypeError: must be str, not int
2017-08-22 08:47:16,966 [ERROR] asyncio {connector.py:__del__:64}: Unclosed connection
client_connection: Connection<('www.bitstamp.net', 443, True)>

@marinsokol5 I also added a fix for bitstamp into 1.4.81+, please update and try it again (with liqui) in a minute or two. Thx!

Ok, it's there, update, try it and let me know if bitstamp and liqui are now working normally for you. I don't see anything left with these two in the testing.

That's strange, should be 1.4.81, it's in the PyPI already: https://pypi.python.org/pypi/ccxt. Maybe retry in a minute? Could be some caching issue getting in the way.

It just arrived

Okay Liqui and Bitstamp are working!!
Thank you.

Cool! Let me know if you have any other problems (hope not))))

Are you fine with me keeping this open for like a half an hour or an hour.
Just so that i can run some other tests with asyncio?

Sure!

If you're wondering, why you get a shorter AuthenticationError (without a list of possible reasons) – that's because ccxt was able to determine that for sure. If it's not able to determine the exact reason, it prints out possible reasons. That's the logic. In most situations an AuthenticationError is very specific and does not require an explanation apart from the error string. And when you get the ExchangeError – it could be anything, that's when we print possible reasons.

P.S. Some exchanges send only the ExchangeError (for any cause, even for auth errors)... that's the shorter explanation.

Bter

bter=ccxt.bter(**)
print(asyncio.get_event_loop().run_until_complete(bter.fetch_balance())
  response = await self.fetch(url, method, headers, body)
  File "/home/marin/fino/.venv/lib/python3.6/site-packages/ccxt/async/exchange.py", line 99, in fetch
    async with session_method(url, data=body or None, headers=headers, timeout=(self.timeout / 1000)) as response:
  File "/home/marin/fino/.venv/lib/python3.6/site-packages/aiohttp/client.py", line 603, in __aenter__
    self._resp = yield from self._coro
  File "/home/marin/fino/.venv/lib/python3.6/site-packages/aiohttp/client.py", line 239, in _request
    resp = req.send(conn)
  File "/home/marin/fino/.venv/lib/python3.6/site-packages/aiohttp/client_reqrep.py", line 401, in send
    writer.write_headers(status_line, self.headers)
  File "/home/marin/fino/.venv/lib/python3.6/site-packages/aiohttp/http_writer.py", line 250, in write_headers
    [k + SEP + v + END for k, v in headers.items()])
  File "/home/marin/fino/.venv/lib/python3.6/site-packages/aiohttp/http_writer.py", line 250, in <listcomp>
    [k + SEP + v + END for k, v in headers.items()])
TypeError: must be str, not int
2017-08-22 09:26:01,760 [ERROR] asyncio {connector.py:__del__:64}: Unclosed connection
client_connection: Connection<('api.bter.com', 443, True)>

Ok, bter should also work normally in 1.4.82+ (should be available from PyPI already).

Bter fixed!!!
Will check a few more.

Awesome! I will stand by )

You did a good job man. :)

At this moment everything seems fine to me.
Will post an issue if i find something.
All the best.

@marinsokol5 without your help, It would be much harder and would take much longer time, thx!

Hello. I found the same problem for gatecoin exchanger:
File "/Users/kas/Documents/Bitcoin/proj/ccxt/async/gatecoin.py", line 385, in request
response = await self.fetch2(path, api, method, params, headers, body)
File "/Users/kas/Documents/Bitcoin/proj/ccxt/async/base/exchange.py", line 84, in fetch2
return await self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "/Users/kas/Documents/Bitcoin/proj/ccxt/async/base/exchange.py", line 104, in fetch
async with session_method(url, data=encoded_body, headers=headers, timeout=(self.timeout / 1000), proxy=self.aiohttp_proxy) as response:
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/client.py", line 690, in __aenter__
self._resp = yield from self._coro
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/client.py", line 275, in _request
resp = req.send(conn)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/client_reqrep.py", line 463, in send
writer.write_headers(status_line, self.headers)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/http_writer.py", line 247, in write_headers
[k + SEP + v + END for k, v in headers.items()])
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiohttp/http_writer.py", line 247, in
[k + SEP + v + END for k, v in headers.items()])
TypeError: must be str, not bytes

This can fix:
'API_PUBLIC_KEY': self.apiKey,
'API_REQUEST_SIGNATURE': self.decode(signature),
'API_REQUEST_DATE': str(nonce)

Thank you

Hi, @alexsith! What's your version of ccxt?

Now I use 1.10.538.

@alexsith fixed in 1.10.549. Please update your version, the issue should be gone. We will be happy if you report back, whether it works normally after updating or not. Thx!

@kroitor Thank you very much. But I can't update ccxt right now I have a issue https://github.com/ccxt/ccxt/issues/1040

@alexsith will fix it in 5-10 minutes as well.

hi @kroitor I seem to be getting this issue with version 1.10.1189 and python 3.6, code attached. Sorry, noob here, so let me know if I should open a separate issue.
async issue.txt

import datetime as dt
import ccxt.async as ccxt
import asyncio


async def main(exchange, st_date):
    raw = []
    for i in range(0, 10):
        raw.extend(await exchange.public_get_executions({'product_id': '5',
                                                         'timestamp': st_date,
                                                         'limit': '1000',
                                                         'page': i + 1}))
        print("call " + str(i) + " returned. " + dt.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'))
    return raw

q = ccxt.quoinex({'enableRateLimit': True, })

# set start date parameter
st = dt.datetime.timestamp(dt.datetime.utcnow() - dt.timedelta(days=7))

# notify start of call process
print("initiating trade call " + dt.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'))

# get trades
tr = asyncio.get_event_loop().run_until_complete(main(q, st))

Thanks!

If think you misclicked in chat^^

On Sat, Feb 24, 2018 at 11:38 PM, wheward notifications@github.com wrote:

hi @kroitor https://github.com/kroitor I seem to be getting this issue
with version 1.10.1189 and python 3.6, code attached. Sorry, noob here, so
let me know if I should open a separate issue.
async issue.txt
https://github.com/ccxt/ccxt/files/1755383/async.issue.txt

Thanks!

β€”
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/ccxt/ccxt/issues/139#issuecomment-368265879, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AiHSIbVdbM-WYtCiF-IBUJLnLzwLs-NBks5tYI9xgaJpZM4O9gpG
.

--
June, junaga.[email protected]

visit my ts at ts302.playeffect.de:10009
also on:
http://steamcommunity.com/id/Junaga/
https://www.reddit.com/user/junaga/comments/

@wheward hi! Can you please show your verbose output from that script following these steps: https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-submit-an-issue ?

thanks for responding @kroitor here is the verbose output, I cut back the amount of data requested to shorten the response.

C:\Python36\python.exe "C:/Users/WH/Pycharm projects/untitled/async issue.py"
initiating trade call 2018-02-25 00:45:40

Request: GET https://api.quoine.com/executions?product_id=5&timestamp=1518875140.835389&limit=5&page=1 {'X-Quoine-API-Version': '2', 'Content-Type': 'application/json', 'User-Agent': 'python-requests/2.18.4', 'Accept-Encoding': 'gzip, deflate'} None

Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001E71C7C7DD8>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x000001E71AFFC390>, 97732.093)]']
connector: <aiohttp.connector.TCPConnector object at 0x000001E71C7C7D30>
Response: GET https://api.quoine.com/executions?product_id=5&timestamp=1518875140.835389&limit=5&page=1 200 <CIMultiDictProxy('Date': 'Sun, 25 Feb 2018 00:45:43 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '175', 'Connection': 'keep-alive', 'Set-Cookie': '__cfduid=d4feb28dd556cb1a383eac73a93798bae1519519543; expires=Mon, 25-Feb-19 00:45:43 GMT; path=/; domain=.quoine.com; HttpOnly', 'Cache-Control': 'max-age=0, private, must-revalidate', 'Content-Encoding': 'gzip', 'Etag': '"88314c7260cfc8dba9b7959092133be0"', 'Set-Cookie': '_vax_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFVEkiJTgzZjc3NzRiYmY0MjQ4ZGRkZTkyZjA4ZGRmZGExNGE0BjsAVEkiCWxhbmcGOwBGOgdlbg%3D%3D--95eca42fddba4a4aa28c0eb4d5126b45f4b67f3f; path=/; secure; HttpOnly', 'Status': '200 OK', 'Strict-Transport-Security': 'max-age=631152000; includeSubdomains', 'Vary': 'Accept-Encoding', 'Via': '1.1 spaces-router (03339d95e5c7)', 'X-Content-Type-Options': 'nosniff', 'X-Frame-Options': 'SAMEORIGIN', 'X-Powered-By': 'Phusion Passenger 5.1.2', 'X-Rack-Cache': 'miss', 'X-Request-Id': 'f5f9fe1f-6f10-0c62-d8f5-b5291fd8365d', 'X-Runtime': '0.031398', 'X-Ua-Compatible': 'IE=Edge,chrome=1', 'X-Xss-Protection': '1; mode=block', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'Server': 'cloudflare', 'CF-RAY': '3f26a4b9aa4465bd-SYD')> [{"id":27223326,"quantity":"0.052","price":"1144576.47727","taker_side":"buy","created_at":1518875148},{"id":27223340,"quantity":"0.18","price":"1144578.60227","taker_side":"buy","created_at":1518875182},{"id":27223339,"quantity":"0.1197902","price":"1144567.68","taker_side":"buy","created_at":1518875182},{"id":27223338,"quantity":"0.7448","price":"1144567.67","taker_side":"buy","created_at":1518875182},{"id":27223337,"quantity":"0.052","price":"1144566.928","taker_side":"buy","created_at":1518875182}]
call 0 returned. 2018-02-25 00:45:42

Process finished with exit code 0

@wheward

ok, thx, however, i'm now a little confused:

I seem to be getting this issue with version 1.10.1189 and python 3.6

Because there were many issues mentioned in this post, can you please clarify which particular issue do you mean? Is it the "unclosed client session" issue?

if you mean that specific issue, then it was addressed here: https://github.com/ccxt/ccxt/pull/2031
And the proper code with a logger-warning for it will be available in version 1.10.1192 in 5-10 minutes.

@kroitor
that's right, it's the unclosed client session issue.
awesome πŸ‘ thanks for the quick response and update!

@wheward ok, so you have to call await exchange.close() on the exchange instance, before the program exits, as the warning message says. Let us know if you still have difficulties with it. Thx!

@kroitor all good, works perfectly now, thanks again!

Cool! Let me know if you have any other problems (hope not))))

Hello @kroitor
It seems bitstamp doesn't work, TypeError occurs
version 1.26.53

connector = bitstamp({'apiKey': "XXXX", 'secret': "YYYY"})
connector.uid = 'ZZZZ'
fut = asyncio.ensure_future(connector.fetch_balance())
asyncio.get_event_loop().run_until_complete(fut)

i get:

Traceback (most recent call last):
  File "/ms_general/private_connector/test_bitstamp.py", line 12, in <module>
    asyncio.get_event_loop().run_until_complete(fut)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
  File "/ms_general/private_connector/test_bitstamp.py", line 7, in test
    print(await exchange.fetch_balance())
  File "/ms_general/venv3.7/lib/python3.7/site-packages/ccxt/async_support/bitstamp.py", line 516, in fetch_balance
    balance = await self.privatePostBalance(params)
  File "/ms_general/venv3.7/lib/python3.7/site-packages/ccxt/async_support/base/exchange.py", line 95, in fetch2
    return await self.fetch(request['url'], request['method'], request['headers'], request['body'])
  File "/ms_general/venv3.7/lib/python3.7/site-packages/ccxt/async_support/base/exchange.py", line 120, in fetch
    proxy=self.aiohttp_proxy) as response:
  File "/ms_general/venv3.7/lib/python3.7/site-packages/aiohttp/client.py", line 1012, in __aenter__
    self._resp = await self._coro
  File "/ms_general/venv3.7/lib/python3.7/site-packages/aiohttp/client.py", line 502, in _request
    resp = await req.send(conn)
  File "/ms_general/venv3.7/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 629, in send
    await writer.write_headers(status_line, self.headers)
  File "/ms_general/venv3.7/lib/python3.7/site-packages/aiohttp/http_writer.py", line 111, in write_headers
    buf = _serialize_headers(status_line, headers)
  File "/ms_general/venv3.7/lib/python3.7/site-packages/aiohttp/http_writer.py", line 160, in _py_serialize_headers
    [k + ': ' + v + '\r\n' for k, v in headers.items()])
  File "/ms_general/venv3.7/lib/python3.7/site-packages/aiohttp/http_writer.py", line 160, in <listcomp>
    [k + ': ' + v + '\r\n' for k, v in headers.items()])
**TypeError: can only concatenate str (not "bytes") to str**

bitstamp requires to release all resources with an explicit call to the .close() coroutine. If you are using the exchange instance with async coroutines, add exchange.close() to your code into a place when you're done with the exchange and don't need the exchange instance anymore (at the end of your async coroutine).
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x10d3cb1d0>

ps: Thank you very much guys for CCXT. It makes my work and the works of many engineers easier

Hi @artas728 !

This issue has been addressed here: https://github.com/ccxt/ccxt/issues/6846

Please, update to the most recent version of CCXT and let us know whether this does resolve the issue for you or not. Looking forward to hearing from you! Thx!

@kroitor , I checked, it works correctly
thank you!

@artas728 thx for the feedback, appreciate it!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mazertwo picture mazertwo  Β·  36Comments

scoshil picture scoshil  Β·  39Comments

cklester picture cklester  Β·  346Comments

synchronizing picture synchronizing  Β·  51Comments

rbn920 picture rbn920  Β·  64Comments