It is a strange phenomenon.
The code works normally on Windows (PC), but an error message occurs in Google Cloud as well as AWS, Azure
Given the following code:
import ccxt
import pandas as pd
from pandas import DataFrame
import numpy as np
import multiprocessing as mp
# binance keys
API_KEY = ''
SECRET_KEY = ''
# binance API
exchange = ccxt.binance()
exchange.apiKey = API_KEY
exchange.secret = SECRET_KEY
exchange.options = {'defaultType': 'future', 'adjustForTimeDifference': True, 'recvWindow' : 10000,'defaultTimeInForce': 'GTC', 'timeDifference': 0}
coin_lists = ['REN/USDT', 'ZIL/USDT', 'CELR/USDT', 'TRX/USDT', 'VET/USDT', 'RVN/USDT','ARPA/USDT','ANKR/USDT','IOTX/USDT','XEM/USDT', '1000XEC/USDT']
# ticker's price
def cur_price(symbol):
ohlc = exchange.fetchOHLCV(symbol=symbol, timeframe='5m', limit=1)
return ohlc[0][4]
if __name__ == '__main__':
# test code
balance = exchange.fetch_balance()
df_1 = DataFrame(balance)
# main code
pool = mp.Pool(processes =None)
ticker_price = list(pool.map(cur_price, coin_lists))
print(ticker_price)
pool.close()
pool.join()
My environment : Desktop: window10, vscode
Google Cloud: Ubuntu 21.10
Python : 3.8.12 64-bit
Phenomenon: The executable code below works normally on Windows (PC). However, errors occur in the clouds service such as Google Cloud Platform with ubuntu.
The code in question(Part of doubt):
If you comment out the #test code part, it works normally on Windows and Goodle Cloud.
An error occurs only when ‘balance = exchange.fetch_balance()’ is with the #main code part below.
But on Windows it works just fine anyway.
This code is absolutely necessary to check the balance.
Please help me!!!
Error Message
"""
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.9/http/client.py", line 1371, in getresponse
response.begin()
File "/usr/lib/python3.9/http/client.py", line 319, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.9/http/client.py", line 288, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 532, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3/dist-packages/six.py", line 718, in reraise
Traceback (most recent call last):
File "/usr/lib/python3.9/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
exchange.apiKey = API_KEY
File "/usr/lib/python3.9/multiprocessing/pool.py", line 48, in mapstar
return list(map(*args))
File "/home/g0xdroneart/auto_trading/t.py", line 26, in cur_price
ohlc = exchange.fetchOHLCV(symbol=symbol, timeframe='5m', limit=1)
File "/home/g0xdroneart/.local/lib/python3.9/site-packages/ccxt/binance.py", line 1887, in fetch_ohlcv
response = getattr(self, method)(self.extend(request, params))
File "/home/g0xdroneart/.local/lib/python3.9/site-packages/ccxt/base/exchange.py", line 457, in inner
return entry(_self, **inner_kwargs)
File "/home/g0xdroneart/.local/lib/python3.9/site-packages/ccxt/binance.py", line 4401, in request
response = self.fetch2(path, api, method, params, headers, body, config, context)
File "/home/g0xdroneart/.local/lib/python3.9/site-packages/ccxt/base/exchange.py", line 502, in fetch2
return self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "/home/g0xdroneart/.local/lib/python3.9/site-packages/ccxt/base/exchange.py", line 639, in fetch
raise NetworkError(details) from e
ccxt.base.errors.NetworkError: binance GET https://fapi.binance.com/fapi/v1/klines?interval=5m&limit=1&sym
bol=CELRUSDT
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/g0xdroneart/auto_trading/t.py", line 37, in <module>
ticker_price = list(pool.map(cur_price, coin_lists))
File "/usr/lib/python3.9/multiprocessing/pool.py", line 364, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/usr/lib/python3.9/multiprocessing/pool.py", line 771, in get
raise self._value
ccxt.base.errors.NetworkError: binance GET https://fapi.binance.com/fapi/v1/klines?interval=5m&limit=1&sym
bol=CELRUSDT