Strategy vault / Tools & templates
Financing and Currency Statistics
Use the exchange api function to display the current financing situation of the exchange (the unpaid portion, including handling fees). Currently only OKCoin and Huobi are supported, welcome to continue to improve…
Use the exchange api function to display the current financing situation of the exchange (the unpaid portion, including handling fees). Currently only OKCoin and Huobi are supported, welcome to continue to improve. Latest version of the custodian required.
Source JavaScript
function getLoanInfo(exchange, type) {
var loanInfo;
var dueAmount;
if (exchange.GetName() == "OKCoin") {
loanInfo = exchange.IO("api", "borrows_info", "symbol=cny");
if (type == "btc") {
dueAmount = loanInfo.borrow_btc + loanInfo.interest_btc;
}
else if (type == "ltc") {
dueAmount = loanInfo.borrow_ltc + loanInfo.interest_ltc;
}
else if (type == "cny") {
dueAmount = loanInfo.borrow_cny + loanInfo.interest_cny;
}
}
else if (exchange.GetName() == "Huobi") {
loanInfo = exchange.IO("api", "get_loans", "market=cny");
dueAmount = 0;
for (var i = 0; i < loanInfo.length; i++) {
if (type == "cny" && loanInfo[i].type == 1 || type == "btc" && loanInfo[i].type == 2 || type == "ltc" && loanInfo[i].type == 3) {
dueAmount += (Number(loanInfo[i].loan_amount) - Number(loanInfo[i].repayment_amount) + Number(loanInfo[i].interest_nopay) + Number(loanInfo[i].interest_payed));
}
}
}
else
throw "Exchange not supported yet: " + exchange.GetName();
return dueAmount;
}
function main() {
for (var i = 0; i < exchanges.length; i++)
Log(exchanges[i].GetName(),
"Not returnedCNY:", getLoanInfo(exchanges[i], "cny"),
"Not returnedBTC:", getLoanInfo(exchanges[i], "btc"),
"Not returnedLTC:", getLoanInfo(exchanges[i], "ltc")
);
}Published by 数·狂 on the FMZ strategy square · last modified 2016-01-13. 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 tested, production-ready module from strategies/Financing-and-Currency-Statistics.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.
Related specs
- Binance Account Cross Transfer Small ToolJavaScript · Tools & templates
- Get cryptocurrency current and max supplyJavaScript · Tools & templates
- Interaction TemplateJavaScript · Tools & templates
- KuCoin Fund Transfer PluginJavaScript · Tools & templates
- Moving Average Bot 30 linesJavaScript · Tools & templates · 1d
- OKEx V5 Candlestick Data Paginated Query ExampleJavaScript · Tools & templates