while(true){
//strategy content
Sleep(Interval * 1000) //Sleep
}
}

記錄歷史數據

由于各種原因,機器人可能會反復重啟,如錯誤、參數更新、策略更新等,因此需要保存一些數據以便下次啟動。以下是如何保存初始凈值以計算回報的示例。_G() 函數可以存儲各種數據。_G(key, value) 可以存放 value 的值,并用 _G(key) 調用它,其中 key 是一個字符串。

let init_eq = 0 //defining initial equity
if(!_G('init_eq')){ //If there is no storage, _G('init_eq') returns null.
init_eq = total_eq
_G('init_eq', total_eq) //Since there is no storage, the initial equity is the current equity and is stored here
}else{
init_eq = _G('init_eq') //If stored, read the value of the initial equity
}

策略容錯

在通過 API 獲取持倉、行情等數據時,可能由于各種原因返回錯誤。直接調用數據可能導致策略因錯誤停止,因此需要一種容錯機制。_C() 函數將在遇到錯誤時自動重試,直到返回正確的數據。或者檢查返回后的數據是否可用。

let pos = _C(exchange.GetPosition, pair)

let ticker_A = exchange.GetTicker(pair_a)
let ticker_B = exchange.GetTicker(pair_b)
if(!ticker_A || !ticker_B){
continue //If the data is not available, exit the loop.
}

多幣種兼容 API

GetPosition、GetTicker 和 GetRecords 等函數可以加上交易對參數來獲取相關數據,無需設置交易所綁定的交易對,這大大提升了多交易對策略的兼容性。有關具體的升級內容,請參見文章:https://www.fmz.com/bbs-topic/10456。當然,您需要最新的 docker 來支持它。如果您的 docker 版本過舊,則需要進行升級。

策略參數

完成策略說明

如果您仍然不明白,您可以使用 FMZ 的 API 文檔、調試工具以及市面上常用的 AI 對話工具來解決您的問題。

function GetPosition(pair){
let pos = _C(exchange.GetPosition, pair)
if(pos.length == 0){ //Returns null to indicate no position
return {amount:0, price:0, profit:0}
}else if(pos.length > 1){ //The strategy should be set to unidirectional position mode
throw 'Bidirectional positions are not supported'
}else{ //For convenience, long positions are positive and short positions are negative
return {amount:pos[0].Type == 0 ? pos[0].Amount : -pos[0].Amount, price:pos[0].Price, profit:pos[0].Profit}
}
}

function GetRatio(){
let kline_A = exchange.GetRecords(Pair_A+"_"+Quote+".swap", 60*60, N) //Hourly K-line
let kline_B = exchange.GetRecords(Pair_B+"_"+Quote+".swap", 60*60, N)
let total = 0
for(let i= Math.min(kline_A.length,kline_B.length)-1; i >= 0; i--){ //Calculate in reverse to avoid the K-line being too short.
total += kline_A[i].Close / kline_B[i].Close
}
return total / Math.min(kline_A.length,kline_B.length)
}

function GetAccount(){
let account = _C(exchange.GetAccount)
let total_eq = 0
if(exchange.GetName == 'Futures_OKCoin'){ //Since the API here is not compatible, only OKX Futures Exchange obtains the total equity currently.
total_eq = account.Info.data[0].totalEq //The equity information of other exchanges is also included. You can look for it yourself in the exchange API documentation.
}else{
total_eq = account.Balance //Temporary use of available balances on other exchanges will cause errors in calculating returns, but will not affect the use of strategies.
}
let init_eq = 0
if(!_G('init_eq')){
init_eq = total_eq
_G('init_eq', total_eq)
}else{
init_eq = _G('init_eq')
}
LogProfit(total_eq - init_eq)
return total_eq
}

function main(){
var precision = exchange.GetMarkets() //Get the precision here
var last_get_ratio_time = Date.now()
var ratio = GetRatio()
var total_eq = GetAccount()
while(true){
let start_loop_time = Date.now()
if(Date.now() - last_get_ratio_time > 10*60*1000){ //Update the average price and account information every 10 minutes
ratio = GetRatio()
total_eq = GetAccount()
last_get_ratio_time = Date.now()
}
let pair_a = Pair_A+"_"+Quote+".swap" //The trading pair is set as BTC_USDT.swap
let pair_b = Pair_B+"_"+Quote+".swap"
let CtVal_a = "CtVal" in precision[pair_a] ? precision[pair_a].CtVal : 1 //Some exchanges use sheets to represent quantity, such as one sheet represents 0.01 coin, so you need to convert.
let CtVal_b = "CtVal" in precision[pair_b] ? precision[pair_b].CtVal : 1 //No need to include this field
let position_A = GetPosition(pair_a)
let position_B = GetPosition(pair_b)
let ticker_A = exchange.GetTicker(pair_a)
let ticker_B = exchange.GetTicker(pair_b)
if(!ticker_A || !ticker_B){ //If the returned data is abnormal, jump out of this loop
continue
}
let diff = (ticker_A.Last / ticker_B.Last - ratio) / ratio //Calculate the ratio of deviation
let aim_value = - Trade_Value * diff / Pct //Target holding position
let id_A = null
let id_B = null
//The following is the specific logic of opening a position
if( -aim_value + position_A.amount*CtVal_a*ticker_A.Last > Trade_Value && position_A.amount*CtVal_a*ticker_A.Last > -Max_Value){
id_A = exchange.CreateOrder(pair_a, "sell", ticker_A.Buy, _N(Ice_Value / (ticker_A.Buy * CtVal_a), precision[pair_a].AmountPrecision))
}
if( -aim_value - position_B.amount*CtVal_b*ticker_B.Last > Trade_Value && position_B.amount*CtVal_b*ticker_B.Last < Max_Value){
id_B = exchange.CreateOrder(pair_b, "buy", ticker_B.Sell, _N(Ice_Value / (ticker_B.Sell * CtVal_b), precision[pair_b].AmountPrecision))
}
if( aim_value - position_A.amount*CtVal_a*ticker_A.Last > Trade_Value && position_A.amount*CtVal_a*ticker_A.Last < Max_Value){
id_A = exchange.CreateOrder(pair_a, "buy", ticker_A.Sell, _N(Ice_Value / (ticker_A.Sell * CtVal_a), precision[pair_a].AmountPrecision))
}
if( aim_value + position_B.amount*CtVal_b*ticker_B.Last > Trade_Value && position_B.amount*CtVal_b*ticker_B.Last > -Max_Value){
id_B = exchange.CreateOrder(pair_b, "sell", ticker_B.Buy, _N(Ice_Value / (ticker_B.Buy * CtVal_b), precision[pair_b].AmountPrecision))
}
if(id_A){
exchange.CancelOrder(id_A) //Cancel directly here
}
if(id_B){
exchange.CancelOrder(id_B)
}
let table = {
type: "table",
title: "trading Information",
cols: ["initial equity", "current equity", Pair_A+"position", Pair_B+"position", Pair_A+"holding price", Pair_B+"holding price", Pair_A+"profits", Pair_B+"profits", Pair_A+"price", Pair_B+"price", "current price comparison", "average price comparison", "deviation from average price", "loop delay"],
rows: [[_N(_G('init_eq'),2), _N(total_eq,2), _N(position_A.amount*CtVal_a*ticker_A.Last, 1), _N(position_B.amount*CtVal_b*ticker_B.Last,1),
_N(position_A.price, precision[pair_a].PircePrecision), _N(position_B.price, precision[pair_b].PircePrecision),
_N(position_A.profit, 1), _N(position_B.profit, 1), ticker_A.Last, ticker_B.Last,
_N(ticker_A.Last / ticker_B.Last,6), _N(ratio, 6), _N(diff, 4), (Date.now() - start_loop_time)+"ms"
]]
}
LogStatus("" + JSON.stringify(table) + "") //This function will display a table containing the above information on the robot page. Sleep(Interval * 1000) //Sleep time in ms } }

如何找到更多同類API?

冪簡集成是國內領先的API集成管理平臺,專注于為開發者提供全面、高效、易用的API集成解決方案。冪簡API平臺可以通過以下兩種方式找到所需API:通過關鍵詞搜索API、或者從API Hub分類頁進入尋找。

原文鏈接:https://medium.com/@FMZQuant/introduction-to-the-source-code-of-digital-currency-pair-trading-strategy-and-the-latest-api-of-fmz-56b912a28231

熱門推薦
一個賬號試用1000+ API
助力AI無縫鏈接物理世界 · 無需多次注冊
3000+提示詞助力AI大模型
和專業工程師共享工作效率翻倍的秘密
返回頂部
上一篇
GraphQL API 的 5 個安全提示
下一篇
GraphQL 與 RESTAPI 哪個更有利于 API 可觀察性
国内精品久久久久影院日本,日本中文字幕视频,99久久精品99999久久,又粗又大又黄又硬又爽毛片
成人免费视频在线观看| 中文字幕av一区二区三区免费看 | 中文字幕一区二区三区四区| 久久精品国产秦先生| 6080yy午夜一二三区久久| 一区二区三区在线免费观看| 欧美性大战久久久久久久蜜臀| 亚洲综合一区在线| 欧美日韩激情一区二区三区| 奇米一区二区三区| 精品国产乱码久久久久久闺蜜| 精品亚洲porn| 国产精品久久久久国产精品日日| av亚洲精华国产精华精| 亚洲午夜精品17c| 日韩亚洲欧美中文三级| 国产馆精品极品| 综合激情网...| 欧美区在线观看| 国产99久久久久| 午夜精品影院在线观看| 精品国产3级a| 欧美三级电影一区| 国产99久久久精品| 日韩精品福利网| 综合久久综合久久| 精品免费国产二区三区| 91麻豆蜜桃一区二区三区| 看电影不卡的网站| 伊人婷婷欧美激情| 中文字幕二三区不卡| 5月丁香婷婷综合| www.欧美色图| 国产v综合v亚洲欧| 久久99久久99小草精品免视看| 一区二区三区四区不卡在线| 欧美精品一区二| 欧美三级在线看| 91麻豆国产自产在线观看| 韩国一区二区在线观看| 午夜久久电影网| 亚洲精品国产无套在线观| 国产精品丝袜在线| 国产目拍亚洲精品99久久精品| 91精品国产综合久久久蜜臀粉嫩| 色中色一区二区| 色婷婷av一区二区三区大白胸| 国产乱码精品一区二区三| 韩国一区二区三区| 国产麻豆成人传媒免费观看| 麻豆极品一区二区三区| 日韩电影在线观看电影| 天天操天天干天天综合网| 亚洲午夜电影在线| 婷婷成人综合网| 欧美aaa在线| 免费高清在线视频一区·| 亚洲成人一区二区| 日韩国产在线观看| 奇米色一区二区三区四区| 久久国产免费看| 国产成人综合网| gogogo免费视频观看亚洲一| 波多野结衣在线aⅴ中文字幕不卡| 国产ts人妖一区二区| 99精品1区2区| 制服丝袜在线91| 国产亚洲欧美一级| 亚洲日本一区二区三区| 亚洲第一在线综合网站| 日韩av在线发布| 国产黄色精品视频| 一本色道亚洲精品aⅴ| 91超碰这里只有精品国产| 久久一区二区视频| 一区二区三区中文在线| 久久精品国产精品青草| 色综合久久久久综合体| 欧美不卡123| 亚洲乱码国产乱码精品精的特点 | 天天综合网天天综合色| 国产一区二区毛片| 在线免费观看成人短视频| 日韩三级av在线播放| 1024精品合集| 极品少妇一区二区三区精品视频| 成人一道本在线| 欧美大白屁股肥臀xxxxxx| 亚洲精品欧美在线| 国产成人免费视频网站| 欧美一区二区三区免费视频| 一区二区三区中文字幕| 国产a久久麻豆| 欧美tickling挠脚心丨vk| 亚洲精品视频在线观看免费| 国产成人精品影院| 日韩欧美一区在线观看| 亚洲一区视频在线观看视频| 99精品久久只有精品| 国产精品私人影院| 国产盗摄一区二区| 精品国产免费视频| 美国十次了思思久久精品导航| 欧美在线你懂得| 亚洲三级久久久| www.欧美日韩国产在线| 国产精品乱码久久久久久| 国产成人午夜视频| 日韩精品专区在线影院观看| 日本女优在线视频一区二区| 欧美军同video69gay| 亚洲国产精品一区二区久久恐怖片 | 色综合色狠狠天天综合色| 国产清纯白嫩初高生在线观看91| 免费成人av资源网| 精品美女被调教视频大全网站| 日韩精品电影在线观看| 日韩免费看的电影| 国产一区视频在线看| 国产亚洲精品久| 成人小视频免费在线观看| 国产精品视频在线看| 99久久久精品| 亚洲成人av资源| 91麻豆精品国产91久久久使用方法| 午夜国产不卡在线观看视频| 欧美一区二区精品| 国产真实乱偷精品视频免| 国产精品免费视频观看| 91在线看国产| 日本在线不卡一区| 国产亚洲美州欧州综合国| caoporn国产一区二区| 一区二区三区四区不卡在线 | 日日夜夜免费精品| 久久久久97国产精华液好用吗| 国产成人免费视频网站| 夜夜嗨av一区二区三区中文字幕| 91精品国产高清一区二区三区 | 成人美女视频在线观看| 手机精品视频在线观看| 精品美女一区二区三区| 91日韩一区二区三区| 美女免费视频一区| 亚洲欧美色一区| 2020国产精品| 欧美性大战xxxxx久久久| 粉嫩13p一区二区三区| 视频在线在亚洲| 一区二区三国产精华液| 国产拍揄自揄精品视频麻豆| 欧美日韩国产经典色站一区二区三区 | 69p69国产精品| 99国产一区二区三精品乱码| 麻豆精品精品国产自在97香蕉| 亚洲免费av观看| 久久精品亚洲麻豆av一区二区| 欧美亚洲综合久久| 色综合久久久网| av成人免费在线| 国产精品996| 国产一区二区不卡老阿姨| 日本不卡的三区四区五区| 亚洲综合丝袜美腿| 一区二区免费在线播放| 日韩理论片在线| 亚洲丝袜美腿综合| 亚洲女厕所小便bbb| 国产精品久久久久一区二区三区共| 337p粉嫩大胆噜噜噜噜噜91av| 欧美成人女星排行榜| 日韩欧美久久一区| 欧美电影免费观看高清完整版在| 欧美日韩国产综合一区二区| 欧美裸体bbwbbwbbw| 欧美人体做爰大胆视频| 欧美性一级生活| 欧美日韩国产综合久久| 欧美一区永久视频免费观看| 日韩欧美亚洲另类制服综合在线| 欧美电影一区二区| 欧美mv和日韩mv的网站| 久久久久久久精| 国产精品久久久久久福利一牛影视| 综合中文字幕亚洲| 午夜久久久影院| 久久se这里有精品| 成人免费毛片aaaaa**| 色婷婷激情综合| 欧美久久久影院| 精品成人一区二区| 中文字幕人成不卡一区| 亚洲成av人综合在线观看| 日本美女一区二区三区| 狠狠色伊人亚洲综合成人| www.日韩在线| 日韩一区二区三区视频在线| 国产精品乱码一区二区三区软件| 亚洲 欧美综合在线网络| 国产91精品精华液一区二区三区|