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

binance python

binance-futures-connector 4.1.0

from binance.um_futures import UMFutures
# U本位  USDT-M Futures /fapi/*
# 币本位 COIN-M Delivery /dapi/* 

proxies = { 'https': 'http://localhost:7890' }
client = UMFutures(proxies=proxies)

apiKey=""
apiSecret=""
client = UMFutures(key=apiKey, secret=apiSecret)

账户信息

def accountInfo(client):
    account_info = client.account()
    totalWalletBalance = account_info.get('totalWalletBalance', 0)
    totalUnrealizedProfit = account_info.get('totalUnrealizedProfit', 0)
    print({
        '合约账户余额': totalWalletBalance,
        '未实现盈亏': totalUnrealizedProfit,
    })
accountInfo(client)

合约信息

import pandas as pd

def positionInfo(positions):
    headers = ["合约", "方向", "开仓价格", "标记价格", "强平价格", "持仓数量", "保证金", "未实现盈亏"]
    data = []
    for position in positions:
        data.append([
            position.get("symbol"),
            "多" if position.get("positionSide") == "LONG" else "空",
            position.get("entryPrice"), 
            position.get("markPrice"), 
            position.get("liquidationPrice"), 
            position.get("positionAmt"), 
            position.get("positionInitialMargin"), 
            position.get("unRealizedProfit")
        ])
    df = pd.DataFrame(data, columns=headers)
    print(df)

# 当前的合约仓位
positions = client.get_position_risk()
positionInfo(positions)

修改杠杆倍数

client.change_leverage(symbol='SOLUSDT', leverage=10)

下单

client.new_order(symbol='DOGEUSDT', 
	positionSide="LONG", side='BUY', type='LIMIT', 
	timeInForce='GTC', quantity=25, price=0.2)

25 × 0.2 = 5 U 25×0.2=5\text{U} 25×0.2=5Uquantityprice的含义可想而知

在这里插入图片描述

关于timeInForce(选GTC就好)

time in forceDescription
Good till canceled (GTC)The order will remain valid until it is fully executed or manually canceled by the trader. GTC is suitable for traders who are willing to wait for all contracts to be completed at a specified price and can flexibly cancel unconcluded contracts at any time.
Fill or Kill (FOK)The order must be immediately executed at the order price or better, otherwise, it will be completely canceled and partially filled contracts will not be allowed. This execution strategy is more commonly used by scalping traders or day traders looking for short-term market opportunities.
Immediate or Cancel (IOC)The order must be filled immediately at the order limit price or better. If the order cannot be filled immediately, the unfilled contracts will be canceled. IOC is usually used to avoid large orders being executed at a price that deviates from the ideal price. With this set, the contracts that fail to trade at the specified price will be canceled.

Refer

  • https://developers.xxx.com/docs/zh-CN/derivatives/usds-margined-futures/general-info
  • https://zhuanlan.zhihu.com/p/603858070

相关文章:

  • PVE 磁盘管理详解:从 Windows 到 Linux 的思维转换(文末附资源)
  • 力扣动态规划-31【算法学习day.125】
  • Python VsCode DeepSeek接入
  • Qt MainWindow
  • java集合框架之Map系列
  • 华为IPD简介
  • LeetCode 232: 用栈实现队列
  • w210基于Springboot开发的精简博客系统的设计与实现
  • windows10本地的JMeter+Influxdb+Grafana压测性能测试,【亲测,避坑】
  • 梅花易数【邵雍】起卦方法
  • OpenMetadata 获取 MySQL 数据库表血缘关系详解
  • 【kafka系列】broker
  • DeepSeek官方推荐的AI集成系统
  • Windows安装Rust环境(详细教程)
  • 解读 Flink Source 接口重构后的 KafkaSource
  • AcWing——61. 最长不含重复字符的子字符串
  • 基于AIOHTTP、Websocket和Vue3一步步实现web部署平台,无延迟控制台输出,接近原生SSH连接
  • 刷题记录(回顾)HOT100 二叉树-10: ​199. 二叉树的右视图
  • 【仪器仪表专题】案例:示波器控制通道开关SCPI命令不同的原因
  • 使用verilog 实现cordic 算法 ---- 向量模式
  • 让“五颜六色”面孔讲述上海故事,2025年上海城市推荐官开启选拔
  • 重庆大学通报本科生发14篇SCI论文:涉事学生及其父亲被处理
  • 巴总理召开国家指挥当局紧急会议
  • 要更加冷静地看待“东升西降”的判断
  • 中非民间对话在赞比亚举行
  • 上海“世行对标改革”的税务样本:设立全国首个税务审判庭、制定首个税务行政复议简易程序