https://www.deribit.comO endereço do arquivo da API:https://www.deribit.com/pages/docs/api
# 注意
# 1、调用 GetAccount 时不需要设置 合约代码。
# 2、获取行情 等信息 需要设置 合约代码。
# 3、注意使用 SetDirection 设置方向。
# 4、平仓时需注意 是否有仓位 可以平仓,如果 仓位不足以平仓,也是 可以平掉的,会持有 负数仓位,重新开仓会抵消这个 负数仓位。(实测)
# 5、永续合约 名称:BTC-PERPETUAL
Interface da bolsa
Testes de código
// 测试合约代码: BTC-27APR18
function E(obj) {
if (!obj) {
return obj
}
var cloneObj = function(obj) { // 深拷贝 对象函数
var str, newobj = obj.constructor === Array ? [] : {};
if (typeof obj !== 'object') {
return;
} else if (JSON) {
str = JSON.stringify(obj); //系列化对象
newobj = JSON.parse(str); //还原
} else {
for (var i in obj) {
newobj[i] = typeof obj[i] === 'object' ?
cloneObj(obj[i]) : obj[i];
}
}
return newobj;
}
if (obj && typeof(obj) == "object" && typeof(obj.Info) !== "undefined") {
var newObj = cloneObj(obj)
delete newObj.Info
return newObj
} else if (typeof(obj.length) == "number") {
var newArray = []
for (var n = 0; n < obj.length; n++) {
newArray.push(E(obj[n]))
}
return newArray
} else {
// Log(obj, "is not object or not have attribute 'Info'")
return obj
}
}
function main() {
exchange.SetContractType("BTC-27APR18")
Log(exchange.GetAccount())
Sleep(1000)
var ticker = exchange.GetTicker()
Log("ticker:", E(exchange.GetTicker()) )
exchange.SetDirection("buy")
var id1 = exchange.Buy(ticker.Sell, 2)
Log("id1:", id1)
// /*
Log(exchange.GetOrder(id1))
Log(E(exchange.GetAccount()))
Sleep(2000)
var pos = exchange.GetPosition()
Log("pos:", pos)
ticker = exchange.GetTicker()
exchange.SetDirection("closebuy")
var id2 = exchange.Sell(ticker.Buy, 1)
Log("id2:", id2)
Sleep(2000)
pos = exchange.GetPosition()
Log("pos:", pos)
var order
Log(order = exchange.GetOrders())
Log(E(exchange.GetAccount()))
while(order.length != 0){
for(var i = 0; i < order.length; i++){
exchange.CancelOrder(order[i].Id, order[i].Id)
Sleep(2000)
}
order = exchange.GetOrders()
}
ticker = exchange.GetTicker()
exchange.SetDirection("closebuy")
id2 = exchange.Sell(ticker.Buy, 2)
// */
pos = exchange.GetPosition()
Log("pos:", pos)
Log(order = exchange.GetOrders())
}
Diário
A maioria das pessoas tem uma posição negativa em relação a uma moeda.
Modificar o código, abrir outra ordem de contrato, manter um contrato.
function E(obj) {
if (!obj) {
return obj
}
var cloneObj = function(obj) { // 深拷贝 对象函数
var str, newobj = obj.constructor === Array ? [] : {};
if (typeof obj !== 'object') {
return;
} else if (JSON) {
str = JSON.stringify(obj); //系列化对象
newobj = JSON.parse(str); //还原
} else {
for (var i in obj) {
newobj[i] = typeof obj[i] === 'object' ?
cloneObj(obj[i]) : obj[i];
}
}
return newobj;
}
if (obj && typeof(obj) == "object" && typeof(obj.Info) !== "undefined") {
var newObj = cloneObj(obj)
delete newObj.Info
return newObj
} else if (typeof(obj.length) == "number") {
var newArray = []
for (var n = 0; n < obj.length; n++) {
newArray.push(E(obj[n]))
}
return newArray
} else {
// Log(obj, "is not object or not have attribute 'Info'")
return obj
}
}
function main() {
exchange.SetContractType("BTC-27APR18")
Log(exchange.GetAccount())
Sleep(1000)
var ticker = exchange.GetTicker()
Log("ticker:", E(exchange.GetTicker()) )
exchange.SetDirection("buy")
var id1 = exchange.Buy(ticker.Sell, 1)
Log("id1:", id1)
pos = exchange.GetPosition()
Log("pos:", pos)
Log(order = exchange.GetOrders())
}
O resultado foi que o contrato de detenção negativo anterior foi cancelado.
Diários de negociação da bolsa