# -*- coding: utf-8 -*-
"""Base exchange class"""
# -----------------------------------------------------------------------------
__version__ = '1.14.208'
# -----------------------------------------------------------------------------
from ccxt.base.errors import ExchangeError
from ccxt.base.errors import NotSupported
from ccxt.base.errors import AuthenticationError
from ccxt.base.errors import DDoSProtection
from ccxt.base.errors import RequestTimeout
from ccxt.base.errors import ExchangeNotAvailable
from ccxt.base.errors import InvalidAddress
# -----------------------------------------------------------------------------
from ccxt.base.decimal_to_precision import decimal_to_precision
from ccxt.base.decimal_to_precision import DECIMAL_PLACES
# -----------------------------------------------------------------------------
__all__ = [
'Exchange',
]
# -----------------------------------------------------------------------------
# Python 2 & 3
import logging
import base64
import calendar
import collections
import datetime
from email.utils import parsedate
import functools
import gzip
import hashlib
import hmac
import io
import json
import math
from numbers import Number
import re
from requests import Session
from requests.utils import default_user_agent
from requests.exceptions import HTTPError, Timeout, TooManyRedirects, RequestException
# import socket
from ssl import SSLError
# import sys
import time
import uuid
import zlib
from decimal import Decimal
# -----------------------------------------------------------------------------
try:
import urllib.parse as _urlencode # Python 3
except ImportError:
import urllib as _urlencode # Python 2
# -----------------------------------------------------------------------------
try:
basestring # Python 3
except NameError:
basestring = str # Python 2
# -----------------------------------------------------------------------------
class Exchange(object):
"""Base exchange class"""
id = None
version = None
# rate limiter settings
enableRateLimit = False
rateLimit = 2000 # milliseconds = seconds * 1000
timeout = 10000 # milliseconds = seconds * 1000
asyncio_loop = None
aiohttp_proxy = None
session = None # Session () by default
logger = None # logging.getLogger(__name__) by default
userAgent = None
userAgents = {
'chrome': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36',
'chrome39': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36',
}
verbose = False
markets = None
symbols = None
fees = {
'trading': {
'fee_loaded': False,
'percentage': True, # subclasses should rarely have to redefine this
},
'funding': {
'fee_loaded': False,
'withdraw': {},
'deposit': {},
},
}
ids = None
tickers = None
api = None
parseJsonResponse = True
proxy = ''
origin = '*' # CORS origin
proxies = None
apiKey = ''
secret = ''
password = ''
uid = ''
twofa = False
marketsById = None
markets_by_id = None
currencies_by_id = None
precision = None
limits = None
exceptions = None
headers = None
balance = None
orderbooks = None
orders = None
trades = None
currencies = None
options = None # Python does not allow to define properties in run-time with setattr
requiredCredentials = {
'apiKey': True,
'secret': True,
'uid': False,
'login': False,
'password': False,
'twofa': False, # 2-factor authentication (one-time password key)
}
# API method metainfo
has = {
'publicAPI': True,
'privateAPI': True,
'CORS': False,
'cancelOrder': True,
'cancelOrders': False,
'createDepositAddress': False,
'createOrder': True,
'createMarketOrder': True,
'createLimitOrder': True,
'deposit': False,
'editOrder': 'emulated',
'fetchBalance': True,
'fetchClosedOrders': False,
'fetchCurrencies': False,
'fetchDepositAddress': False,
'fetchFundingFees': False,
'fetchL2OrderBook': True,
'fetchMarkets': True,
'fetchMyTrades': False,
'fetchOHLCV': 'emulated',
'fetchOpenOrders': False,
'fetchOrder': False,
'fetchOrderBook': True,
'fetchOrderBooks': False,
'fetchOrders': False,
'fetchTicker': True,
'fetchTickers': False,
'fetchTrades': True,
'fetchTradingFees': False,
'fetchTradingLimits': False,
'withdraw': False,
}
precisionMode = DECIMAL_PLACES
minFundingAddressLength = 1 # used in check_address
substituteCommonCurrencyCodes = True
lastRestRequestTimestamp = 0
lastRestPollTimestamp = 0
restRequestQueue = None
restPollerLoopIsRunning = False
rateLimitTokens = 16
rateLimitMaxTokens = 16
rateLimitUpdateTime = 0
last_http_response = None
last_json_response = None
last_response_headers = None
commonCurrencies = {
'XBT': 'BTC',
'BCC': 'BCH',
'DRK': 'DASH',
}
def __init__(self, config={}):
self.precision = {} if self.precision is None else self.precision
self.limits = {} if self.limits is None else self.limits
self.exceptions = {} if self.exceptions is None else self.exceptions
self.headers = {} if self.headers is None else self.headers
self.balance = {} if self.balance is None else self.balance
self.orderbooks = {} if self.orderbooks is None else self.orderbooks
self.orders = {} if self.orders is None else self.orders
self.trades = {} if self.trades is None else self.trades
self.currencies = {} if self.currencies is None else self.currencies
self.options = {} if self.options is None else self.options # Python does not allow to define properties in run-time with setattr
self.decimalToPrecision = self.decimal_to_precision = decimal_to_precision
# version = '.'.join(map(str, sys.version_info[:3]))
# self.userAgent = {
# 'User-Agent': 'ccxt/' + __version__ + ' (+https://github.com/ccxt/ccxt) Python/' + version
# }
self.userAgent = default_user_agent()
settings = self.deep_extend(self.describe(), config)
for key in settings:
if hasattr(self, key) and isinstance(getattr(self, key), dict):
setattr(self, key, self.deep_extend(getattr(self, key), settings[key]))
else:
setattr(self, key, settings[key])
if self.api:
self.define_rest_api(self.api, 'request')
if self.markets:
self.set_markets(self.markets)
# format camel case
for attr in dir(self):
if attr[0] != '_'and attr[-1] != '_' and '_' in attr:
conv = attr.split('_')
camel_case = conv[0] + ''.join(i[0].upper() + i[1:] for i in conv[1:])
setattr(self, camel_case, getattr(self, attr))
self.tokenBucket = self.extend({
'refillRate': 1.0 / self.rateLimit,
'delay': 1.0,
'capacity': 1.0,
'defaultCost': 1.0,
}, getattr(self, 'tokenBucket') if hasattr(self, 'tokenBucket') else {})
self.session = self.session if self.session else Session()
self.logger = self.logger if self.logger else logging.getLogger(__name__)
def __del__(self):
if self.session:
self.session.close()
def describe(self):
return {}
def define_rest_api(self, api, method_name, options={}):
delimiters = re.compile('[^a-zA-Z0-9]')
for api_type, methods in api.items():
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
PyPI 官网下载 | ccxt-1.14.208.tar.gz (265个子文件)
setup.cfg 205B
MANIFEST.in 100B
package.json 7KB
PKG-INFO 98KB
PKG-INFO 98KB
exchange.py 49KB
cointiger.py 44KB
cointiger.py 43KB
kucoin.py 43KB
kucoin.py 43KB
hitbtc2.py 41KB
hitbtc2.py 41KB
binance.py 37KB
binance.py 37KB
kraken.py 34KB
kraken.py 34KB
bitfinex.py 33KB
hitbtc.py 33KB
bitfinex.py 33KB
hitbtc.py 32KB
gatecoin.py 32KB
gatecoin.py 31KB
poloniex.py 30KB
poloniex.py 30KB
huobipro.py 29KB
bittrex.py 29KB
huobipro.py 29KB
bittrex.py 29KB
liqui.py 28KB
cryptopia.py 28KB
liqui.py 28KB
okcoinusd.py 28KB
cryptopia.py 28KB
okcoinusd.py 28KB
coinexchange.py 25KB
bibox.py 25KB
coinexchange.py 25KB
bibox.py 25KB
exmo.py 25KB
exmo.py 24KB
livecoin.py 24KB
livecoin.py 24KB
bitstamp.py 23KB
bitstamp.py 22KB
bitmex.py 22KB
bitmex.py 22KB
cobinhood.py 22KB
indodax.py 22KB
indodax.py 22KB
cobinhood.py 22KB
gdax.py 21KB
gdax.py 21KB
bitbank.py 21KB
bitbank.py 21KB
gateio.py 20KB
cex.py 20KB
zb.py 19KB
gateio.py 19KB
bitso.py 19KB
coinegg.py 19KB
cex.py 19KB
zb.py 19KB
coinegg.py 19KB
bitso.py 19KB
lbank.py 18KB
lbank.py 17KB
btcmarkets.py 17KB
qryptos.py 17KB
qryptos.py 17KB
btcmarkets.py 17KB
bitbay.py 17KB
bitbay.py 17KB
bitfinex2.py 17KB
bitfinex2.py 16KB
coinex.py 16KB
braziliex.py 16KB
coinex.py 16KB
braziliex.py 16KB
bitsane.py 16KB
bitsane.py 16KB
ice3x.py 15KB
acx.py 15KB
bitz.py 15KB
ice3x.py 15KB
bitz.py 15KB
acx.py 15KB
coinbase.py 14KB
coinbase.py 14KB
coinone.py 14KB
bitflyer.py 14KB
coinone.py 14KB
tidebit.py 14KB
test_async.py 14KB
bitflyer.py 14KB
coinsecure.py 14KB
tidebit.py 14KB
coinsecure.py 14KB
bithumb.py 14KB
__init__.py 14KB
bithumb.py 14KB
共 265 条
- 1
- 2
- 3
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功