0bps

Strategy vault / Tools & templates

Binance Contract BNB Fee Deduction Automatic Purchase and Transfer

Contact : [email protected] / WeChat@stay37 This strategy automatically transfers USDT from the futures account to the spot account to buy BNB, then transfers BNB back to the futures account to offset fees. Need to…

Author
Xueqiu Bot
Complexity
Starter · 36 lines
Parameters
0

Contact : [email protected] / WeChat@stay37 This strategy automatically transfers USDT from the futures account to the spot account to buy BNB, then transfers BNB back to the futures account to offset fees. Need to add the BNB_USDT trading pair in advance

Source Python

# Contact : [email protected] / WeChat@stay37

import time


def supply_bnb(transfer_usdt,i):
    Log("CurrentBNBInsufficient, supplementBNBUsed as fee deduction")
    #Get CurrentBNB_USDTPrice
    depth = _C(exchanges[i].GetDepth)
    #Transfer outtransfer_usdtIndividual/UnitUSDT
    timestamp = time.time() * 1000
    transfer = exchanges[i].IO("api","POST","/sapi/v1/futures/transfer","asset=USDT&amount="+str(transfer_usdt)+"&type=2&timestamp=+"+str(timestamp))
    time.sleep(1)
    #ObtainBNBDepth, place buy order
    depth = _C(exchanges[i].GetDepth)
    buyamount = round(transfer_usdt / (depth.Asks[0].Price + 0.2) , 2)
    buyid = exchanges[i].Buy(round(depth.Asks[0].Price + 0.1 , 4) , buyamount)
    time.sleep(1)
    #Query purchase results after buyingBNBAnd the remainingUSDTTransfer to contract account
    acc = _C(exchanges[i].GetAccount)
    transfer_usdt = acc.Balance
    transfer_bnb = acc.Stocks
    timestamp = time.time() * 1000
    transfer = exchanges[i].IO("api","POST","/sapi/v1/futures/transfer","asset=USDT&amount="+str(transfer_usdt)+"&type=1&timestamp=+"+str(timestamp))
    transfer = exchanges[i].IO("api","POST","/sapi/v1/futures/transfer","asset=BNB&amount="+str(transfer_bnb)+"&type=1&timestamp=+"+str(timestamp))
    Log("BNBSupplement completed")




def main():
    if 'Insufficient BNB in the contract account':
        #transfer_usdt: Amount of USDT required to purchase
        #i: bnb_usdtIndex of spot trading pair
        supply_bnb(transfer_usdt,i)

Published by Xueqiu Bot on the FMZ strategy square · last modified 2020-11-11. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a tested, production-ready module from strategies/Binance-Contract-BNB-Fee-Deduction-Automatic-Purchase-and-Transfer.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open