Type/to search
3
Follow
1505
Followers
Estratégia de aquisição e monitoramento de taxas de financiamento FMZ
Discussions
Created 2024-10-31 16:41:13  Updated 2024-11-11 08:47:40
 2
 2083

img

Estratégia de aquisição e monitoramento de taxas de financiamento de futuros multiplataforma

descrever:

Essa estratégia é usada para obter e monitorar taxas de financiamento de diversas plataformas de futuros, como OKCoin, Binance, Bitget, etc. Pesquise os mercados de contratos perpétuos de várias bolsas por meio de threads paralelos e obtenha dados de taxas de financiamento, usando um mecanismo de atraso para otimizar a frequência de solicitações.

Este artigo faz algumas alterações na estratégia para dar suporte às funções de exibição e envio de alarme de taxa de financiamento.

Endereço de código aberto: https://www.fmz.com/strategy/470345

Função:

  • Suporte multiplataforma: Sincronize taxas de financiamento entre diversas exchanges e defina diferentes atrasos de solicitação para cada uma.
  • Aquisição de símbolo específico:Suporta a obtenção de taxas de financiamento para pares de negociação específicos (como BTC/USDT, ETH/USDT).
  • Otimizado para diferentes plataformas: Distinga entre plataformas que não precisam consultar cada mercado um por um (como a Binance) e plataformas que precisam percorrer todos os mercados (como a OKCoin).
  • Taxa de exibição: Exibe taxas de financiamento de múltiplas plataformas de negociação. Como os intervalos de cobrança são diferentes, eles são ajustados uniformemente para taxas de 24h para comparação direta.
  • Aviso de taxa push: Um certo limite pode ser definido. Quando a taxa equivalente de 24h exceder o valor definido, ela será enviada para o APP móvel FMZ.

Instruções:

Você pode ajustar a lista de plataformas, a lista de símbolos e o intervalo de pesquisa conforme necessário para atender às suas necessidades específicas de negociação.

Código de estratégia

O roteiro é dividido em várias partes principais:

  1. startFundingWorker:Inicie um thread independente para cada exchange para monitorar a taxa de financiamento e evitar o atual problema de limitação causado por um único thread solicitando muitos dados.
  2. getFundings: Leia os dados da taxa de financiamento da bolsa especificada no armazenamento.
  3. UpdateStatus: Processe e atualize a tabela de taxas de financiamento de todas as bolsas, exiba os dados agregados como uma tabela e registre os símbolos com taxas altas no log.
  4. main:Inicie o programa principal, inicie o thread de monitoramento e atualize regularmente o status resumido da taxa de financiamento.
javascript
// 启动资金费率监控线程,为每个交易所的资金费率数据创建一个单独的线程 function startFundingWorker() { exchanges.forEach((_, pos) => { __Thread(function (pos) { let e = exchanges[pos] let eName = e.GetName() // 设置不同交易所的请求延迟,以防止频繁请求导致被限流 let delaySettings = { 'Futures_OKCoin': 20, 'Futures_Binance': 500, 'Futures_MEXC': 100, } // 需要遍历所有市场的交易所名称列表,这些交易所不支持一次获取所有交易对 let needInterate = ['Futures_OKCoin', 'Futures_Bitget','Futures_OKX', 'Futures_KuCoin', 'Futures_MEXC'] // 根据交易所名称设定延迟 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) { // 未达到更新周期则暂停1秒后继续检查 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') && symbol.includes('_USDT')) { let ret = e.GetFundings(symbol) if (ret) { for (let r of ret) { fundings[r.Symbol] = r } } delay(); } } } else { // 不在遍历列表中的交易所,仅请求 USDT.swap 的资金费率 let ret = e.GetFundings('USDT.swap') if (ret) { for (let r of ret) { fundings[r.Symbol] = r } } } // 更新数据时间戳 ts = now // 存储该交易所的资金费率数据 __threadSetData(0, eName+"_funding", fundings) } }, pos) }) } // 获取指定交易所的资金费率数据 function getFundings(eName) { let efundings = __threadGetData(0, eName+"_funding") if (!efundings) { return null } return efundings } // 更新资金费率表并在日志中显示 function UpdateStatus(){ let table = { type: 'table', title: 'Funding Rate%', cols: ['index', 'symbol'], // 初始化列,包含 symbol rows: [] }; let fundingRates = {}; exchanges.forEach((e) => { let eName = e.GetName(); if (fundings[eName]) { for (let symbol in fundings[eName]) { // 解析简短的 symbol 名称,去除多余前缀 let short_symbol = symbol.split('_')[0].replace(/^(100|1000|10000|100000|1000000|10000000)|^(100|1000|10000|100000|1000000|10000000)$/g, ''); let rate = fundings[eName][symbol].Rate; let day = 24 / (fundings[eName][symbol].Interval / 3600000) // 初始化符号的数据结构 if (!fundingRates[short_symbol]) { fundingRates[short_symbol] = { total: 0, count: 0, day_rate: {}, next_time: {}, last_time:0}; } // 对超过阈值的费率进行记录并推送 if (Math.abs(rate) > 0.01 && Date.now() - fundingRates[short_symbol].last_time > 30*60*1000) { Log(e.GetName(), symbol, rate, '@') fundingRates[short_symbol].last_time = Date.now() } fundingRates[short_symbol].total += rate; fundingRates[short_symbol].count++; fundingRates[short_symbol].day_rate[eName] = _N(rate * day , 6); // 记录费率 fundingRates[short_symbol].next_time[eName] = _N((fundings[eName][symbol].Time - Date.now()) / 3600000 , 1) + 'h' } } }); // 为每个交易所添加费率列和下次更新的时间列 for (let e of exchanges) { table.cols.push(e.GetName()+' Rate'); table.cols.push('Next Time'); } table.cols.push('Average Rate'); // 添加平均费率列 let i = 0; // 遍历每个符号并填充数据 for (let symbol in fundingRates) { let data = fundingRates[symbol]; if (data.count == 1) { continue // 只包含单个数据点的符号忽略 } let averageRate = data.total / data.count; // 计算平均费率 let row = [i++, symbol]; for (let e of exchanges) { row.push(data.day_rate[e.GetName()] || null); // 填充各个交易所的费率 row.push(data.next_time[e.GetName()] || null); } row.push(_N(averageRate, 6)); // 填充平均费率 table.rows.push(row); } LogStatus('`' + JSON.stringify(table) + '`'); } // 主函数,启动资金费率监控和状态更新 var fundings = {} function main() { startFundingWorker() // 启动每个交易所的监控线程 while (true) { exchanges.forEach((e) => { let eName = e.GetName() let eFundings = getFundings(eName) fundings[eName] = eFundings }) Sleep(15000) // 每15秒更新一次 UpdateStatus() } }
Comment
All comments (2)

    大佬,usdt充值渠道能不能增加大交易所的地址,这样充值就可以免手续费了,对于小额充值手续费都要1.5u了,肉疼=。=

    2 years ago

    嗯嗯,可以考虑,链上手续费太高

    2 years ago
  • 1
iPhone Download
Forums
PINE Language
© 2015 - ∞ INVENTOR PTE LTD (SG)