当前位置: 首页 > article >正文

2.5 Binance_interface APP 现货交易-基础订单

Binance_interface APP 现货交易-基础订单

  • Github地址
  • PyTed量化交易研究院

目录

  • Binance_interface APP 现货交易-基础订单
    • 1. APP 现货交易-基础订单函数总览
    • 2. 模型实例化
    • 3. 下单(API原始接口) set_order
    • 4. 查询订单(API原始接口) get_order
    • 5. 查看当前挂单 get_orders_pending
    • 6 查看当前购买挂单 get_orders_pending_open
    • 7. 查看当前卖出挂单 get_orders_pending_close
    • 8. 等待订单成交 wait_order_FILLED
    • 9. 撤销订单(API原始接口) cancel_order

1. APP 现货交易-基础订单函数总览

方法解释
set_order下单(API原始接口)
get_order查询订单(API原始接口)
get_orders_pending查看当前挂单
get_orders_pending_open查看当前购买挂单
get_orders_pending_close查看当前卖出挂单
wait_order_FILLED等待订单成交
cancel_order撤销订单(API原始接口)

2. 模型实例化

from binance_interface.app import BinanceSPOT
from binance_interface.app.utils import eprint
import paux.date
# 转发:需搭建转发服务器,可参考:https://github.com/pyted/binance_resender
proxy_host = None
key = 'xxxx'
secret = 'xxxx'

binanceSPOT = BinanceSPOT(
    key=key,
    secret=secret,
    proxy_host=proxy_host,
    timezone='Asia/Shanghai',
)
trade = binanceSPOT.trade

3. 下单(API原始接口) set_order

set_order_result = trade.set_order(
    symbol='MANAUSDT',
    price='0.4',
    quantity='15',
    side='BUY',
    type='LIMIT',
    timeInForce='GTC',
)
eprint(set_order_result)

输出:

>>> {'code': 200,
>>>  'data': {'symbol': 'MANAUSDT',
>>>           'orderId': 2207382482,
>>>           'orderListId': -1,
>>>           'clientOrderId': 'P3PQXqOCmLmvSgT3bHpNhY',
>>>           'transactTime': 1706119355892,
>>>           'price': '0.40000000',
>>>           'origQty': '15.00000000',
>>>           'executedQty': '0.00000000',
>>>           'cummulativeQuoteQty': '0.00000000',
>>>           'status': 'NEW',
>>>           'timeInForce': 'GTC',
>>>           'type': 'LIMIT',
>>>           'side': 'BUY',
>>>           'workingTime': 1706119355892,
>>>           'fills': [],
>>>           'selfTradePreventionMode': 'EXPIRE_MAKER'},
>>>  'msg': ''}

4. 查询订单(API原始接口) get_order

orderId = set_order_result['data']['orderId']
order_result = trade.get_order(
    symbol='MANAUSDT',
    orderId=orderId,
)
eprint(order_result)

输出:

>>> {'code': 200,
>>>  'data': {'symbol': 'MANAUSDT',
>>>           'orderId': 2207382482,
>>>           'orderListId': -1,
>>>           'clientOrderId': 'P3PQXqOCmLmvSgT3bHpNhY',
>>>           'price': '0.40000000',
>>>           'origQty': '15.00000000',
>>>           'executedQty': '0.00000000',
>>>           'cummulativeQuoteQty': '0.00000000',
>>>           'status': 'NEW',
>>>           'timeInForce': 'GTC',
>>>           'type': 'LIMIT',
>>>           'side': 'BUY',
>>>           'stopPrice': '0.00000000',
>>>           'icebergQty': '0.00000000',
>>>           'time': 1706119355892,
>>>           'updateTime': 1706119355892,
>>>           'isWorking': True,
>>>           'workingTime': 1706119355892,
>>>           'origQuoteOrderQty': '0.00000000',
>>>           'selfTradePreventionMode': 'EXPIRE_MAKER'},
>>>  'msg': ''}

5. 查看当前挂单 get_orders_pending

# 查询symbol 从start到end全部未成交订单
orders_pending_result = trade.get_orders_pending(
    symbol='',  # 默认为空,表示全部产品
    start='2024-01-23 10:00:00',  # 默认为空,表示不限定订单的起始时间
    end='2024-01-25',  # 默认为空,表示不限定订单的终止时间
)
eprint(orders_pending_result, length=30)

输出:

>>> {'code': 200,
>>>  'data': [{'symbol': 'MANAUSDT',
>>>            'orderId': 2207181640,
>>>            'orderListId': -1,
>>>            'clientOrderId': 'm7UdoWyzjkl80q1rgzJ19U',
>>>            'price': '1.00000000',
>>>            'origQty': '5.00000000',
>>>            'executedQty': '0.00000000',
>>>            'cummulativeQuoteQty': '0.00000000',
>>>            'status': 'NEW',
>>>            'timeInForce': 'GTC',
>>>            'type': 'LIMIT',
>>>            'side': 'SELL',
>>>            'stopPrice': '0.00000000',
>>>            'icebergQty': '0.00000000',
>>>            'time': 1706105539772,
>>>            'updateTime': 1706105539772,
>>>            'isWorking': True,
>>>            'workingTime': 1706105539772,
>>>            'origQuoteOrderQty': '0.00000000',
>>>            'selfTradePreventionMode': 'EXPIRE_MAKER'},
>>>           {'symbol': 'MANAUSDT',
>>>            'orderId': 2207182516,
>>>            'orderListId': -1,
>>>            'clientOrderId': 'G03pZe5KataOJ7C1DS3gmn',
>>>            'price': '0.47940000',
>>>            'origQty': '15.00000000',
>>>            'executedQty': '0.00000000',
>>>            'cummulativeQuoteQty': '0.00000000',
>>>            'status': 'NEW',
>>>            'timeInForce': 'GTC',
>>>            'type': 'LIMIT',
>>>            'side': 'SELL',
>>>            'stopPrice': '0.00000000',
>>>            'icebergQty': '0.00000000',
>>>            'time': 1706105588896,
>>>            'updateTime': 1706105588896,
>>>            'isWorking': True,
>>>            'workingTime': 1706105588896,
>>>            'origQuoteOrderQty': '0.00000000',
>>>            'selfTradePreventionMode': 'EXPIRE_MAKER'}],
>>>  'msg': ''}
# 查询symbol 从start到end全部未成交订单
orders_pending_result = trade.get_orders_pending(
    symbol='BTCUSDT',  # 默认为空,表示全部产品
    start='2024-01-23 10:00:00',  # 默认为空,表示不限定订单的起始时间
    end='2024-01-26',  # 默认为空,表示不限定订单的终止时间
)
eprint(orders_pending_result, length=30)

输出:

>>> {'code': 200,
>>>  'data': [{'symbol': 'BTCUSDT',
>>>            'orderId': 24501202294,
>>>            'orderListId': -1,
>>>            'clientOrderId': 'ios_7952d852422d460e9c82405c628af712',
>>>            'price': '38000.00000000',
>>>            'origQty': '0.00026000',
>>>            'executedQty': '0.00000000',
>>>            'cummulativeQuoteQty': '0.00000000',
>>>            'status': 'NEW',
>>>            'timeInForce': 'GTC',
>>>            'type': 'LIMIT',
>>>            'side': 'BUY',
>>>            'stopPrice': '0.00000000',
>>>            'icebergQty': '0.00000000',
>>>            'time': 1706119340397,
>>>            'updateTime': 1706119340397,
>>>            'isWorking': True,
>>>            'workingTime': 1706119340397,
>>>            'origQuoteOrderQty': '0.00000000',
>>>            'selfTradePreventionMode': 'EXPIRE_MAKER'}],
>>>  'msg': ''}

6 查看当前购买挂单 get_orders_pending_open

orders_pending_open_result = trade.get_orders_pending_open(
    symbol='MANAUSDT',
)
eprint(orders_pending_open_result, length=30)

输出:

>>> {'code': 200,
>>>  'data': [{'symbol': 'MANAUSDT',
>>>            'orderId': 2207382482,
>>>            'orderListId': -1,
>>>            'clientOrderId': 'P3PQXqOCmLmvSgT3bHpNhY',
>>>            'price': '0.40000000',
>>>            'origQty': '15.00000000',
>>>            'executedQty': '0.00000000',
>>>            'cummulativeQuoteQty': '0.00000000',
>>>            'status': 'NEW',
>>>            'timeInForce': 'GTC',
>>>            'type': 'LIMIT',
>>>            'side': 'BUY',
>>>            'stopPrice': '0.00000000',
>>>            'icebergQty': '0.00000000',
>>>            'time': 1706119355892,
>>>            'updateTime': 1706119355892,
>>>            'isWorking': True,
>>>            'workingTime': 1706119355892,
>>>            'origQuoteOrderQty': '0.00000000',
>>>            'selfTradePreventionMode': 'EXPIRE_MAKER'}],
>>>  'msg': ''}

7. 查看当前卖出挂单 get_orders_pending_close

orders_pending_close_result = trade.get_orders_pending_close(
    symbol='MANAUSDT',
)
eprint(orders_pending_close_result, length=30)

输出:

>>> {'code': 200,
>>>  'data': [{'symbol': 'MANAUSDT',
>>>            'orderId': 2207181640,
>>>            'orderListId': -1,
>>>            'clientOrderId': 'm7UdoWyzjkl80q1rgzJ19U',
>>>            'price': '1.00000000',
>>>            'origQty': '5.00000000',
>>>            'executedQty': '0.00000000',
>>>            'cummulativeQuoteQty': '0.00000000',
>>>            'status': 'NEW',
>>>            'timeInForce': 'GTC',
>>>            'type': 'LIMIT',
>>>            'side': 'SELL',
>>>            'stopPrice': '0.00000000',
>>>            'icebergQty': '0.00000000',
>>>            'time': 1706105539772,
>>>            'updateTime': 1706105539772,
>>>            'isWorking': True,
>>>            'workingTime': 1706105539772,
>>>            'origQuoteOrderQty': '0.00000000',
>>>            'selfTradePreventionMode': 'EXPIRE_MAKER'},
>>>           {'symbol': 'MANAUSDT',
>>>            'orderId': 2207182516,
>>>            'orderListId': -1,
>>>            'clientOrderId': 'G03pZe5KataOJ7C1DS3gmn',
>>>            'price': '0.47940000',
>>>            'origQty': '15.00000000',
>>>            'executedQty': '0.00000000',
>>>            'cummulativeQuoteQty': '0.00000000',
>>>            'status': 'NEW',
>>>            'timeInForce': 'GTC',
>>>            'type': 'LIMIT',
>>>            'side': 'SELL',
>>>            'stopPrice': '0.00000000',
>>>            'icebergQty': '0.00000000',
>>>            'time': 1706105588896,
>>>            'updateTime': 1706105588896,
>>>            'isWorking': True,
>>>            'workingTime': 1706105588896,
>>>            'origQuoteOrderQty': '0.00000000',
>>>            'selfTradePreventionMode': 'EXPIRE_MAKER'}],
>>>  'msg': ''}

8. 等待订单成交 wait_order_FILLED

# 堵塞,等待订单完全成交,如果超时后仍未成交,返回订单数据
orderId = set_order_result['data']['orderId']
wait_order_filled_result = trade.wait_order_FILLED(
    symbol='MANAUSDT',
    orderId=orderId,
    timeout=5,
)

eprint(wait_order_filled_result)

输出:

>>> {'code': 200,
>>>  'data': {'symbol': 'MANAUSDT',
>>>           'orderId': 2207382482,
>>>           'orderListId': -1,
>>>           'clientOrderId': 'P3PQXqOCmLmvSgT3bHpNhY',
>>>           'price': '0.40000000',
>>>           'origQty': '15.00000000',
>>>           'executedQty': '0.00000000',
>>>           'cummulativeQuoteQty': '0.00000000',
>>>           'status': 'NEW',
>>>           'timeInForce': 'GTC',
>>>           'type': 'LIMIT',
>>>           'side': 'BUY',
>>>           'stopPrice': '0.00000000',
>>>           'icebergQty': '0.00000000',
>>>           'time': 1706119355892,
>>>           'updateTime': 1706119355892,
>>>           'isWorking': True,
>>>           'workingTime': 1706119355892,
>>>           'origQuoteOrderQty': '0.00000000',
>>>           'selfTradePreventionMode': 'EXPIRE_MAKER'},
>>>  'msg': ''}

9. 撤销订单(API原始接口) cancel_order

orderId = set_order_result['data']['orderId']
cancel_order_result = trade.cancel_order(
    symbol='MANAUSDT',
    orderId=orderId,
)
eprint(cancel_order_result)

输出:

>>> {'code': 200,
>>>  'data': {'symbol': 'MANAUSDT',
>>>           'origClientOrderId': 'P3PQXqOCmLmvSgT3bHpNhY',
>>>           'orderId': 2207382482,
>>>           'orderListId': -1,
>>>           'clientOrderId': 'Gll4JiBPwxkI3FYhIB0CHi',
>>>           'transactTime': 1706119384094,
>>>           'price': '0.40000000',
>>>           'origQty': '15.00000000',
>>>           'executedQty': '0.00000000',
>>>           'cummulativeQuoteQty': '0.00000000',
>>>           'status': 'CANCELED',
>>>           'timeInForce': 'GTC',
>>>           'type': 'LIMIT',
>>>           'side': 'BUY',
>>>           'selfTradePreventionMode': 'EXPIRE_MAKER'},
>>>  'msg': ''}

http://www.kler.cn/a/233249.html

相关文章:

  • sqlsever 分布式存储查询
  • 计算机网络 (1)互联网的组成
  • 前端vue 列表中回显并下拉选择修改标签
  • 如何向函数模块 FM 中传递 Range 参数
  • CCI3.0-HQ:用于预训练大型语言模型的高质量大规模中文数据集
  • CTFHub每日练习
  • C#上位机与三菱PLC的通信05--MC协议之QnA-3E报文解析
  • 简化版SpringMVC
  • 在 Next 中, ORM 框架 Prisma 使用
  • Ajax+JSON学习二
  • C#,欧拉常数(Euler Constant)的算法与源代码
  • springboot/ssm学生请假管理系统 高校请假审批管理系统Java系统
  • jsp页面,让alert弹出信息换行显示
  • Rust方法自动解引用测试,总结和补充
  • 前端入门:(五)JavaScript 续
  • Oracle篇—logminer日志挖掘恢复误操作数据
  • Vue源码系列讲解——虚拟DOM篇【三】(更新子节点)
  • 华为交换机常用命令
  • [office] excel2003进行可视性加密的方法 #媒体#其他#知识分享
  • 京东微前端框架MicroApp简介
  • 让cgteamwork自动为Houdini载入相机,角色道具的abc文件
  • docker下,容器无法启动,要删除里面的文件
  • vue3 elementplus DateTimePicker 日期时间设置默认时间为当天
  • 跟着cherno手搓游戏引擎【22】CameraController、Resize
  • WordPress突然后台无法管理问题
  • GPT-3 训练自己的数据教程详解