ccxt获取okex账户返回内容如下 求解

2021-03-11 11:46发布

用fetchbalance方法 交易账户里明明有币返回结果里却是空的 

用fetchbalance方法 交易账户里明明有币返回结果里却是空的 

1条回答
Anonyem
2021-03-18 14:44


在网上搜了很多如何通过ccxt获取okex的k线数据,都是说的含糊不清,这里记录一下。

当前使用的ccxt版本是1.30.14,该版本中okex3已经不再使用了,统一使用okex。

 

1、替换okex.com

ccxt的okex相关代码都在lib/python3.7/site-packages/ccxt/okex.py这个文件中,

直接修改这里的okex.com为okex.me就可以访问了,但是这样会影响以后的升级、影响代码的移植,很麻烦。

博主这里通过传参的方式将okex.com都替换成okex.me,其他交易所也可以用这种方法。


 

exchange=ccxt.okex({

'hostname':'okex.me',

'urls':{

'logo':'https://user-images.githubusercontent.com/1294454/32552768-0d6dd3c6-c4a6-11e7-90f8-c043b64756a7.jpg',

'api':{

'rest':'https://www.okex.me',

},

'www':'https://www.okex.me',

'doc':'https://www.okex.me/docs/en/',

'fees':'https://www.okex.me/pages/products/fees.html',

'referral':'https://www.okex.me/join/1888677',

'test':{

'rest':'https://testnet.okex.me',

},

}})

 

2、获取k线

fetch_ohlcv需要传入的起始时间格式是毫秒时间戳,同样,返回的也是毫秒时间戳。

importccxt

importtime

importpandasaspd



defcreate_exchange():

exchange=ccxt.okex({

'hostname':'okex.me',

'urls':{

'logo':'https://user-images.githubusercontent.com/1294454/32552768-0d6dd3c6-c4a6-11e7-90f8-c043b64756a7.jpg',

'api':{

'rest':'https://www.okex.me',

},

'www':'https://www.okex.me',

'doc':'https://www.okex.me/docs/en/',

'fees':'https://www.okex.me/pages/products/fees.html',

'referral':'https://www.okex.me/join/1888677',

'test':{

'rest':'https://testnet.okex.me',

},

}})

returnexchange



defget_candles(symbol,k_time,since_time):

exchange=create_exchange()

candles=exchange.fetch_ohlcv(symbol,k_time,since_time)

df=pd.DataFrame(candles)

df.rename(columns={0:'MTS',1:'open',2:'high',3:'low',4:'close',5:'volume'},inplace=True)

df['MTS']=pd.to_datetime(df['MTS'],unit='ms')+pd.Timedelta(hours=8)

returndf



if__name__=='__main__':

symbol='BTC-USD-200925'

limit=100

k_time='1m'

current_time=int(time.time()//60*60*1000)

since_time=current_time-limit*60*1000


df=get_candles(symbol,k_time,since_time)

print(df)


 

3、注意

通常情况下获取到的最后一根K线是不完整的,具体原因自己思考~,入库时候要注意处理,否则会导致数据不准确,比如用df.drop掉最后一条数据。

4、再来一波

各个交易所接口提供的数据都不多,比如okex的季度交割合约,分钟级数据只提供最近的300条,这个数据对我们来说毫无作用。

博主这里长期采集OKEX、火币、币安的分钟级别数据,需要的联系我wh909077093,备注(k线),比市面上合适多的多哦。


一周热门 更多>