OKX & Binance Websocket-Vorlage für Hochfrequenzhandel (Multi-Instrument)
event.positions) {
Log("account update", event)
}
if (event.orders) {
Log("private orders update", event)
}
// include orders, positions, balance for latest
Log("account", ctx.wsPrivate.account)
// for test only
if (false) {
return {
amendOrders: [{
instId: event.instId,
clOrdId: "xxxx*****",
cxlOnFail: true,
newSz: "2",
}],
newOrders: [{
instId: event.instId,
clOrdId: UUID(),
side: "sell",
tdMode: "cross",
ordType: "post_only",
px: event.depth.asks[0].price.toFixed(4),
sz: "1",
}, {
instId: event.instId,
clOrdId: UUID(),
side: "sell",
tdMode: "cross",
ordType: "post_only",
px: event.depth.asks[0].price.toFixed(4),
sz: "1",
}],
cancelOrders: [{
instId: order.instId,
clOrdId: order.Id
}]
}
}
}
function main() {
let instId = exchange.SetContractType("swap").InstrumentID
let ctx = $.NewWSS(exchange, function(ws) {
let msg = null
if (exchange.GetName() === 'Futures_OKCoin') {
msg = {
op: "subscribe",
args: [{
channel: "books5",
instId: instId,
}, {
channel: "trades",
instId: instId,
}]
}
} else {
let symbol = exchange.GetCurrency().replace('_', '').toLowerCase()
msg = {
method: "SUBSCRIBE",
params: [symbol + "@aggTrade", symbol + "@depth20@100ms"],
id: "1",
}
}
ws.write(JSON.stringify(msg))
Log("subscribe", msg, "channel")
LogStatus("Ready")
}, onTick, Debug)
while (true) {
ctx.poll()
EventLoop(1000)
}
}
Das Ergebnis der Ausführung ist wie folgt dargestellt. Sie können auch mehrere Instrumente in der Abonnementfunktion abonnieren.
[/upload/asset/107646c11b93b32c493.png](/upload/asset/107646c11b93b32c493.png)
Nachfolgend ein Beispiel für eine universelle Market-Making-Strategie basierend auf dieser Vorlage, die für OKX und Binance funktioniert.
[/upload/asset/73393d2122c1f41a2a.png](/upload/asset/73393d2122c1f41a2a.png)
[/upload/asset/17efd8896a74dc9e271.gif](/upload/asset/17efd8896a74dc9e271.gif)
- 1


