0bps

Strategy vault / Tools & templates

Huobi U Contract Fund Transfer Plugin

JavaScript strategy by xunfeng91.

Author
xunfeng91
Complexity
Intermediate · 97 lines
Parameters
7

The original spec has no written description. Read the source below.

Parameters

NameDefaultWhat it controls
typeIndex0Transfer type: master-sub account transfer | transfer between different accounts of the same account
subuidsub-accountUID
assetUSDTTransfer Currency
from_margin_accountUSDTMargin account to transfer out from
to_margin_accountUSDTMargin account to transfer in to
amount10000Transfer Quantity
direct0Account transfer direction: Parent to child | Child to parent

Source JavaScript



/*
1,Parent-child account transfer
2,Transfer between different margin accounts under the same account
*/ 

var type = [1,2][typeIndex]
function swap_master_sub_transfer( e , cur , amount , direct ){
    try {
        var params = ''
        var Currency = cur
        var Transfer Quantity = amount
        var exname = e.GetName()
        var sub_uid = subuid
        if (!sub_uid){
            Log("Please correct accountUID")
            return
        }
        var frommarginaccount = from_margin_account=="USDT"?from_margin_account:from_margin_account+"-USDT"
        var tomarginaccount = to_margin_account=="USDT"?to_margin_account:to_margin_account+"-USDT"
        transdirect = ["master_to_sub","sub_to_master"][direct]
        params ={"contract_code":frommarginaccount}
        if (amount == -1){
            if(frommarginaccount=="USDT"){//Full Position
                var ret1 = e.IO("api", "POST", "/linear-swap-api/v1/swap_cross_account_info" )
                Transfer Quantity =parseFloat(ret1.data[0].withdraw_available)
            }else{
                var ret1 = e.IO("api", "POST", "/linear-swap-api/v1/swap_account_info" ,"",  JSON.stringify( params ) )
                Transfer Quantity =parseFloat(ret1.data[0].withdraw_available)
            }            
        }
        if( exname == 'Futures_HuobiDM'){
            var Transfer type = transdirect
            params ={
                "sub_uid": sub_uid , 
                "asset": Currency , 
                "from_margin_account":frommarginaccount,
                "to_margin_account":tomarginaccount,
                "amount": Transfer Quantity, 
                "type" : Transfer type,
                "timestamp" : new Date().getTime()    
			}
			Log( "Transfer Currency:",Currency,"Transfer Quantity:",Transfer Quantity,"Transfer type:",Transfer type)
            var ret1 = e.IO("api", "POST", "/linear-swap-api/v1/swap_master_sub_transfer" ,"",  JSON.stringify( params ) )
			Log(ret1)
        }
    } catch (error) { 
        Log( error )
    }  
}

function swap_transfer_inner( e , cur , amount ){
    try {
        var params = ''
        var Currency = cur
        var Transfer Quantity = amount
        var exname = e.GetName()
        var frommarginaccount = from_margin_account=="USDT"?from_margin_account:from_margin_account+"-USDT"
        var tomarginaccount = to_margin_account=="USDT"?to_margin_account:to_margin_account+"-USDT"
        params ={"contract_code":frommarginaccount}
        if (amount == -1){
            if(frommarginaccount=="USDT"){//Full Position
                var ret1 = e.IO("api", "POST", "/linear-swap-api/v1/swap_cross_account_info" )
                Transfer Quantity =_N(parseFloat(ret1.data[0].withdraw_available),6)
            }else{
                var ret1 = e.IO("api", "POST", "/linear-swap-api/v1/swap_account_info" ,"",  JSON.stringify( params ) )
                Transfer Quantity =_N(parseFloat(ret1.data[0].withdraw_available),6)
            }            
        }
        if( exname == 'Futures_HuobiDM'){
            params ={
                "asset": Currency , 
                "from_margin_account":frommarginaccount,
                "to_margin_account":tomarginaccount,
                "amount": Transfer Quantity, 
                "timestamp" : new Date().getTime()    
			}
			Log( "Transfer Currency:",Currency,"Transfer Quantity:",Transfer Quantity,)
            var ret1 = e.IO("api", "POST", "/linear-swap-api/v1/swap_transfer_inner" ,"",  JSON.stringify( params ) )
			Log(ret1)
        }
    } catch (error) { 
        Log( error )
    }

}

function main() {
    if (type==1){
        swap_master_sub_transfer( exchange , asset , amount , direct )
    }
    if (type==2){
        swap_transfer_inner( exchange , asset , amount )
    }
    
}

Published by xunfeng91 on the FMZ strategy square · last modified 2021-02-26. 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/Huobi-U-Contract-Fund-Transfer-Plugin.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