方法 | 解释 |
---|---|
round_quantity | 下单数量圆整 |
round_price | 价格圆整 |
get_quantity | 根据产品的开仓金额、杠杆倍数、开仓价格获取购买数量 |
quantity_to_f | 将下单数量转化为字符串 |
price_to_f | 将价格转化为字符串 |
from binance_interface.app import BinanceSPOT
from binance_interface.app.utils import eprint
# 转发:需搭建转发服务器,可参考:https://github.com/pyted/binance_resender
proxy_host = None
key = 'xxxx'
secret = 'xxxx'
binanceSPOT = BinanceSPOT(
key=key, secret=secret,
proxy_host=proxy_host
)
trade = binanceSPOT.trade
# 以产品数量的最小精度向下取圆整
quantity_result = trade.round_quantity(
symbol='BTCUSDT',
quantity=0.12345678912345,
)
print(quantity_result)
输出:
>>> {'code': 200, 'data': 0.12345, 'msg': ''}
# 以产品价格的最小精度取圆整
price_result = trade.round_price(
price=12345.67891234,
symbol='BTCUSDT',
type='CEIL', # 向上取圆整
)
print(price_result)
输出:
>>> {'code': 200, 'data': 12345.68, 'msg': ''}
# 以产品价格的最小精度取圆整
price_result = trade.round_price(
price=12345.67891234,
symbol='BTCUSDT',
type='FLOOR', # 向下取圆整
)
print(price_result)
输出:
>>> {'code': 200, 'data': 12345.67, 'msg': ''}
quantity_result = trade.get_quantity(
openPrice=21212.12,
openMoney=400,
symbol='BTCUSDT',
)
print(quantity_result)
输出:
>>> {'code': 200, 'data': 0.01885, 'msg': ''}
quantity_to_f_result = trade.quantity_to_f(
quantity=0.01885,
symbol='BTCUSDT',
)
print(quantity_to_f_result)
输出:
>>> {'code': 200, 'data': '0.01885', 'msg': ''}
price_to_f_result = trade.price_to_f(
price=12345.12,
symbol='BTCUSDT',
)
print(price_to_f_result)
输出:
>>> {'code': 200, 'data': '12345.12', 'msg': ''}