CCXT:加密貨幣量化交易神器

支持許多交易市場(chǎng),甚至即將推出的 為所有交易提供完整的公共和私人API 所有貨幣,山寨幣和標(biāo)記,價(jià)格,訂單,交易,代碼等… 提供用于交叉交換或跨貨幣分析和套利的可選標(biāo)準(zhǔn)化數(shù)據(jù) 開箱即用的統(tǒng)一的一體化API,非常易于集成 適用于Node7.6+,Python2和3,PHP5.4+,Web瀏覽器

NPM中的ccxt(JavaScript/Node v7.6+) PyPI中的ccxt(Python 2和3.5.3+) Packagist/Composer中的ccxt(PHP 5.4+)
js/在JavaScript中 python/在Python中(從JS生成) PHP/ PHP(從JS生成)
git clone https://github.com/ccxt/ccxt.git
安裝
pip install ccxt
常用接口
# 初始化交易所
binance_exchange = ccxt.binance({
'timeout': 15000,
'enableRateLimit': True
})
# 獲取單個(gè)交易對(duì)ticker數(shù)據(jù)
binance_exchange.fetchTicker(symbol)
# 獲取多個(gè)交易對(duì)ticker數(shù)據(jù)
tickers_data = binance_exchange.fetchTickers(['BTC/USDT', 'ETH/USDT'])
# 交易委托賬本數(shù)據(jù)獲取
binance_exchange.fetch_order_book(symbol)
# K線數(shù)據(jù)數(shù)據(jù)獲取
binance_exchange.fetch_ohlcv(symbol, timeframe='1d')
使用
市場(chǎng)數(shù)據(jù) 交易對(duì) 交易手續(xù)費(fèi) 訂單薄/深度數(shù)據(jù) 交易歷史 行情/Tickers 用以制圖的 OHLC(V)/K線 其他公共接口
管理個(gè)人賬戶信息 查詢賬戶余額 通過市價(jià)單和限價(jià)單進(jìn)行交易 存入和提取法幣和加密貨幣 查詢個(gè)人訂單 獲取交易明細(xì)/歷史 在賬戶之間轉(zhuǎn)移資金 使用商業(yè)服務(wù)
camelcase表示法(在JavaScript中是首選)和下劃線表示法(在Python和PHP中首選),因此所有方法都可以用任何語(yǔ)言的符號(hào)或編碼方式調(diào)用。
// both of these notations work in JavaScript/Python/PHP
exchange.methodName () // camelcase pseudocode
exchange.method_name () // underscore pseudocode
# coding=utf-8
import ccxt
hitbtc = ccxt.hitbtc({'verbose': True})
bitmex = ccxt.bitmex()
huobi = ccxt.huobi()
exmo = ccxt.exmo({
'apiKey': 'YOUR_PUBLIC_API_KEY',
'secret': 'YOUR_SECRET_PRIVATE_KEY',
})
kraken = ccxt.kraken({
'apiKey': 'YOUR_PUBLIC_API_KEY',
'secret': 'YOUR_SECRET_PRIVATE_KEY',
})
exchange_id = 'binance'
exchange_class = getattr(ccxt, exchange_id)
exchange = exchange_class({
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_SECRET',
'timeout': 30000,
'enableRateLimit': True,
})
hitbtc_markets = hitbtc.load_markets()
print(hitbtc.id, hitbtc_markets)
print(bitmex.id, bitmex.load_markets())
print(huobi.id, huobi.load_markets())
print(hitbtc.fetch_order_book(hitbtc.symbols[0]))
print(bitmex.fetch_ticker('BTC/USD'))
print(huobi.fetch_trades('LTC/CNY'))
print(exmo.fetch_balance())
# sell one ? for market price and receive $ right now
print(exmo.id, exmo.create_market_sell_order('BTC/USD', 1))
# limit buy BTC/EUR, you pay €2500 and receive ?1 when the order is closed
print(exmo.id, exmo.create_limit_buy_order('BTC/EUR', 1, 2500.00))
# pass/redefine custom exchange-specific order params: type, amount, price, flags, etc...
kraken.create_market_buy_order('BTC/USD', 1, {'trading_agreement': 'agree'})

