OKX&Binance Websocket 고빈도 거래 템플릿 (다종목)
event.positions) {
Log("account update", event)
}
if (event.orders) {
Log("private orders update", event)
}
// 최신 orders, positions, balance 포함
Log("account", ctx.wsPrivate.account)
// 테스트 전용
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)
}
}
실행 결과는 아래와 같습니다. 구독 함수에서 여러 종목을 구독할 수도 있습니다.
[/upload/asset/107646c11b93b32c493.png](/upload/asset/107646c11b93b32c493.png)
다음은 이 템플릿을 기반으로 구현된 OKX와 Binance 공용 마켓 메이커 전략의 실행 결과입니다.
[/upload/asset/73393d2122c1f41a2a.png](/upload/asset/73393d2122c1f41a2a.png)
[/upload/asset/17efd8896a74dc9e271.gif](/upload/asset/17efd8896a74dc9e271.gif)
- 1


