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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值