Bitfinex Margin Trading
JavaScript strategy by 7meter.
JavaScriptOther
The original spec has no written description. Read the source below.
Source JavaScript
var bitfinexIndex = 0;
var basecurrency;
var quotecurrency;
function init(){
for(var i = 0;i<exchanges.length;i++){
if(exchanges[i].GetName() == "Bitfinex"){
bitfinexIndex = i
}
}
var st = exchanges[bitfinexIndex].GetCurrency().split("_")
basecurrency = st[0]
quotecurrency = st[1]
}
$.bitfinexSell = function(price, amount){
var message = "symbol=" + basecurrency + quotecurrency + "&amount=" + amount.toString() + "&price=" + price.toString() + "&side=sell" + "&type=limit"
id = exchanges[bitfinexIndex].IO("api", "POST", "/v1/order/new", message)
return id.order_id
}
$.bitfinexBuy = function(price, amount){
var message = "symbol=" + basecurrency + quotecurrency + "&amount=" + amount.toString() + "&price=" + price.toString() + "&side=buy" + "&type=fill-or-kill"
var id = exchanges[bitfinexIndex].IO("api", "POST", "/v1/order/new", message)
return id.order_id
}
$.bitfinexGetPosition = function(){
var position = exchanges[bitfinexIndex].IO("api", "POST", "/v1/positions")
return position
}
//Use directlyexchange.GetOrder(id)That's all, no need to call the template
$.bitfinexGetOrder = function(order_id){
var order = exchanges[bitfinexIndex].IO("api", "POST", "/v1/order/status", "order_id=", parseInt(order_id))
return order
}
//Directly useexchange.CancelOrder(id)You can cancel orders without calling a template
$.bitfinexCancelOrder = function(order_id){
//var result = exchanges[bitfinexIndex].IO("api", "POST", "/v1/order/cancel", "order_id=", parseInt(order_id))
//return order
}
//ReturnmarginHow much can the wallet trade in totalUSD(Cryptocurrency will be converted to USD for calculation)
$.marginBalance = function(){
var balance = exchanges[bitfinexIndex].IO("api", "POST", "/v1/margin_infos")
return balance[0].tradable_balance;
}Published by 7meter on the FMZ strategy square · last modified 2017-12-02. 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.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Bitfinex-Margin-Trading.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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.