简体   繁体   English

ccxt python库无法在我的本地计算机上连接bitmex专用api

[英]ccxt python library ca'nt connect bitmex private api on my local

I'm going to use ccxt python library to connect bitmex private api. 我将使用ccxt python库连接bitmex私有api。 Following code working well on online python compiler: https://repl.it/languages/python3 But on my local can't run. 以下代码在在线python编译器上运行良好: https : //repl.it/languages/python3但是在我的本地无法运行。

btmx = ccxt.bitmex({
   'apiKey': '',
   'secret':'',
   'enableRateLimit': True,
   'origin': 'bitmex',
})

if 'test' in btmx.urls:
    btmx.urls['api']=btmx.urls['test']

print(btmx.fetch_balance())

The following error occurred: image error. 发生以下错误: 图像错误。 Please help me on in this problem. 请帮我解决这个问题。

I've fixed this problem by help of the ccxt team . 我已经在ccxt小组的帮助下解决了这个问题。

import ccxt exchange = ccxt.bitmex({ 'apiKey': 'YOUR_API_KEY', # ←------------- EDIT HERE FOR YOUR KEYS 'secret':'YOUR_SECRET', 'enableRateLimit': True, 'options': { # ↓ ADD THIS OPTION OR SYNCHRONIZE YOUR TIME # default value is 5 seconds, your time drifts by 21 seconds or more import ccxt exchange = ccxt.bitmex({'apiKey':'YOUR_API_KEY',#←-------------在此处编辑您的密钥'secret':'YOUR_SECRET','enableRateLimit':True ,“选项”:{#↓添加此选项或同步您的时间#默认值为5秒,您的时间漂移​​21秒或更多
'api-expires': 60, }, }) 'api-expires':60,},})

if 'test' in exchange.urls: exchange.urls['api'] = exchange.urls['test'] 如果exchange.urls中的“ test”为:exchange.urls ['api'] = exchange.urls ['test']

print(exchange.fetch_balance()) 打印(exchange.fetch_balance())

This code talked to me. 这段代码告诉我。 My local time was different 21s from standard time. 我的当地时间与标准时间相差21秒。 I've fixed my local time. 我已经确定了当地时间。 So all is working well. 因此,一切正常。 I'm thanks for the ccxt team. 感谢ccxt小组。

try: # Python 3 from http.server import HTTPServer, SimpleHTTPRequestHandler, test as test_orig import sys def test (*args): test_orig (*args, port = int (sys.argv[1]) if len (sys.argv) > 1 else 8080) except ImportError: # Python 2 from BaseHTTPServer import HTTPServer, test from SimpleHTTPServer import SimpleHTTPRequestHandler 尝试:#Python 3从http.server导入HTTPServer,SimpleHTTPRequestHandler,测试为test_orig导入sys def测试(* args):test_orig(* args,端口= int(sys.argv [1]),如果len(sys.argv)> 1 8080),除了ImportError:#Python 2从BaseHTTPServer导入HTTPServer,从SimpleHTTPServer导入SimpleHTTPRequestHandler进行测试

class CORSRequestHandler (SimpleHTTPRequestHandler): def end_headers (self): self.send_header ('Access-Control-Allow-Origin', '*') SimpleHTTPRequestHandler.end_headers (self) 类CORSRequestHandler(SimpleHTTPRequestHandler):def end_headers(个体):self.send_header('Access-Control-Allow-Origin','*')SimpleHTTPRequestHandler.end_headers(个体)

if name == ' main ': test (CORSRequestHandler, HTTPServer) 如果name ==' main ':测试(CORSRequestHandler,HTTPServer)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM