Loading ...

获取账户信息问题

Author: lzhqlj, Created: 2021-11-07 14:59:43, Updated:

模拟盘OKEX 有持仓 成交明细 BTCUSD 永续

全仓
买入

成交时间 数量 价格 交易额 流动性方向 手续费

2021-11-06
13:45:19

1.0001 BTC	61,496.6 USD	1.0001 BTC	吃单	-0.00050002 BTC

代码 var position = exchange.GetPosition() Log(“position.length”,position.length) if(position.length > 0){ Log(“Amount:”, position[0].Amount, “FrozenAmount:”, position[0].FrozenAmount, “Price:”, position[0].Price, “Profit:”, position[0].Profit, “Type:”, position[0].Type, “ContractType:”, position[0].ContractType) } -------------- 显示信息为 2021-11-07 14:56:50 信息 position.length 0 2021-11-07 14:56:50 信息 {“instrument”:“ETH-USD-SWAP”,“InstrumentID”:“ETH-USD-SWAP”} 设置合约: swap 2021-11-07 14:56:50 信息 添加的交易所为期货交易所: Futures_OKCoin 2021-11-07 14:56:50 信息 当前交易所: Futures_OKCoin

读不到数据是什么原因呢?API已经添加模拟API信息了


More

小小梦 另外,你的持仓是BTC的,但是你当前读取的是ETH的持仓,肯定返回是```[]```了。

小小梦 使用```exchange.IO("simulate", true) ```切换模拟盘了么?

lzhqlj 谢谢 读到信息啦

小小梦 你的exchanges 交易所对象都切换模拟盘了么?具体自己检查下,细心。

lzhqlj /upload/asset/23ca3f81151f6e07e79d3.jpg /upload/asset/23bf3ecd55cf97042c92f.jpg /upload/asset/23c46a7af1a3ef0ab85c7.jpg 代码是这个样子的 Log("exchanges[0].GetTicker()", exchanges[0].GetTicker()) Log("exchanges[1].GetTicker()", exchanges[1].GetTicker()) Log("exchanges[0]. GetPosition()", exchanges[0].GetPosition()) Log("exchanges[1]. GetPosition()", exchanges[1].GetPosition()) ------------------------------------------------------------------------------------------- exchanges[0]. GetPosition() [{"Info":{"deltaBS":"","margin":"","availPos":"","cTime":"1636376761683","liqPx":"","mmr":"0.0011116299320592","posCcy":"","thetaBS":"","thetaPA":"","vegaPA":"","instId":"ETH-USD-SWAP","interest":"0","liab":"","mgnRatio":"21842.219147614658","deltaPA":"","imr":"0.001445118911677","optVal":"","posSide":"net","ccy":"ETH","gammaBS":"","last":"4760.37","notionalUsd":"29.99097305872279","avgPx":"4763.22","uTime":"1636376761683","uplRatio":"0","gammaPA":"","lever":"0","mgnMode":"cross","pos":"3","posId":"377924498758184961","tradeId":"35114871","upl":"-0.0000027348184755","vegaBS":"","adl":"1","instType":"SWAP","liabCcy":"","markPx":"4761.152621504205"},"MarginLevel":0,"Amount":3,"FrozenAmount":0,"Price":4763.22,"Profit":-0.0000027348184755,"Margin":0.001445118911677,"Type":0,"ContractType":"swap"}] -------------------------------------------------- 这是返回的信息 请问 1)日志文件里为什么【1】是空的呢?2)返回的信息 也没有开仓信息什么的啊?完全懵逼了。。。。。。谢谢梦总

lzhqlj /upload/asset/23ca3f81151f6e07e79d3.jpg /upload/asset/23bf3ecd55cf97042c92f.jpg /upload/asset/23c46a7af1a3ef0ab85c7.jpg 代码是这个样子的 Log("exchanges[0].GetTicker()", exchanges[0].GetTicker()) Log("exchanges[1].GetTicker()", exchanges[1].GetTicker()) Log("exchanges[0]. GetPosition()", exchanges[0].GetPosition()) Log("exchanges[1]. GetPosition()", exchanges[1].GetPosition()) ------------------------------------------------------------------------------------------- exchanges[0]. GetPosition() [{"Info":{"deltaBS":"","margin":"","availPos":"","cTime":"1636376761683","liqPx":"","mmr":"0.0011116299320592","posCcy":"","thetaBS":"","thetaPA":"","vegaPA":"","instId":"ETH-USD-SWAP","interest":"0","liab":"","mgnRatio":"21842.219147614658","deltaPA":"","imr":"0.001445118911677","optVal":"","posSide":"net","ccy":"ETH","gammaBS":"","last":"4760.37","notionalUsd":"29.99097305872279","avgPx":"4763.22","uTime":"1636376761683","uplRatio":"0","gammaPA":"","lever":"0","mgnMode":"cross","pos":"3","posId":"377924498758184961","tradeId":"35114871","upl":"-0.0000027348184755","vegaBS":"","adl":"1","instType":"SWAP","liabCcy":"","markPx":"4761.152621504205"},"MarginLevel":0,"Amount":3,"FrozenAmount":0,"Price":4763.22,"Profit":-0.0000027348184755,"Margin":0.001445118911677,"Type":0,"ContractType":"swap"}] -------------------------------------------------- 这是返回的信息

小小梦 截图上你的第一个交易所对象不是设置的ETH么, 所以获取ETH的持仓,肯定获取不到BTC的持仓,你要访问第二个交易所对象,用exchanges[1] ,不要用exchange 了。看下API 文档上关于exchanges 和 exchange的说明。

lzhqlj /upload/asset/23ca3f81151f6e07e79d3.jpg 已经在配置实盘 的时候设置拉啊。。。。。。。。。 如果这里设置就可以 的话 那我感觉就是我账户设置的原因了

小小梦 在实盘添加交易所对象时设置的交易对注意下,在策略代码里也可以切换交易对,使用```exchange.SetCurrency("XXX_YYY")```设置完要重新设置合约代码。可以看下萌新入门:https://www.fmz.com/digest-topic/6857 先了解这些基础概念、功能。

lzhqlj 请问是代码设置还是欧易设置呢?新人 一头雾水

小小梦 检查下交易对是不是设置错了。

lzhqlj var Ct = 'swap' //合约类型为永续合约 详见API文档 function main() { // 清空日志,如不需要,可以删除 LogReset(1) // 设置价格小数位精度为2位,品种下单量小数位精度为3位 exchange.SetPrecision(QuotePrecision, BasePrecision) //设置为模拟仓 exchange.IO("simulate", true) Log("当前交易所:", exchange.GetName()) Log("策略开始") var eType = 0 var eName = exchange.GetName() var patt = /Futures_/ if (patt.test(eName)) { Log("添加的交易所为期货交易所:", eName, "#FF0000") eType = 1 if (Ct == "") { throw "Ct 合约设置为空" } else { Log(exchange.SetContractType(Ct), "设置合约:", Ct, "#FF0000") } } else { Log("添加的交易所为现货交易所:", eName, "#32CD32") } var lastMsg = "" var position = exchange.GetPosition() Log("position.length", position.length) if (position.length > 0) { Log("Amount:", position[0].Amount, "FrozenAmount:", position[0].FrozenAmount, "Price:", position[0].Price, "Profit:", position[0].Profit, "Type:", position[0].Type, "ContractType:", position[0].ContractType) } 在实盘配置的时候 添加BTC了 可是不知道为什么 log出来的就是ETH啊 策略: 曲奇测试代码 (最后更新 2021-11-07 23:07:18) 日期: 创建于 2021-11-06 13:43:16 最近开始于 2021-11-08 12:41:18 停止于 2021-11-08 12:41:25 状态: K线周期 3分钟 已停止 托管于 546412 : 8.218.123.197 - linux/amd64 (VPS-12054), ID: 394619 OKEX期货模拟/ETHOKEX期货模拟/BTC

lzhqlj 切换啦啊