Environment
Pyton
Alpaca SDK Version
The Newest One I believe
Problem
This error pops up randomly, it is the server’s problem I believe.
Super Annoying
Traceback (most recent call last):
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py”, line 169, in _new_conn
conn = connection.create_connection(
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\connection.py”, line 96, in create_connection
raise err
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\connection.py”, line 86, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py”, line 699, in urlopen
httplib_response = self._make_request(
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py”, line 382, in _make_request
self._validate_conn(conn)
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py”, line 1010, in _validate_conn
conn.connect()
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py”, line 353, in connect
conn = self._new_conn()
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py”, line 181, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x000002857A2F0280>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py”, line 439, in send
resp = conn.urlopen(
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py”, line 755, in urlopen
retries = retries.increment(
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\retry.py”, line 573, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=‘paper-api.alpaca.markets’, port=443): Max retries exceeded with url: /v2/orders (Caused by NewConnectionError(’<urllib3.connection.HTTPSConnection object at 0x000002857A2F0280>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond’))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\user\PycharmProjects\pythonProject\Stock\Trading\Minute_2.py”, line 81, in
main()
File “C:\Users\user\PycharmProjects\pythonProject\Stock\Trading\Minute_2.py”, line 77, in main
running()
File “C:\Users\user\PycharmProjects\pythonProject\Stock\Trading\Minute_2.py”, line 67, in running
stream.run()
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\alpaca_trade_api\stream.py”, line 402, in run
loop.run_until_complete(self._run_forever())
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py”, line 642, in run_until_complete
return future.result()
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\alpaca_trade_api\stream.py”, line 396, in _run_forever
await asyncio.gather(self._trading_ws._run_forever(),
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\alpaca_trade_api\stream.py”, line 204, in _run_forever
await self._consume()
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\alpaca_trade_api\stream.py”, line 189, in _consume
await self._dispatch(msg)
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\alpaca_trade_api\stream.py”, line 113, in _dispatch
await handler(self._cast(msg_type, msg))
File “C:\Users\user\PycharmProjects\pythonProject\Stock\Trading\Minute_2.py”, line 64, in _
auto(SymbolList[0], Position[0], lowP, highP)
File “C:\Users\user\PycharmProjects\pythonProject\Stock\Trading\Minute_2.py”, line 28, in auto
Func.Func().StopLimitSellOrder(Symbol[0], price=sellPrice, qty=Position)
File “C:\Users\user\PycharmProjects\pythonProject\Stock\Trading\AAA_Trading_Funcs.py”, line 52, in StopLimitSellOrder
r = requests.post(self.ORDER_URL, json=var, headers=self.HEADERS)
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py”, line 119, in post
return request(‘post’, url, data=data, json=json, **kwargs)
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py”, line 61, in request
return session.request(method=method, url=url, **kwargs)
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py”, line 542, in request
resp = self.send(prep, **send_kwargs)
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py”, line 655, in send
r = adapter.send(request, **kwargs)
File “C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py”, line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host=‘paper-api.alpaca.markets’, port=443): Max retries exceeded with url: /v2/orders (Caused by NewConnectionError(’<urllib3.connection.HTTPSConnection object at 0x000002857A2F0280>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond’))
Paper or Live Tradng?
Paper Account
Example Code
logging.basicConfig(level=logging.INFO)
stream = Stream(Func.Func().API_KEY,
Func.Func().SECRET_KEY,
data_feed=‘sip’,
raw_data=True)
logging.basicConfig(level=logging.INFO)
@stream.on_bar('TQQQ')
async def _(bar):
print(datetime.datetime.now().strftime('%H %M %S'), end="\n")
print("check")
Func.Func().OrderChecker()
Position[0] = Func.Func().PositionChecker(SymbolList[0][0])
lowP = bar['l']
highP = bar['h']
auto(SymbolList[0], Position[0], lowP, highP) #Calling of my trading method
print(datetime.datetime.now().strftime('%H %M %S'), end="\n\n")