Strategi ini digunakan untuk mendapatkan dan memantau kadar dana dari pelbagai platform niaga hadapan (seperti OKCoin, Binance, Bitget, dan lain-lain). Dengan menyiasat pasaran kontrak kekal di bursa secara selari, dan mendapatkan data kadar dana, sementara menggunakan mekanisme kelewatan untuk mengoptimumkan kekerapan permintaan.
Anda boleh menyesuaikan senarai platform, senarai simbol dan selang rundingan mengikut keperluan untuk memenuhi keperluan dagangan tertentu.
function startFundingWorker() { exchanges.forEach((_, pos) => { __Thread(function (pos) { let e = exchanges[pos] let eName = e.GetName() let delaySettings = { 'Futures_OKCoin': 20, 'Futures_Binance': 500, } let needInterate = ['Futures_OKCoin', 'Futures_Bitget','Futures_OKX', 'Futures_KuCoin', 'Futures_MEXC', 'Futures_Crypto', 'Futures_Deribit'] let delay = function () { let n = delaySettings[eName] if (n) { Sleep(n) } } let epoch = 60000*2; let ts = 0; let fundings = {} while (true) { let now = new Date().getTime() if (now - ts < epoch) { Sleep(1000) continue } let markets = e.GetMarkets() if (!markets) { Sleep(1000) continue } if (needInterate.includes(eName)) { for (let symbol in markets) { if (symbol.includes('.swap')) { let ret = e.GetFundings(symbol) if (ret) { for (let r of ret) { fundings[r.Symbol] = r } } delay(); } } } else { let zones = [] for (let symbol in markets) { if (symbol.includes('.swap') && !zones.includes(markets[symbol].QuoteAsset)) { zones.push(markets[symbol].QuoteAsset) let ret = e.GetFundings(markets[symbol].QuoteAsset + '.swap') if (ret) { for (let r of ret) { fundings[r.Symbol] = r } } delay(); } } } ts = now __threadSetData(0, eName+"_funding", fundings) } }, pos) }) } function getFundings(eName, symbols) { let fundings = __threadGetData(0, eName+"_funding") if (!fundings) { return null } if (typeof(symbols) === 'undefined') { return fundings } let ret = {} symbols.forEach((s) => { if (fundings[s]) { ret[s] = fundings[s] } }) return ret } function main() { startFundingWorker() while (true) { exchanges.forEach((e) => { let eName = e.GetName() let fundings = getFundings(eName, ['BTC_USDT.swap', 'ETH_USDT.swap']) Log(eName, fundings) }) Sleep(5000) } }