okex BTC Contract Account Public
JavaScript strategy by leviyuan.
JavaScriptOther
The original spec has no written description. Read the source below.
Source JavaScript
var exchangeRate = 6.4,
usdprice = 1000
var chartCfg = [{
title: {
text: "Account monitoring"
},
xAxis: {
type: 'datetime'
},
series: [{
name: "Current account fund value",
data: []
}, {
name: "Current value of BTC starting this week",
data: []
}]
}]
function GetWebJson(url) {
for (var i = 0; i < 10; i++) {
try {
return JSON.parse(HttpQuery(url))
} catch (e) {
Sleep(500)
}
}
}
function main() {
exchange.SetRate(1)
LogReset()
var chart = Chart(chartCfg)
chart.reset()
var nxttime = new Date().getTime()
while (true) {
var accountinfo = _C(exchange.GetAccount)
try {
var bdata = GetWebJson("https://api-otc.huobipro.com/v1/otc/trade/list/public?coinId=2&tradeType=0¤tPage=1&payWay=&country=&merchant=1&online=1&range=0").data
var sdata = GetWebJson("https://api-otc.huobipro.com/v1/otc/trade/list/public?coinId=2&tradeType=1¤tPage=1&payWay=&country=&merchant=1&online=1&range=0").data
var count = 0,
rate = 0
for (var k = 0; k < 3; k++) {
count += bdata[k].tradeCount
count += sdata[k].tradeCount
rate += bdata[k].price * bdata[k].tradeCount
rate += sdata[k].price * sdata[k].tradeCount
}
exchangeRate = rate / count
} catch (e) {}
try {
usdprice = GetWebJson("https://www.okex.com/api/v1/future_index.do?symbol=btc_usd").future_index
} catch (e) {}
var rmb = accountinfo.Info.info.btc.account_rights * usdprice * exchangeRate
var startcount = accountinfo.Info.info.btc.account_rights - accountinfo.Info.info.btc.profit_real - accountinfo.Info.info.btc.profit_unreal
// Refresh chart
chart.add(0, [new Date().getTime(), rmb])
chart.add(1, [new Date().getTime(), startcount * exchangeRate * usdprice])
var message = "Current equity of contract account:฿" + accountinfo.Info.info.btc.account_rights + "btc\n" +
"Realized P&L this week:฿" + accountinfo.Info.info.btc.profit_real + "btc\n" +
"Unrealized profit and loss:฿" + accountinfo.Info.info.btc.profit_unreal + "btc\n" +
"HuobiOTCExchange rate:" + exchangeRate.toFixed(2) + "\n" +
"BTCPrice index:$" + usdprice + "\n" +
"ConversionRMBPrice:¥" + (usdprice * exchangeRate).toFixed(0) + "\n" +
"Asset conversion:¥" + rmb.toFixed(0) + "/ $" + (rmb / exchangeRate).toFixed(0) + "\n" +
"Account Margin Rate:" + (accountinfo.Info.info.btc.risk_rate * 100).toFixed(1) + "%\n" +
_D(new Date().getTime())
LogStatus(message)
var nowtime = new Date().getTime()
while (nxttime < nowtime)
nxttime += 30 * 60 * 1000
Sleep(nxttime - nowtime)
}
}Published by leviyuan on the FMZ strategy square · last modified 2018-03-29. 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/okex-BTC-Contract-Account-Public.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.