์ฒซ ๋ฒ์งธ ์์ฒญ ํ์ aiohttp_proxy๋ฅผ ๋ณ๊ฒฝํด๋ ํจ๊ณผ๊ฐ ์์ต๋๋ค. ์ฒซ ๋ฒ์งธ (์ :) await e.load_markets()
๋ค์ ์ค์ ํ๋ฉด ์ฌ์ฉ๋์ง ์์ต๋๋ค. ์ฒซ ๋ฒ์งธ await e.load_markets()
์ด์ ์ ์ค์ ๋ ๊ฒฝ์ฐ ๋์ค์ aiohttp_proxy๋ฅผ ๋ค๋ฅธ ํ๋ก์ ์๋ฒ๋ก ๋ณ๊ฒฝํ๋ ๊ฒฝ์ฐ์๋ ํด๋น ํ๋ก์ ์๋ฒ๋ก ๊ณ์ ์ด๋ํฉ๋๋ค.
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๊ฐ์ฅ ์ฌ์ด ๋ฐฉ๋ฒ์ ๋ฌด์์
๋๊น? close()
ํธ์ถํ๊ณ ์ธ์
๋ณ์๋ฅผ ๋ฎ์ด ์ฐ์๊ฒ ์ต๋๊น? ๊ทธ๋ฆฌ๊ณ / ๋๋ ์ด๊ฒ์ ccxt์์ ์์ ํด์ผํ๋ ๊ฒ์
๋๊น (์ : ์ธ์
์ ๋ค์ ์์ํ๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ ์ถ๊ฐ)
import ccxt.async as ccxt
import asyncio
import test2_config as config
async def main():
exchange = 'gatecoin'
e = getattr(ccxt, exchange)()
e.verbose = True
e.apiKey = config.exchange_keys[exchange]['key']
e.secret = config.exchange_keys[exchange]['secret']
e.aiohttp_proxy = 'http://' + config.check_proxylist[0]['host'] + ':' + config.check_proxylist[0]['port']
await e.load_markets(reload=True)
e.aiohttp_proxy = 'http://' + config.transaction_proxy['host'] + ':' + config.transaction_proxy['port']
await e.load_markets(reload=True)
await e.close()
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
์์ธํ ์ถ๋ ฅ
Request: GET https://api.gatecoin.com/Public/LiveTickers {'User-Agent': 'python-requests/2.18.4', 'Accept-Encoding': 'gzip, deflate'} None
Response: GET https://api.gatecoin.com/Public/LiveTickers 200 <CIMultiDictProxy('Date': 'Tue, 27 Feb 2018 18:15:41 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Set-Cookie': '__cfduid=<snip>; expires=Wed, 27-Feb-19 18:15:40 GMT; path=/; domain=.gatecoin.com; HttpOnly', 'Cache-Control': 'private', 'Content-Encoding': 'gzip', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains; preload', 'X-Content-Type-Options': 'nosniff', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'Server': 'cloudflare', 'CF-RAY': '<snip>-DUB')> <snip>
Request: GET https://api.gatecoin.com/Public/LiveTickers {'User-Agent': 'python-requests/2.18.4', 'Accept-Encoding': 'gzip, deflate'} None
Response: GET https://api.gatecoin.com/Public/LiveTickers 200 <CIMultiDictProxy('Date': 'Tue, 27 Feb 2018 18:15:41 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'private', 'Content-Encoding': 'gzip', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains; preload', 'X-Content-Type-Options': 'nosniff', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'Server': 'cloudflare', 'CF-RAY': '<snip>-DUB')> <snip>
๋ถ๋ช
ํ ํ๋ก์๋ TCP ์ฐ๊ฒฐ๋ง๋ค ์๋ํฉ๋๋ค. ๋ซํ์ง ์์ผ๋ฉด ์ด์ ํ๋ก์๊ฐ ์ฌ์ฉ๋ฉ๋๋ค. ๋ด๊ฐ ์ถ๊ฐํ๋ฉด
headers['Connection'] = 'close'
๊ธฐ๋ณธ ๊ตํ ํด๋์ค (๋น๋๊ธฐ์ ๊ฒฝ์ฐ)์ ๊ฐ์ ธ ์ค๊ธฐ ๋ฉ์๋์ ์ฒซ ๋ฒ์งธ ์์ฒญ ํ TCP ์ฐ๊ฒฐ์ด ๋ซํ๊ธฐ ๋๋ฌธ์ ํ๋ก์ ์ํ์ด ์์๋๋ก ์๋ํฉ๋๋ค. ํด๋น ํค๋๊ฐ ์ถ๊ฐ๋์ง ์์ผ๋ฉด ์ด์ ํ๋ก์์ ๋ํ TCP ์ฐ๊ฒฐ์ด ์ด๋ฆฐ ์ํ๋ก ์ ์ง๋๊ณ aiohttp๋ ์ aiohttp_proxy์ ๊ด๊ณ์์ด ํด๋น ํค๋๋ฅผ ์ฌ์ฌ์ฉํฉ๋๋ค.
๋ฐ๋ผ์ ํต ์ผ๋ผ์ด๋ธ ๊ตฌํ ์ฌ๋ถ / ๋ฐฉ๋ฒ์ ๋ฐ๋ผ ํ๋ก์ ๋ฐ ๊ตํ์ ๋ฐ๋ผ ๋์์ด ๋ค๋ฅผ ์ ์์ต๋๋ค.
ํ์ง๋ง headers['Connection'] = 'close'
์ฃผ์
ํ๋ '๊นจ๋ํ'๋ฐฉ๋ฒ์ ์ฐพ์ ์ ์์ต๋๋ค.
ํค๋๋ฅผ ์ฝ์ ํ๋ '๊นจ๋ํ'๋ฐฉ๋ฒ์ ์ฐพ์ ์ ์์ต๋๋ค [ 'Connection'] = 'close'.
์ ํ๋ฅผ ๊ฑธ๊ธฐ ์ ๋๋ ๊ตํ ์ธ์คํด์ค๋ฅผ ๋ง๋ ์งํ์ exchange.headers = {'Connection': 'close'}
๋ฅผ ์ถ๊ฐํฉ๋๋ค.
# option 1
exchange = ccxt.gatecoin({'headers': {'Connection': 'close'}})
# option 2
exchange = ccxt.gatecoin()
exchange.headers = {'Connection': 'close'}
๋์์ด๋์ง ์์ผ๋ฉด ์๋ ค์ฃผ์ญ์์ค. ๊ณ ๋ง์!
์ผํ๋ ๊ฒ ๊ฐ์ต๋๋ค, thx!