commit
52707d9acb
@ -0,0 +1,10 @@
|
|||||||
|
pipeline:
|
||||||
|
ssh:
|
||||||
|
image: 'me/sre/drone-ssh:20210519'
|
||||||
|
host: 172.16.0.22
|
||||||
|
username: root
|
||||||
|
password: 123456
|
||||||
|
port: 22
|
||||||
|
#username: deploy+ volumes:+ -/root/drone_rsa:/root/ssh/drone_rsa key_path:/root/ssh/drone_rsa
|
||||||
|
script:
|
||||||
|
- echo"test ssh1"
|
||||||
@ -0,0 +1,118 @@
|
|||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
*.idea/*
|
||||||
|
*.idea
|
||||||
|
*.iml
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
.DS_Store
|
||||||
|
config.json
|
||||||
|
venv
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
nohub.out
|
||||||
|
myquant.txt
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
.python-version
|
||||||
|
|
||||||
|
# celery beat schedule file
|
||||||
|
celerybeat-schedule
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.idea
|
||||||
|
.idea/*
|
||||||
|
|
||||||
|
# log file
|
||||||
|
grid_trader_log.txt
|
||||||
|
*.log
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
#mmmmmmmmmmmm/binance_grid_trader:67
|
||||||
|
FROM python:3.9
|
||||||
|
#RUN pip install -r requirements.txt
|
||||||
|
WORKDIR /app
|
||||||
|
ADD . /app
|
||||||
|
RUN python -m pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
|
||||||
|
CMD ["python", "main.py"]
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
#mmmmmmmmmmmmmmmmmmmmmmmmm/binance_grid_trader_requirements:5
|
||||||
|
FROM python:3.9
|
||||||
|
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
requests==2.22.0
|
||||||
|
dingtalkchatbot
|
||||||
|
pytz
|
||||||
|
APScheduler==3.6.3
|
||||||
|
aiohttp==3.6.2
|
||||||
|
websocket_client==0.57.0
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
from .binance_constant import OrderType, OrderStatus, OrderSide, RequestMethod,Interval
|
||||||
|
from .binance_spot import BinanceSpotHttp
|
||||||
|
from .binance_future import BinanceFutureHttp
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
class RequestMethod(Enum):
|
||||||
|
"""
|
||||||
|
请求的方法.
|
||||||
|
"""
|
||||||
|
GET = 'GET'
|
||||||
|
POST = 'POST'
|
||||||
|
PUT = 'PUT'
|
||||||
|
DELETE = 'DELETE'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class OrderStatus(Enum):
|
||||||
|
NEW = "NEW"
|
||||||
|
PARTIALLY_FILLED = "PARTIALLY_FILLED"
|
||||||
|
FILLED = "FILLED"
|
||||||
|
CANCELED = "CANCELED"
|
||||||
|
PENDING_CANCEL = "PENDING_CANCEL"
|
||||||
|
REJECTED = "REJECTED"
|
||||||
|
EXPIRED = "EXPIRED"
|
||||||
|
|
||||||
|
|
||||||
|
class OrderType(Enum):
|
||||||
|
LIMIT = "LIMIT"
|
||||||
|
MARKET = "MARKET"
|
||||||
|
STOP = "STOP"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class OrderSide(Enum):
|
||||||
|
BUY = "BUY"
|
||||||
|
SELL = "SELL"
|
||||||
|
|
||||||
|
|
||||||
|
class Interval(Enum):
|
||||||
|
"""
|
||||||
|
请求的K线数据..
|
||||||
|
"""
|
||||||
|
MINUTE_1 = '1m'
|
||||||
|
MINUTE_3 = '3m'
|
||||||
|
MINUTE_5 = '5m'
|
||||||
|
MINUTE_15 = '15m'
|
||||||
|
MINUTE_30 = '30m'
|
||||||
|
HOUR_1 = '1h'
|
||||||
|
HOUR_2 = '2h'
|
||||||
|
HOUR_4 = '4h'
|
||||||
|
HOUR_6 = '6h'
|
||||||
|
HOUR_8 = '8h'
|
||||||
|
HOUR_12 = '12h'
|
||||||
|
DAY_1 = '1d'
|
||||||
|
DAY_3 = '3d'
|
||||||
|
WEEK_1 = '1w'
|
||||||
|
MONTH_1 = '1M'
|
||||||
|
|
||||||
@ -0,0 +1,345 @@
|
|||||||
|
from binance import OrderType, OrderStatus, OrderSide, RequestMethod,Interval
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
|
import hmac
|
||||||
|
import hashlib
|
||||||
|
from threading import Thread, Lock
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
class BinanceFutureHttp(object):
|
||||||
|
|
||||||
|
def __init__(self, api_key=None, secret=None, host=None, proxy_host="", proxy_port=0, timeout=5, try_counts=5):
|
||||||
|
self.key = api_key
|
||||||
|
self.secret = secret
|
||||||
|
self.host = host if host else "https://fapi.binance.com"
|
||||||
|
self.recv_window = 5000
|
||||||
|
self.timeout = timeout
|
||||||
|
self.order_count_lock = Lock()
|
||||||
|
self.order_count = 1_000_000
|
||||||
|
self.try_counts = try_counts # 失败尝试的次数.
|
||||||
|
self.proxy_host = proxy_host
|
||||||
|
self.proxy_port = proxy_port
|
||||||
|
|
||||||
|
@property
|
||||||
|
def proxies(self):
|
||||||
|
if self.proxy_host and self.proxy_port:
|
||||||
|
proxy = f"http://{self.proxy_host}:{self.proxy_port}"
|
||||||
|
return {"http": proxy, "https": proxy}
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def build_parameters(self, params: dict):
|
||||||
|
keys = list(params.keys())
|
||||||
|
keys.sort()
|
||||||
|
return '&'.join([f"{key}={params[key]}" for key in params.keys()])
|
||||||
|
|
||||||
|
def request(self, req_method: RequestMethod, path: str, requery_dict=None, verify=False):
|
||||||
|
url = self.host + path
|
||||||
|
|
||||||
|
if verify:
|
||||||
|
query_str = self._sign(requery_dict)
|
||||||
|
url += '?' + query_str
|
||||||
|
elif requery_dict:
|
||||||
|
url += '?' + self.build_parameters(requery_dict)
|
||||||
|
headers = {"X-MBX-APIKEY": self.key}
|
||||||
|
|
||||||
|
for i in range(0, self.try_counts):
|
||||||
|
try:
|
||||||
|
response = requests.request(req_method.value, url=url, headers=headers, timeout=self.timeout, proxies=self.proxies)
|
||||||
|
if response.status_code == 200:
|
||||||
|
return response.json()
|
||||||
|
else:
|
||||||
|
print(f"请求没有成功: {response.status_code}, 继续尝试请求")
|
||||||
|
except Exception as error:
|
||||||
|
print(f"请求:{path}, 发生了错误: {error}, 时间: {datetime.now()}")
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
|
def server_time(self):
|
||||||
|
path = '/fapi/v1/time'
|
||||||
|
return self.request(req_method=RequestMethod.GET, path=path)
|
||||||
|
|
||||||
|
def exchangeInfo(self):
|
||||||
|
|
||||||
|
"""
|
||||||
|
{'timezone': 'UTC', 'serverTime': 1570802268092, 'rateLimits':
|
||||||
|
[{'rateLimitType': 'REQUEST_WEIGHT', 'interval': 'MINUTE', 'intervalNum': 1, 'limit': 1200},
|
||||||
|
{'rateLimitType': 'ORDERS', 'interval': 'MINUTE', 'intervalNum': 1, 'limit': 1200}],
|
||||||
|
'exchangeFilters': [], 'symbols':
|
||||||
|
[{'symbol': 'BTCUSDT', 'status': 'TRADING', 'maintMarginPercent': '2.5000', 'requiredMarginPercent': '5.0000',
|
||||||
|
'baseAsset': 'BTC', 'quoteAsset': 'USDT', 'pricePrecision': 2, 'quantityPrecision': 3, 'baseAssetPrecision': 8,
|
||||||
|
'quotePrecision': 8,
|
||||||
|
'filters': [{'minPrice': '0.01', 'maxPrice': '100000', 'filterType': 'PRICE_FILTER', 'tickSize': '0.01'},
|
||||||
|
{'stepSize': '0.001', 'filterType': 'LOT_SIZE', 'maxQty': '1000', 'minQty': '0.001'},
|
||||||
|
{'stepSize': '0.001', 'filterType': 'MARKET_LOT_SIZE', 'maxQty': '1000', 'minQty': '0.001'},
|
||||||
|
{'limit': 200, 'filterType': 'MAX_NUM_ORDERS'},
|
||||||
|
{'multiplierDown': '0.8500', 'multiplierUp': '1.1500', 'multiplierDecimal': '4', 'filterType': 'PERCENT_PRICE'}],
|
||||||
|
'orderTypes': ['LIMIT', 'MARKET', 'STOP'], 'timeInForce': ['GTC', 'IOC', 'FOK', 'GTX']}]}
|
||||||
|
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
|
path = '/fapi/v1/exchangeInfo'
|
||||||
|
return self.request(req_method=RequestMethod.GET, path=path)
|
||||||
|
|
||||||
|
def order_book(self, symbol, limit=5):
|
||||||
|
limits = [5, 10, 20, 50, 100, 500, 1000]
|
||||||
|
if limit not in limits:
|
||||||
|
limit = 5
|
||||||
|
|
||||||
|
path = "/fapi/v1/depth"
|
||||||
|
query_dict = {"symbol": symbol,
|
||||||
|
"limit": limit
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.request(RequestMethod.GET, path, query_dict)
|
||||||
|
|
||||||
|
def get_kline(self, symbol, interval: Interval, start_time=None, end_time=None, limit=500, max_try_time=10):
|
||||||
|
"""
|
||||||
|
|
||||||
|
:param symbol:
|
||||||
|
:param interval:
|
||||||
|
:param start_time:
|
||||||
|
:param end_time:
|
||||||
|
:param limit:
|
||||||
|
:return:
|
||||||
|
[
|
||||||
|
1499040000000, // 开盘时间
|
||||||
|
"0.01634790", // 开盘价
|
||||||
|
"0.80000000", // 最高价
|
||||||
|
"0.01575800", // 最低价
|
||||||
|
"0.01577100", // 收盘价(当前K线未结束的即为最新价)
|
||||||
|
"148976.11427815", // 成交量
|
||||||
|
1499644799999, // 收盘时间
|
||||||
|
"2434.19055334", // 成交额
|
||||||
|
308, // 成交笔数
|
||||||
|
"1756.87402397", // 主动买入成交量
|
||||||
|
"28.46694368", // 主动买入成交额
|
||||||
|
"17928899.62484339" // 请忽略该参数
|
||||||
|
]
|
||||||
|
"""
|
||||||
|
path = "/fapi/v1/klines"
|
||||||
|
|
||||||
|
query_dict = {
|
||||||
|
"symbol": symbol,
|
||||||
|
"interval": interval.value,
|
||||||
|
"limit": limit
|
||||||
|
}
|
||||||
|
|
||||||
|
if start_time:
|
||||||
|
query_dict['startTime'] = start_time
|
||||||
|
|
||||||
|
if end_time:
|
||||||
|
query_dict['endTime'] = end_time
|
||||||
|
|
||||||
|
for i in range(max_try_time):
|
||||||
|
data = self.request(RequestMethod.GET, path, query_dict)
|
||||||
|
if isinstance(data, list) and len(data):
|
||||||
|
return data
|
||||||
|
|
||||||
|
def get_latest_price(self, symbol):
|
||||||
|
path = "/fapi/v1/ticker/price"
|
||||||
|
query_dict = {"symbol": symbol}
|
||||||
|
return self.request(RequestMethod.GET, path, query_dict)
|
||||||
|
|
||||||
|
def get_ticker(self, symbol):
|
||||||
|
path = "/fapi/v1/ticker/bookTicker"
|
||||||
|
query_dict = {"symbol": symbol}
|
||||||
|
return self.request(RequestMethod.GET, path, query_dict)
|
||||||
|
|
||||||
|
########################### the following request is for private data ########################
|
||||||
|
|
||||||
|
def _timestamp(self):
|
||||||
|
return int(time.time() * 1000)
|
||||||
|
|
||||||
|
def _sign(self, params):
|
||||||
|
|
||||||
|
requery_string = self.build_parameters(params)
|
||||||
|
hexdigest = hmac.new(self.secret.encode('utf8'), requery_string.encode("utf-8"), hashlib.sha256).hexdigest()
|
||||||
|
return requery_string + '&signature=' + str(hexdigest)
|
||||||
|
|
||||||
|
def get_client_order_id(self):
|
||||||
|
|
||||||
|
"""
|
||||||
|
generate the client_order_id for user.
|
||||||
|
:return: new client order id
|
||||||
|
"""
|
||||||
|
with self.order_count_lock:
|
||||||
|
self.order_count += 1
|
||||||
|
return "x-cLbi5uMH" + str(self._timestamp()) + str(self.order_count)
|
||||||
|
|
||||||
|
def place_order(self, symbol: str, order_side: OrderSide, order_type: OrderType, quantity, price,
|
||||||
|
time_inforce="GTC", client_order_id=None, recvWindow=5000, stop_price=0):
|
||||||
|
|
||||||
|
"""
|
||||||
|
下单..
|
||||||
|
:param symbol: BTCUSDT
|
||||||
|
:param side: BUY or SELL
|
||||||
|
:param type: LIMIT MARKET STOP
|
||||||
|
:param quantity: 数量.
|
||||||
|
:param price: 价格
|
||||||
|
:param stop_price: 停止单的价格.
|
||||||
|
:param time_inforce:
|
||||||
|
:param params: 其他参数
|
||||||
|
|
||||||
|
LIMIT : timeInForce, quantity, price
|
||||||
|
MARKET : quantity
|
||||||
|
STOP: quantity, price, stopPrice
|
||||||
|
:return:
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
path = '/fapi/v1/order'
|
||||||
|
|
||||||
|
if client_order_id is None:
|
||||||
|
client_order_id = self.get_client_order_id()
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"symbol": symbol,
|
||||||
|
"side": order_side.value,
|
||||||
|
"type": order_type.value,
|
||||||
|
"quantity": quantity,
|
||||||
|
"price": price,
|
||||||
|
"recvWindow": recvWindow,
|
||||||
|
"timeInForce": "GTC",
|
||||||
|
"timestamp": self._timestamp(),
|
||||||
|
"newClientOrderId": client_order_id
|
||||||
|
}
|
||||||
|
|
||||||
|
if order_type == OrderType.LIMIT:
|
||||||
|
params['timeInForce'] = time_inforce
|
||||||
|
|
||||||
|
if order_type == OrderType.MARKET:
|
||||||
|
if params.get('price'):
|
||||||
|
del params['price']
|
||||||
|
|
||||||
|
if order_type == OrderType.STOP:
|
||||||
|
if stop_price > 0:
|
||||||
|
params["stopPrice"] = stop_price
|
||||||
|
else:
|
||||||
|
raise ValueError("stopPrice must greater than 0")
|
||||||
|
# print(params)
|
||||||
|
return self.request(RequestMethod.POST, path=path, requery_dict=params, verify=True)
|
||||||
|
|
||||||
|
def get_order(self, symbol, client_order_id=None):
|
||||||
|
path = "/fapi/v1/order"
|
||||||
|
query_dict = {"symbol": symbol, "timestamp": self._timestamp()}
|
||||||
|
if client_order_id:
|
||||||
|
query_dict["origClientOrderId"] = client_order_id
|
||||||
|
|
||||||
|
return self.request(RequestMethod.GET, path, query_dict, verify=True)
|
||||||
|
|
||||||
|
def cancel_order(self, symbol, client_order_id=None):
|
||||||
|
path = "/fapi/v1/order"
|
||||||
|
params = {"symbol": symbol, "timestamp": self._timestamp()}
|
||||||
|
if client_order_id:
|
||||||
|
params["origClientOrderId"] = client_order_id
|
||||||
|
|
||||||
|
return self.request(RequestMethod.DELETE, path, params, verify=True)
|
||||||
|
|
||||||
|
def get_open_orders(self, symbol=None):
|
||||||
|
path = "/fapi/v1/openOrders"
|
||||||
|
|
||||||
|
params = {"timestamp": self._timestamp()}
|
||||||
|
if symbol:
|
||||||
|
params["symbol"] = symbol
|
||||||
|
|
||||||
|
return self.request(RequestMethod.GET, path, params, verify=True)
|
||||||
|
|
||||||
|
def cancel_open_orders(self, symbol):
|
||||||
|
"""
|
||||||
|
撤销某个交易对的所有挂单
|
||||||
|
:param symbol: symbol
|
||||||
|
:return: return a list of orders.
|
||||||
|
"""
|
||||||
|
path = "/fapi/v1/allOpenOrders"
|
||||||
|
|
||||||
|
params = {"timestamp": self._timestamp(),
|
||||||
|
"recvWindow": self.recv_window,
|
||||||
|
"symbol": symbol
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.request(RequestMethod.DELETE, path, params, verify=True)
|
||||||
|
|
||||||
|
def get_balance(self):
|
||||||
|
"""
|
||||||
|
[{'accountId': 18396, 'asset': 'USDT', 'balance': '530.21334791', 'withdrawAvailable': '530.21334791', 'updateTime': 1570330854015}]
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
path = "/fapi/v1/balance"
|
||||||
|
params = {"timestamp": self._timestamp()}
|
||||||
|
|
||||||
|
return self.request(RequestMethod.GET, path=path, requery_dict=params, verify=True)
|
||||||
|
|
||||||
|
def get_account_info(self):
|
||||||
|
"""
|
||||||
|
{'feeTier': 2, 'canTrade': True, 'canDeposit': True, 'canWithdraw': True, 'updateTime': 0, 'totalInitialMargin': '0.00000000',
|
||||||
|
'totalMaintMargin': '0.00000000', 'totalWalletBalance': '530.21334791', 'totalUnrealizedProfit': '0.00000000',
|
||||||
|
'totalMarginBalance': '530.21334791', 'totalPositionInitialMargin': '0.00000000', 'totalOpenOrderInitialMargin': '0.00000000',
|
||||||
|
'maxWithdrawAmount': '530.2133479100000', 'assets':
|
||||||
|
[{'asset': 'USDT', 'walletBalance': '530.21334791', 'unrealizedProfit': '0.00000000', 'marginBalance': '530.21334791',
|
||||||
|
'maintMargin': '0.00000000', 'initialMargin': '0.00000000', 'positionInitialMargin': '0.00000000', 'openOrderInitialMargin': '0.00000000',
|
||||||
|
'maxWithdrawAmount': '530.2133479100000'}]}
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
path = "/fapi/v1/account"
|
||||||
|
params = {"timestamp": self._timestamp()}
|
||||||
|
return self.request(RequestMethod.GET, path, params, verify=True)
|
||||||
|
|
||||||
|
def get_position_info(self):
|
||||||
|
"""
|
||||||
|
[{'symbol': 'BTCUSDT', 'positionAmt': '0.000', 'entryPrice': '0.00000', 'markPrice': '8326.40833498', 'unRealizedProfit': '0.00000000', 'liquidationPrice': '0'}]
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
path = "/fapi/v1/positionRisk"
|
||||||
|
params = {"timestamp": self._timestamp()}
|
||||||
|
return self.request(RequestMethod.GET, path, params, verify=True)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# import pandas as pd
|
||||||
|
|
||||||
|
key = "xxxx"
|
||||||
|
secret = 'xxxx'
|
||||||
|
binance = BinanceFutureHttp(api_key=key, secret=secret)
|
||||||
|
|
||||||
|
# import datetime
|
||||||
|
# print(datetime.datetime.now())
|
||||||
|
|
||||||
|
data = binance.get_kline('BTCUSDT', Interval.HOUR_1, limit=100)
|
||||||
|
print(data)
|
||||||
|
print(isinstance(data, list))
|
||||||
|
|
||||||
|
exit()
|
||||||
|
# info = binance.exchangeInfo()
|
||||||
|
# print(info)
|
||||||
|
# exit()
|
||||||
|
# print(binance.order_book(symbol='BTCUSDT', limit=5))
|
||||||
|
# exit()
|
||||||
|
|
||||||
|
# print(binance.latest_price('BTCUSDT'))
|
||||||
|
# kline = binance.kline('BTCUSDT', interval='1m')
|
||||||
|
# print(pd.DataFrame(kline))
|
||||||
|
|
||||||
|
# print(binance.ticker("BTCUSDT"))
|
||||||
|
|
||||||
|
# print(binance.get_ticker('BTCUSDT'))
|
||||||
|
# {'symbol': 'BTCUSDT', 'side': 'SELL', 'type': 'LIMIT', 'quantity': 0.001, 'price': 8360.82, 'recvWindow': 5000, 'timestamp': 1570969995974, 'timeInForce': 'GTC'}
|
||||||
|
|
||||||
|
# data = binance.place_order(symbol="BTCUSDT", side=OrderSide.BUY, order_type=OrderType.MARKET, quantity=0.001, price=8250.82)
|
||||||
|
# print(data)
|
||||||
|
|
||||||
|
# cancel_order = binance.cancel_order("BTCUSDT", order_id="30714952")
|
||||||
|
# print(cancel_order)
|
||||||
|
|
||||||
|
# balance = binance.get_balance()
|
||||||
|
# print(balance)
|
||||||
|
|
||||||
|
# account_info = binance.get_account_info()
|
||||||
|
# print(account_info)
|
||||||
|
|
||||||
|
# account_info = binance.get_position_info()
|
||||||
|
# print(account_info)
|
||||||
|
|
||||||
|
"""
|
||||||
|
{'orderId': 30714952, 'symbol': 'BTCUSDT', 'accountId': 18396, 'status': 'NEW', 'clientOrderId': 'ZC3qSbzbODl0GId9idK9hM', 'price': '7900', 'origQty': '0.010', 'executedQty': '0', 'cumQty': '0', 'cumQuote': '0', 'timeInForce': 'GTC', 'type': 'LIMIT', 'reduceOnly': False, 'side': 'BUY', 'stopPrice': '0', 'updateTime': 1569658787083}
|
||||||
|
{'orderId': 30714952, 'symbol': 'BTCUSDT', 'accountId': 18396, 'status': 'NEW', 'clientOrderId': 'ZC3qSbzbODl0GId9idK9hM', 'price': '7900', 'origQty': '0.010', 'executedQty': '0', 'cumQty': '0', 'cumQuote': '0', 'timeInForce': 'GTC', 'type': 'LIMIT', 'reduceOnly': False, 'side': 'BUY', 'stopPrice': '0', 'updateTime': 1569658787083}
|
||||||
|
"""
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"sleep_time": 10,
|
||||||
|
"cancel_time": 120,
|
||||||
|
"platform": "binance_spot",
|
||||||
|
"symbol": "SHIBUSDT",
|
||||||
|
"api_key": "44444444444444444444444444",
|
||||||
|
"api_secret": "4444444444444444444444444444444444444444444444444444",
|
||||||
|
"profit_scroll": 1.005,
|
||||||
|
"profit_intend": 0.996,
|
||||||
|
"deficit_scroll": 0.985,
|
||||||
|
"gap_percent": 0.01,
|
||||||
|
"quantity": 500000,
|
||||||
|
"min_price": 0.00000001,
|
||||||
|
"price_stop_to_buy": 0.7,
|
||||||
|
"price_stop_to_sell": 0.5,
|
||||||
|
"min_qty": 100000,
|
||||||
|
"max_orders": 2,
|
||||||
|
"max_sell_orders": 2,
|
||||||
|
"proxy_host": "privoxy",
|
||||||
|
"proxy_port": 8118,
|
||||||
|
"dingding_robot_url": "https://oapi.dingtalk.com/robot/send?access_token=666666666666666666666666666666666d29c",
|
||||||
|
"dingding_user_phone": "1111111111",
|
||||||
|
"user_email": "me@me.me",
|
||||||
|
"SMTP_HOST": "smtp.me.me",
|
||||||
|
"SMTP_PORT": 80,
|
||||||
|
"SMTP_USER": "me2@me.me",
|
||||||
|
"SMTP_PASSWORD": "77777777777777777777777777777777777"
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"account_id": 44444,
|
||||||
|
"api_key": "e7f555555555555555555b3",
|
||||||
|
"api_secret": "f065555555555555555555555555555aec",
|
||||||
|
"symbol_spot": ["btcusdt","btc3lusdt","eth3susdt"],
|
||||||
|
"symbol_margin": ["linkusdt","xmrusdt","bsvusdt","ethusdt"],
|
||||||
|
"symbol_c2c": ["linkusdt","xmrusdt","bsvusdt","ethusdt"],
|
||||||
|
"proxy_host": "172.16.0.137",
|
||||||
|
"proxy_port": 58591
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
# prod 机器上
|
||||||
|
|
||||||
|
## docker build push ,k8s update img
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
CURRENT_VERSION=41
|
||||||
|
CURRENT_IMG="me/grid_trader"
|
||||||
|
cd /root
|
||||||
|
rm -rf grid_trader
|
||||||
|
git clone https://mmmm/grid_trader.git
|
||||||
|
cd grid_trader
|
||||||
|
docker build -t $CURRENT_IMG:$CURRENT_VERSION .
|
||||||
|
docker push $CURRENT_IMG:$CURRENT_VERSION
|
||||||
|
clear
|
||||||
|
echo $CURRENT_VERSION
|
||||||
|
|
||||||
|
|
||||||
|
DEPLOYMENTS=`kubectl -n sre get deployment |grep binance-trader-qy |awk '{print $1}' |xargs`
|
||||||
|
for deployment in $DEPLOYMENTS;do
|
||||||
|
kubectl set image deployments $deployment *=$CURRENT_IMG:$CURRENT_VERSION -n sre
|
||||||
|
done
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,12 @@
|
|||||||
|
from huobi.client.account import AccountClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
# get accounts
|
||||||
|
from huobi.utils import *
|
||||||
|
from example.api_key import *
|
||||||
|
# 子账户财产
|
||||||
|
account_client = AccountClient(api_key=g_api_key,
|
||||||
|
secret_key=g_secret_key)
|
||||||
|
list_obj = account_client.get_account_balance_by_subuid(sub_uid=g_sub_uid)
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
from huobi.client.account import AccountClient
|
||||||
|
|
||||||
|
# get accounts
|
||||||
|
from huobi.utils import *
|
||||||
|
from example.api_key import *
|
||||||
|
|
||||||
|
account_client = AccountClient(api_key=g_api_key,
|
||||||
|
secret_key=g_secret_key)
|
||||||
|
# list_obj = account_client.get_accounts()
|
||||||
|
# if list_obj and len(list_obj):
|
||||||
|
# for account_obj in list_obj:
|
||||||
|
# list_obj = account_client.get_balance(account_id=account_obj.id)
|
||||||
|
# LogInfo.output("===== {account_id} , {account_type} =====".format(account_id=account_obj.id, account_type=account_obj.type))
|
||||||
|
# if len(list_obj):
|
||||||
|
# for obj in list_obj:
|
||||||
|
# if float(obj.balance) > 0.1: # only show account with balance
|
||||||
|
# obj.print_object()
|
||||||
|
# print()
|
||||||
|
|
||||||
|
LogInfo.output("====== (SDK encapsulated api) not recommend for low performance and frequence limitation ======")
|
||||||
|
account_balance_list = account_client.get_account_balance()
|
||||||
|
if account_balance_list and len(account_balance_list):
|
||||||
|
for account_balance_obj in account_balance_list:
|
||||||
|
if account_balance_obj and len(account_balance_obj.list):
|
||||||
|
PrintBasic.print_basic(account_balance_obj.id, "ID")
|
||||||
|
PrintBasic.print_basic(account_balance_obj.type, "Account Type")
|
||||||
|
PrintBasic.print_basic(account_balance_obj.state, "Account State")
|
||||||
|
PrintBasic.print_basic(account_balance_obj.subtype, "Subtype")
|
||||||
|
for balance_obj in account_balance_obj.list:
|
||||||
|
if float(balance_obj.balance) > 0.1: # only show account with balance
|
||||||
|
balance_obj.print_object("\t")
|
||||||
|
print()
|
||||||
|
print()
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
from huobi.client.account import AccountClient
|
||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
# get accounts
|
||||||
|
from huobi.utils import *
|
||||||
|
from example.api_key import *
|
||||||
|
|
||||||
|
account_client = AccountClient(api_key=g_api_key,
|
||||||
|
secret_key=g_secret_key)
|
||||||
|
|
||||||
|
LogInfo.output("========= case 1 get spot (SDK encapsulated api) =========")
|
||||||
|
account_obj = account_client.get_account_by_type_and_symbol(account_type=AccountType.SPOT, symbol=None)
|
||||||
|
account_obj.print_object()
|
||||||
|
|
||||||
|
LogInfo.output("========= case 2 get margin-linkusdt (SDK encapsulated api) =========")
|
||||||
|
account_obj = account_client.get_account_by_type_and_symbol(account_type=AccountType.MARGIN, symbol="linkusdt")
|
||||||
|
if account_obj:
|
||||||
|
account_obj.print_object()
|
||||||
|
|
||||||
|
LogInfo.output("========= case 3 get margin-linkusdt (SDK encapsulated api) =========")
|
||||||
|
account_obj = account_client.get_account_by_type_and_symbol(account_type=AccountType.SUPER_MARGIN, symbol=None)
|
||||||
|
if account_obj:
|
||||||
|
account_obj.print_object()
|
||||||
|
|
||||||
|
LogInfo.output("========= case 4 get margin-linkusdt (original api, supported) =========")
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
list_obj = margin_client.get_margin_account_balance(symbol="linkusdt")
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
|
LogInfo.output("========= case 5 get cross-margin (original api, supported) =========")
|
||||||
|
print(margin_client)
|
||||||
|
account_balance = margin_client.get_cross_margin_account_balance()
|
||||||
|
account_balance.print_object()
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
from huobi.client.account import AccountClient
|
||||||
|
|
||||||
|
# get accounts
|
||||||
|
from huobi.utils import *
|
||||||
|
from example.api_key import *
|
||||||
|
account_client = AccountClient(api_key=g_api_key,
|
||||||
|
secret_key=g_secret_key)
|
||||||
|
|
||||||
|
account_history = account_client.get_account_history(account_id=g_account_id, start_time=1600827872000, size=4)
|
||||||
|
LogInfo.output_list(account_history["data"])
|
||||||
|
LogInfo.output('Next Id: %s' % (account_history["next_id"]))
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
from huobi.client.account import AccountClient
|
||||||
|
from huobi.utils import *
|
||||||
|
from example.api_key import *
|
||||||
|
account_client = AccountClient(api_key=g_api_key,
|
||||||
|
secret_key=g_secret_key)
|
||||||
|
|
||||||
|
list_obj = account_client.get_account_ledger(account_id=g_account_id)
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
from huobi.client.account import AccountClient
|
||||||
|
from example.api_key import *
|
||||||
|
|
||||||
|
account_client = AccountClient(api_key=g_api_key,
|
||||||
|
secret_key=g_secret_key)
|
||||||
|
|
||||||
|
account_point_result = account_client.get_account_point()
|
||||||
|
account_point_result.print_object()
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
from huobi.client.account import AccountClient
|
||||||
|
|
||||||
|
# get accounts
|
||||||
|
from huobi.utils import *
|
||||||
|
from example.api_key import *
|
||||||
|
|
||||||
|
|
||||||
|
account_client = AccountClient(api_key=g_api_key,secret_key=g_secret_key)
|
||||||
|
|
||||||
|
list_obj = account_client.get_accounts()
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
from huobi.client.account import AccountClient
|
||||||
|
|
||||||
|
# get accounts
|
||||||
|
from huobi.utils import *
|
||||||
|
from example.api_key import *
|
||||||
|
|
||||||
|
account_client = AccountClient(api_key=g_api_key,
|
||||||
|
secret_key=g_secret_key)
|
||||||
|
list_obj = account_client.get_aggregated_subuser_balance()
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
from huobi.client.account import AccountClient
|
||||||
|
|
||||||
|
# get accounts
|
||||||
|
from huobi.utils import *
|
||||||
|
from example.api_key import *
|
||||||
|
account_client = AccountClient(api_key=g_api_key,
|
||||||
|
secret_key=g_secret_key)
|
||||||
|
list_obj = account_client.get_balance(account_id=g_account_id)
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
from huobi.client.account import AccountClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
account_client = AccountClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
# transfer_result = account_client.post_account_transfer(111859319, 'spot', 10354000, 147509118, 'spot', 13956126, 'trx', 3600)
|
||||||
|
# transfer_result.print_object()
|
||||||
|
|
||||||
|
# transfer_result = account_client.post_account_transfer(111859319, 'spot', 10354000, 147991959, 'spot', 14026125, 'usdt', 3600)
|
||||||
|
# transfer_result.print_object()
|
||||||
|
|
||||||
|
transfer_result = account_client.post_account_transfer(111859319, 'spot', 10354000, 141403659, 'spot', 13082796, 'usdt', 32.21)
|
||||||
|
transfer_result.print_object()
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
from huobi.client.account import AccountClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
account_client = AccountClient(api_key=g_api_key,
|
||||||
|
secret_key=g_secret_key)
|
||||||
|
|
||||||
|
point_transfer_result = account_client.post_point_transfer(from_uid=111859319, to_uid=124409916, group_id=0, amount=10)
|
||||||
|
point_transfer_result.print_object()
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
from huobi.client.account import AccountClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
# get accounts
|
||||||
|
account_client = AccountClient(api_key=g_api_key,
|
||||||
|
secret_key=g_secret_key)
|
||||||
|
|
||||||
|
ret = account_client.post_sub_uid_management(sub_uid=g_sub_uid, action=SubUidAction.LOCK)
|
||||||
|
ret.print_object()
|
||||||
|
|
||||||
|
ret = account_client.post_sub_uid_management(sub_uid=g_sub_uid, action=SubUidAction.UNLOCK)
|
||||||
|
ret.print_object()
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
from huobi.client.account import AccountClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
import time
|
||||||
|
|
||||||
|
account_client = AccountClient(api_key=g_api_key,
|
||||||
|
secret_key=g_secret_key)
|
||||||
|
transfer_order_id = account_client.transfer_between_futures_and_pro(currency="trx", amount=200, transfer_type=TransferFuturesPro.TO_FUTURES)
|
||||||
|
LogInfo.output("transfer from pro to future Order Id : {id}".format(id=transfer_order_id))
|
||||||
|
|
||||||
|
# need wait a minute
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
transfer_order_id = account_client.transfer_between_futures_and_pro(currency="trx", amount=200, transfer_type=TransferFuturesPro.TO_PRO)
|
||||||
|
LogInfo.output("transfer from future to pro Order Id : {id}".format(id=transfer_order_id))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
from huobi.client.account import AccountClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
account_client = AccountClient(api_key=g_api_key,
|
||||||
|
secret_key=g_secret_key)
|
||||||
|
transfer_order_id = account_client.transfer_between_parent_and_subuser(sub_uid=g_sub_uid, currency="usdt", amount=10, transfer_type=TransferMasterType.OUT)
|
||||||
|
LogInfo.output("transfer from master to subuser Order Id : {id}".format(id=transfer_order_id))
|
||||||
|
|
||||||
|
transfer_order_id = account_client.transfer_between_parent_and_subuser(sub_uid=g_sub_uid, currency="usdt", amount=10, transfer_type=TransferMasterType.IN)
|
||||||
|
LogInfo.output("transfer from subuser to master Order Id : {id}".format(id=transfer_order_id))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
from huobi.client.account import AccountClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
|
||||||
|
def callback(account_balance_req: 'AccountBalanceReq'):
|
||||||
|
account_balance_req.print_object()
|
||||||
|
|
||||||
|
|
||||||
|
account_client = AccountClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
account_client.req_account_balance(callback=callback, client_req_id=None)
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
from huobi.client.account import AccountClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
|
||||||
|
def callback(account_change_event: 'AccountChangeEvent'):
|
||||||
|
account_change_event.print_object()
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
account_client = AccountClient(api_key=g_api_key,
|
||||||
|
secret_key=g_secret_key,
|
||||||
|
init_log=True)
|
||||||
|
# account_client.sub_account_update(AccountBalanceMode.TOTAL, callback)
|
||||||
|
account_client.sub_account_update(AccountBalanceMode.BALANCE, callback)
|
||||||
|
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
from huobi.client.algo import AlgoClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
symbol_test = "adausdt"
|
||||||
|
account_id = g_account_id
|
||||||
|
|
||||||
|
algo_client = AlgoClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
result = algo_client.get_open_orders()
|
||||||
|
LogInfo.output_list(result)
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
from huobi.client.algo import AlgoClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
account_id = g_account_id
|
||||||
|
client_order_id = "test002"
|
||||||
|
|
||||||
|
# get specific order by clientOrderId
|
||||||
|
algo_client = AlgoClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
result = algo_client.get_order(client_order_id)
|
||||||
|
result.print_object()
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
from huobi.client.algo import AlgoClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
symbol_test = "adausdt"
|
||||||
|
account_id = g_account_id
|
||||||
|
|
||||||
|
algo_client = AlgoClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
result = algo_client.get_order_history(symbol_test, AlgoOrderStatus.TRIGGERED)
|
||||||
|
LogInfo.output_list(result)
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
from huobi.client.algo import AlgoClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
symbol_test = "adausdt"
|
||||||
|
account_id = g_account_id
|
||||||
|
|
||||||
|
orders_to_cancel = ["test003", "test001"]
|
||||||
|
algo_client = AlgoClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
result = algo_client.cancel_orders(orders_to_cancel)
|
||||||
|
result.print_object()
|
||||||
|
|
||||||
|
# order_id = algo_client.create_order(symbol=symbol_test, account_id=account_id, order_type=OrderType.BUY_MARKET, source=OrderSource.API, amount=5.0, price=1.292)
|
||||||
|
# LogInfo.output("created order id : {id}".format(id=order_id))
|
||||||
|
#
|
||||||
|
# order_id = algo_client.create_order(symbol=symbol_test, account_id=account_id, order_type=OrderType.SELL_MARKET, source=OrderSource.API, amount=1.77, price=None)
|
||||||
|
# LogInfo.output("created order id : {id}".format(id=order_id))
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
from huobi.client.algo import AlgoClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
symbol_test = "adausdt"
|
||||||
|
account_id = g_account_id
|
||||||
|
|
||||||
|
algo_client = AlgoClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
order_id = algo_client.create_order(symbol=symbol_test, account_id=account_id, order_side=OrderSide.BUY,
|
||||||
|
order_type=AlgoOrderType.LIMIT, order_size=65, order_price=0.08, stop_price=0.085,
|
||||||
|
client_order_id="test004")
|
||||||
|
LogInfo.output("created order id : {id}".format(id=order_id))
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
g_api_key = "e7f941dd-4167913c-mjlpdje3ld-f97b3"
|
||||||
|
g_secret_key = "f06af3d0-eaf3e4ff-9f0e931f-43aec"
|
||||||
|
g_account_id = 18788142
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
from huobi.client.etf import EtfClient
|
||||||
|
|
||||||
|
|
||||||
|
etf_client = EtfClient()
|
||||||
|
etf_config = etf_client.get_etf_swap_config("hb10")
|
||||||
|
etf_config.print_object()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
from huobi.client.etf import EtfClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
|
||||||
|
etf_client = EtfClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
etf_list = etf_client.get_etf_swap_list(etf_name="hb10", offset=0, size=20)
|
||||||
|
LogInfo.output_list(etf_list)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
from huobi.client.etf import EtfClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
etf_client = EtfClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
etf_swap_ret = etf_client.post_etf_swap_in("hb10", 1000)
|
||||||
|
etf_swap_ret.print_object()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
from huobi.client.etf import EtfClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
etf_client = EtfClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
etf_swap_ret = etf_client.post_etf_swap_out("hb10", 1000)
|
||||||
|
etf_swap_ret.print_object()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
from huobi.client.generic import GenericClient
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
|
||||||
|
generic_client = GenericClient()
|
||||||
|
list_obj = generic_client.get_exchange_currencies()
|
||||||
|
LogInfo.output("---- Supported currency ----")
|
||||||
|
for currency in list_obj:
|
||||||
|
LogInfo.output(currency)
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
from huobi.client.generic import GenericClient
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
|
||||||
|
generic_client = GenericClient()
|
||||||
|
list_obj = generic_client.get_exchange_info()
|
||||||
|
LogInfo.output("---- Supported symbols ----")
|
||||||
|
for symbol in list_obj.symbol_list:
|
||||||
|
LogInfo.output(symbol.symbol)
|
||||||
|
|
||||||
|
LogInfo.output("---- Supported currencies ----");
|
||||||
|
for currency in list_obj.currencies:
|
||||||
|
LogInfo.output(currency)
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
from huobi.client.generic import GenericClient
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
|
||||||
|
generic_client = GenericClient()
|
||||||
|
list_obj = generic_client.get_exchange_symbols()
|
||||||
|
if len(list_obj):
|
||||||
|
for idx, row in enumerate(list_obj):
|
||||||
|
LogInfo.output("------- number " + str(idx) + " -------")
|
||||||
|
row.print_object()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
from huobi.client.generic import GenericClient
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
|
||||||
|
generic_client = GenericClient()
|
||||||
|
ts = generic_client.get_exchange_timestamp()
|
||||||
|
LogInfo.output(ts)
|
||||||
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
from huobi.client.generic import GenericClient
|
||||||
|
|
||||||
|
generic_client = GenericClient()
|
||||||
|
market_status = generic_client.get_market_status()
|
||||||
|
print(market_status)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
from huobi.client.generic import GenericClient
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
|
||||||
|
generic_client = GenericClient()
|
||||||
|
|
||||||
|
list_obj = generic_client.get_reference_currencies()
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
|
|
||||||
|
list_obj = generic_client.get_reference_currencies(currency="usdt")
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
from huobi.client.generic import GenericClient
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
GET https://status.huobigroup.com/api/v2/summary.json
|
||||||
|
"""
|
||||||
|
generic_client = GenericClient()
|
||||||
|
system_status = generic_client.get_system_status()
|
||||||
|
print(system_status)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
account_balance = margin_client.get_cross_margin_account_balance()
|
||||||
|
account_balance.print_object()
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
list_obj = margin_client.get_cross_margin_loan_info()
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
|
||||||
|
# no filter
|
||||||
|
list_obj = margin_client.get_cross_margin_loan_orders()
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
|
# filter by state
|
||||||
|
list_obj = margin_client.get_cross_margin_loan_orders(state=LoanOrderState.ACCRUAL)
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import LogInfo
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
|
||||||
|
list_result = margin_client.get_general_repayment_loan_records(limit=10)
|
||||||
|
LogInfo.output_list(list_result)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
list_obj = margin_client.get_margin_account_balance(symbol="eosusdt")
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
list_obj = margin_client.get_margin_loan_info(symbols="btcusdt,ethusdt,eosusdt")
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
list_obj = margin_client.get_margin_loan_orders(symbol="eosusdt")
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
|
||||||
|
amount = 100
|
||||||
|
currency = "usdt"
|
||||||
|
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
# order_id = margin_client.post_cross_margin_create_loan_orders(currency=currency, amount=amount)
|
||||||
|
# LogInfo.output("step 1: create loan order {id}".format(id=order_id))
|
||||||
|
|
||||||
|
# to check not clearing loan orders
|
||||||
|
list_obj = margin_client.get_cross_margin_loan_orders(currency=currency, state=LoanOrderState.ACCRUAL)
|
||||||
|
LogInfo.output("step 2: loaning order information ")
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
|
if list_obj and len(list_obj):
|
||||||
|
for loan_order in list_obj:
|
||||||
|
# pay attention to Scientific Notation
|
||||||
|
repay_amount = float(loan_order.loan_balance) + float(loan_order.interest_balance)
|
||||||
|
LogInfo.output("repay loan order {id}, repay amount : {amount}".format(id=loan_order.id, amount=repay_amount))
|
||||||
|
result = margin_client.post_cross_margin_loan_order_repay(order_id=loan_order.id, amount=repay_amount)
|
||||||
|
LogInfo.output("step 3: repay loan order {id}, status : {status}, repay amount : {amount}".format(id=loan_order.id, status=result, amount=repay_amount))
|
||||||
|
|
||||||
|
list_obj = margin_client.get_cross_margin_loan_orders(currency=currency, state=LoanOrderState.ACCRUAL)
|
||||||
|
LogInfo.output("step 4: loaning order history ")
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
|
||||||
|
# to check not clearing loan orders
|
||||||
|
list_obj = margin_client.get_cross_margin_loan_orders(currency="usdt", state=LoanOrderState.ACCRUAL)
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
|
if list_obj and len(list_obj):
|
||||||
|
for loan_order in list_obj:
|
||||||
|
repay_amount = float(loan_order.loan_balance) + float(loan_order.interest_balance)
|
||||||
|
LogInfo.output("repay loan order {id} and amount {amount}".format(id=loan_order.id, amount=repay_amount))
|
||||||
|
order_id = margin_client.post_cross_margin_loan_order_repay(order_id=loan_order.id, amount=repay_amount)
|
||||||
|
|
||||||
|
# to check not clearing loan orders
|
||||||
|
list_obj = margin_client.get_cross_margin_loan_orders(currency="usdt", state=LoanOrderState.ACCRUAL)
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
transfer_id = margin_client.post_cross_margin_transfer_in(currency="eos", amount=5)
|
||||||
|
LogInfo.output(transfer_id)
|
||||||
|
|
||||||
|
transfer_id = margin_client.post_cross_margin_transfer_out(currency="eos", amount=5)
|
||||||
|
LogInfo.output(transfer_id)
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import LogInfo
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
|
||||||
|
list_result = margin_client.post_general_repay_loan(account_id=g_account_id, currency="usdt", amount=1)
|
||||||
|
LogInfo.output_list(list_result)
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
import time
|
||||||
|
|
||||||
|
loan_amount = 100
|
||||||
|
interest_amount = 0.004083
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
loan_id = margin_client.post_create_margin_order(symbol="eosusdt", currency="usdt", amount=loan_amount)
|
||||||
|
LogInfo.output("step 1: loan id : {id}".format(id=loan_id))
|
||||||
|
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
repay_id = margin_client.post_repay_margin_order(loan_id=loan_id, amount=loan_amount + interest_amount)
|
||||||
|
LogInfo.output("step 2: repay id : {id}".format(id=repay_id))
|
||||||
|
|
||||||
|
list_obj = margin_client.get_margin_loan_orders(symbol="eosusdt", states=LoanOrderState.ACCRUAL)
|
||||||
|
LogInfo.output("step 3: loaning order information")
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
|
|
||||||
|
list_obj = margin_client.get_margin_loan_orders(symbol="eosusdt")
|
||||||
|
LogInfo.output("step 4: loan order history")
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
transfer_id = margin_client.post_repay_margin_order(loan_id=7440184, amount=100.004083)
|
||||||
|
LogInfo.output("transfer id : {id}".format(id=transfer_id))
|
||||||
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
transfer_id = margin_client.post_transfer_in_margin(symbol="eosusdt", currency="usdt", amount=20)
|
||||||
|
LogInfo.output("transfer id : {id}".format(id=transfer_id))
|
||||||
|
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
from huobi.client.margin import MarginClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
transfer_id = margin_client.post_transfer_out_margin(symbol="eosusdt", currency="usdt", amount=20)
|
||||||
|
LogInfo.output("transfer id : {id}".format(id=transfer_id))
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
market_client = MarketClient(init_log=True)
|
||||||
|
interval = CandlestickInterval.MIN5
|
||||||
|
symbol = "ethusdt"
|
||||||
|
list_obj = market_client.get_candlestick(symbol, interval, 10)
|
||||||
|
LogInfo.output("---- {interval} candlestick for {symbol} ----".format(interval=interval, symbol=symbol))
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.utils import *
|
||||||
|
market_client = MarketClient()
|
||||||
|
list_obj = market_client.get_history_trade("btcusdt", 6)
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
from huobi.client.market import MarketClient
|
||||||
|
|
||||||
|
market_client = MarketClient()
|
||||||
|
obj = market_client.get_market_detail("btcusdt")
|
||||||
|
obj.print_object()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
market_client = MarketClient()
|
||||||
|
obj = market_client.get_market_detail_merged("btcusdt")
|
||||||
|
obj.print_object()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
market_client = MarketClient(init_log=True)
|
||||||
|
list_obj = market_client.get_market_tickers()
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
market_client = MarketClient()
|
||||||
|
list_obj = market_client.get_market_trade(symbol="eosusdt")
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
|
||||||
|
market_client = MarketClient()
|
||||||
|
symbol = "btcusdt"
|
||||||
|
depth_size = 6
|
||||||
|
depth = market_client.get_pricedepth(symbol, DepthStep.STEP0, depth_size)
|
||||||
|
LogInfo.output("---- Top {size} bids ----".format(size=len(depth.bids)))
|
||||||
|
i = 0
|
||||||
|
for entry in depth.bids:
|
||||||
|
i = i + 1
|
||||||
|
LogInfo.output(str(i) + ": price: " + str(entry.price) + ", amount: " + str(entry.amount))
|
||||||
|
|
||||||
|
LogInfo.output("---- Top {size} asks ----".format(size=len(depth.asks)))
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
for entry in depth.asks:
|
||||||
|
i = i + 1
|
||||||
|
LogInfo.output(str(i) + ": price: " + str(entry.price) + ", amount: " + str(entry.amount))
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.exception.huobi_api_exception import HuobiApiException
|
||||||
|
|
||||||
|
def callback(candlestick_req: 'CandlestickReq'):
|
||||||
|
candlestick_req.print_object()
|
||||||
|
|
||||||
|
def error(e: 'HuobiApiException'):
|
||||||
|
print(e.error_code + e.error_message)
|
||||||
|
|
||||||
|
sub_client = MarketClient(init_log=True)
|
||||||
|
#sub_client.request_candlestick_event("btcusdt", CandlestickInterval.MIN1, callback, from_ts_second=None, end_ts_second=None, error_handler=None)
|
||||||
|
#sub_client.request_candlestick_event("btcusdt", CandlestickInterval.MIN1, callback, from_ts_second=1571124360, end_ts_second=1571129820)
|
||||||
|
#sub_client.request_candlestick_event("btcusdt", CandlestickInterval.MIN1, callback, from_ts_second=1569361140, end_ts_second=0)
|
||||||
|
#sub_client.request_candlestick_event("btcusdt", CandlestickInterval.MIN1, callback, from_ts_second=1569379980)
|
||||||
|
sub_client.req_candlestick("btcusdt", CandlestickInterval.MIN1, callback)
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.model.market import *
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def callback(obj_event: 'MarketDetailReq'):
|
||||||
|
obj_event.print_object()
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
sub_client = MarketClient()
|
||||||
|
sub_client.req_market_detail("btcusdt", callback)
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
|
||||||
|
def callback(mbp_event: 'MbpIncreaseEvent'):
|
||||||
|
mbp_event.print_object()
|
||||||
|
|
||||||
|
|
||||||
|
def error(e: 'HuobiApiException'):
|
||||||
|
print(e.error_code + e.error_message)
|
||||||
|
|
||||||
|
|
||||||
|
market_client = MarketClient(init_log=True)
|
||||||
|
market_client.req_mbp("btcusdt", MbpLevel.MBP5, callback, error)
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.constant import DepthStep
|
||||||
|
|
||||||
|
|
||||||
|
def callback(price_depth_req: 'PriceDepthReq'):
|
||||||
|
price_depth_req.print_object()
|
||||||
|
|
||||||
|
|
||||||
|
def error(e: 'HuobiApiException'):
|
||||||
|
print(e.error_code + e.error_message)
|
||||||
|
|
||||||
|
|
||||||
|
sub_client = MarketClient()
|
||||||
|
sub_client.req_pricedepth("btcusdt", DepthStep.STEP0, callback, error)
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
from huobi.client.market import MarketClient
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def callback(trade_req: 'TradeDetailReq'):
|
||||||
|
print("---- trade_event: ----")
|
||||||
|
trade_req.print_object()
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
market_client = MarketClient()
|
||||||
|
market_client.req_trade_detail("btcusdt,eosusdt", callback)
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.exception.huobi_api_exception import HuobiApiException
|
||||||
|
from huobi.model.market.candlestick_event import CandlestickEvent
|
||||||
|
|
||||||
|
|
||||||
|
def callback(candlestick_event: 'CandlestickEvent'):
|
||||||
|
candlestick_event.print_object()
|
||||||
|
print("\n")
|
||||||
|
|
||||||
|
|
||||||
|
def error(e: 'HuobiApiException'):
|
||||||
|
print(e.error_code + e.error_message)
|
||||||
|
|
||||||
|
market_client = MarketClient()
|
||||||
|
market_client.sub_candlestick("btcusdt,ethusdt", CandlestickInterval.MIN1, callback, error)
|
||||||
|
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.model.market import *
|
||||||
|
|
||||||
|
|
||||||
|
def callback(obj_event: 'MarketDetailEvent'):
|
||||||
|
obj_event.print_object()
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
market_client = MarketClient()
|
||||||
|
market_client.sub_market_detail("btcusdt", callback)
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
|
||||||
|
def callback(mbp_event: 'MbpFullEvent'):
|
||||||
|
mbp_event.print_object()
|
||||||
|
|
||||||
|
|
||||||
|
def error(e: 'HuobiApiException'):
|
||||||
|
print(e.error_code + e.error_message)
|
||||||
|
|
||||||
|
|
||||||
|
market_client = MarketClient(init_log=True)
|
||||||
|
market_client.sub_mbp_full("btcusdt,eosusdt", MbpLevel.MBP5, callback, error)
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
|
||||||
|
def callback(mbp_event: 'MbpIncreaseEvent'):
|
||||||
|
mbp_event.print_object()
|
||||||
|
|
||||||
|
|
||||||
|
def error(e: 'HuobiApiException'):
|
||||||
|
print(e.error_code + e.error_message)
|
||||||
|
|
||||||
|
|
||||||
|
market_client = MarketClient(init_log=True)
|
||||||
|
market_client.sub_mbp_increase("btcusdt,eosusdt", MbpLevel.MBP5, callback, error)
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
from huobi.client.market import MarketClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def callback(price_depth_event: 'PriceDepthEvent'):
|
||||||
|
price_depth_event.print_object()
|
||||||
|
|
||||||
|
|
||||||
|
def error(e: 'HuobiApiException'):
|
||||||
|
print(e.error_code + e.error_message)
|
||||||
|
|
||||||
|
|
||||||
|
market_client = MarketClient()
|
||||||
|
market_client.sub_pricedepth("btcusdt", DepthStep.STEP0, callback, error)
|
||||||
|
market_client.sub_pricedepth("eosusdt", DepthStep.STEP0, callback, error)
|
||||||
|
market_client.sub_pricedepth("ethusdt", DepthStep.STEP0, callback, error)
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
from huobi.client.market import MarketClient
|
||||||
|
|
||||||
|
|
||||||
|
def callback(price_depth_event: 'PriceDepthBboEvent'):
|
||||||
|
price_depth_event.print_object()
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def error(e: 'HuobiApiException'):
|
||||||
|
print(e.error_code + e.error_message)
|
||||||
|
|
||||||
|
market_client = MarketClient()
|
||||||
|
market_client.sub_pricedepth_bbo("btcusdt", callback, error)
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
from huobi.client.market import MarketClient
|
||||||
|
|
||||||
|
|
||||||
|
def callback(trade_event: 'TradeDetailEvent'):
|
||||||
|
print("---- trade_event: ----")
|
||||||
|
trade_event.print_object()
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
market_client = MarketClient(init_log=True)
|
||||||
|
market_client.sub_trade_detail("btcusdt,eosusdt", callback)
|
||||||
|
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
from huobi.client.subuser import SubuserClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
from example.api_key import *
|
||||||
|
|
||||||
|
|
||||||
|
subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
uid = subuser_client.get_uid()
|
||||||
|
LogInfo.output(uid)
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
from huobi.client.subuser import SubuserClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
apikey_info = subuser_client.get_user_apikey_info(122946475)
|
||||||
|
LogInfo.output_list(apikey_info)
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
from huobi.client.subuser import SubuserClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
import string
|
||||||
|
import random
|
||||||
|
|
||||||
|
subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
userName = ''.join(random.choices(string.ascii_uppercase + string.digits, k=7))
|
||||||
|
params = {"userList": [
|
||||||
|
{
|
||||||
|
"userName": userName,
|
||||||
|
"note": "huobi"
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
|
||||||
|
userList = subuser_client.post_create_subuser(params)
|
||||||
|
LogInfo.output_list(userList)
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
from huobi.client.subuser import SubuserClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
sub_uids = '122946475'
|
||||||
|
|
||||||
|
transferability_result = subuser_client.post_set_subuser_transferability(sub_uids, False)
|
||||||
|
LogInfo.output_list(transferability_result)
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
from huobi.client.subuser import SubuserClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
sub_uid = '122946475'
|
||||||
|
access_key = '7ab679d7-b9fee8ed-9cd4cd8a-bgbfh5tv3f'
|
||||||
|
|
||||||
|
result = subuser_client.post_subuser_apikey_deletion(sub_uid, access_key)
|
||||||
|
LogInfo.output(result)
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
from huobi.client.subuser import SubuserClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
|
||||||
|
otp_token = '746316'
|
||||||
|
sub_uid = 122946475
|
||||||
|
note = "huobi_subuser"
|
||||||
|
permission = 'readOnly'
|
||||||
|
# ip_addresses = ''
|
||||||
|
|
||||||
|
result = subuser_client.post_subuser_apikey_generate(otp_token, sub_uid, note, permission)
|
||||||
|
result.print_object()
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
from huobi.client.subuser import SubuserClient
|
||||||
|
from huobi.constant import *
|
||||||
|
|
||||||
|
subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
|
||||||
|
subUid = 122946475
|
||||||
|
access_key = "abc"
|
||||||
|
note = "test"
|
||||||
|
permission = 'readOnly,trade'
|
||||||
|
|
||||||
|
result = subuser_client.post_subuser_apikey_modification(subUid, access_key, permission=permission, note=note)
|
||||||
|
result.print_object()
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
from huobi.client.subuser import SubuserClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
|
||||||
|
subUids = '159284259'
|
||||||
|
accountType = SubuserTradePrivilegeType.MARGIN
|
||||||
|
activation = SubUserTradeStatus.DEACTIVATED
|
||||||
|
|
||||||
|
subUserList = subuser_client.post_set_tradable_market(subUids, accountType, activation)
|
||||||
|
LogInfo.output_list(subUserList)
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
from huobi.client.trade import TradeClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
from example.api_key import *
|
||||||
|
|
||||||
|
|
||||||
|
trade_client = TradeClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
list_obj = trade_client.get_feerate(symbols="htusdt,btcusdt,eosusdt")
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
from huobi.client.trade import TradeClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
from example.api_key import *
|
||||||
|
|
||||||
|
symbol_test_list = ["linkusdt"]
|
||||||
|
trade_client = TradeClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
for symbol_test in symbol_test_list:
|
||||||
|
list_obj = trade_client.get_history_orders(symbol=symbol_test, start_time=None, end_time=None, size=20, direct=None)
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
from huobi.client.trade import TradeClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
|
||||||
|
trade_client = TradeClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
list_obj = trade_client.get_match_result(symbol="trxusdt", size=5, direct=QueryDirection.NEXT)
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
|
|
||||||
|
list_obj = trade_client.get_match_result(symbol="eosusdt", size=5)
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
from huobi.client.trade import TradeClient
|
||||||
|
from huobi.constant import *
|
||||||
|
from huobi.utils import *
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
order_id_test = 87939085540
|
||||||
|
|
||||||
|
trade_client = TradeClient(api_key=g_api_key, secret_key=g_secret_key)
|
||||||
|
list_obj = trade_client.get_match_results_by_order_id(order_id=order_id_test)
|
||||||
|
LogInfo.output_list(list_obj)
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue