我正在尝试连接到fxmpy。我尝试了几个教程,加上用于财务说明的O'reilly Python,但无论我尝试什么解决方案,都会不断出现错误
我降级到socket 4.6.1,但仍然遇到问题
确保已安装socketio4.6.1
版本。不适用于新版本
fxcmpy版本1.2.6
import time
import numpy as np
import pandas as pd
import datetime as dt
from pylab import mpl, plt
import requests
import fxcmpy
import socket
from socketIO_client import SocketIO`
FXCM_API_TOKEN = '23b0f71eab5b91edd3b38ce15f6885ecxxxxxx'
api = fxcmpy.fxcmpy(access_token = FXCM_API_TOKEN, log_level='error')
|ERROR|2021-03-15 23:50:29,166|Socket returns unknown error.
---------------------------------------------------------------------------
ServerError Traceback (most recent call last)
<ipython-input-24-9cb4e3797d65> in <module>
12
13 FXCM_API_TOKEN = '23b0f71eab5b91edd3b38ce15f6885ecxxxxxxxx'
---> 14 api = fxcmpy.fxcmpy(access_token = FXCM_API_TOKEN, log_level='error')
~\anaconda3.1\lib\site-packages\fxcmpy\fxcmpy.py in __init__(self, access_token, config_file, log_file, log_level, server, proxy_url, proxy_port, proxy_type)
216 raise ServerError('Can not find FXCM Server.')
217 elif self.connection_status == 'aborted':
--> 218 raise ServerError('Can not connect to FXCM Server.')
219
220 self.__collect_account_ids__()
ServerError: Can not connect to FXCM Server.
plt.style.use('seaborn') #plot style
mpl.rcParams['savefig.dpi'] = 300 # resolution of the figures
mpl.rcParams['font.family'] = 'serif' #font style
%matplotlib inline
from fxcmpy import fxcmpy_tick_data_reader as tdr
print(tdr.get_available_symbols())
在检索符号时,此部分似乎出于某种原因起作用
('AUDCAD', 'AUDCHF', 'AUDJPY', 'AUDNZD', 'CADCHF', 'EURAUD', 'EURCHF', 'EURGBP', 'EURJPY', 'EURUSD', 'GBPCHF', 'GBPJPY', 'GBPNZD', 'GBPUSD', 'GBPCHF', 'GBPJPY', 'GBPNZD', 'NZDCAD', 'NZDCHF', 'NZDJPY', 'NZDUSD', 'USDCAD', 'USDCHF', 'USDJPY')
然后尝试检索历史数据
start = dt.datetime(2021, 2, 20)
stop = dt.datetime(2021, 2, 22)
td = tdr('GBPUSD', start, stop)
现在我得到一个https错误:
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
<ipython-input-16-5298b956609c> in <module>
----> 1 td = tdr('GBPUSD', start, stop)
~\anaconda3.1\lib\site-packages\fxcmpy\fxcmpy_data_reader.py in __init__(self, symbol, start, end, verbosity)
94 self.codec = 'utf-16'
95 if not isinstance(self, fxcmpy_candles_data_reader):
---> 96 self.__fetch_data__()
97
98 def get_raw_data(self):
~\anaconda3.1\lib\site-packages\fxcmpy\fxcmpy_data_reader.py in __fetch_data__(self)
172 year, week, noop = running_date.isocalendar()
173 url = self.url % (self.symbol, year, week)
--> 174 data = self.__fetch_dataset__(url)
175 if len(self.data) == 0:
176 self.data = data
~\anaconda3.1\lib\site-packages\fxcmpy\fxcmpy_data_reader.py in __fetch_dataset__(self, url)
183 if self.verbosity:
184 print('Fetching data from: %s' % url)
--> 185 requests = urllib.request.urlopen(url)
186 buf = BytesIO(requests.read())
187 f = gzip.GzipFile(fileobj=buf)
~\anaconda3.1\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
220 else:
221 opener = _opener
--> 222 return opener.open(url, data, timeout)
223
224 def install_opener(opener):
~\anaconda3.1\lib\urllib\request.py in open(self, fullurl, data, timeout)
529 for processor in self.process_response.get(protocol, []):
530 meth = getattr(processor, meth_name)
--> 531 response = meth(req, response)
532
533 return response
~\anaconda3.1\lib\urllib\request.py in http_response(self, request, response)
638 # request was successfully received, understood, and accepted.
639 if not (200 <= code < 300):
--> 640 response = self.parent.error(
641 'http', request, response, code, msg, hdrs)
642
~\anaconda3.1\lib\urllib\request.py in error(self, proto, *args)
567 if http_err:
568 args = (dict, 'default', 'http_error_default') + orig_args
--> 569 return self._call_chain(*args)
570
571 # XXX probably also want an abstract factory that knows when it makes
~\anaconda3.1\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
500 for handler in handlers:
501 func = getattr(handler, meth_name)
--> 502 result = func(*args)
503 if result is not None:
504 return result
~\anaconda3.1\lib\urllib\request.py in http_error_default(self, req, fp, code, msg, hdrs)
647 class HTTPDefaultErrorHandler(BaseHandler):
648 def http_error_default(self, req, fp, code, msg, hdrs):
--> 649 raise HTTPError(req.full_url, code, msg, hdrs, fp)
650
651 class HTTPRedirectHandler(BaseHandler):
HTTPError: HTTP Error 404: Not Found```
Any ideas?
在cmd中,但是如果linux尝试pip3
将连接更改为:无其他内容。 fxcmpy.fxcmpy(access_token=token,log_level='warn',log_file=None)
相关问题 更多 >
编程相关推荐