Strategy vault / Tools & templates
Deribit websocket
JavaScript strategy by 发明者量化-小小梦.
JavaScriptTools & templates
The original spec has no written description. Read the source below.
Source JavaScript
var client = null
var deribitAcc = {} // You can set a global object to save token
function WS_GetAccount() { // Get asset information of a certain cryptocurrency in the account
var msg = {
"jsonrpc": "2.0",
"id": 2515,
"method": "private/get_account_summary",
"params": {
"currency": "ETH",
"extended": true
}
}
client.write(JSON.stringify(msg))
var ret = client.read()
Log(ret, "#FF0000")
}
function WS_GetToken() { // Certification and obtain token
var msg = {
"jsonrpc": "2.0",
"id": 9929,
"method": "public/auth",
"params": {
"grant_type": "client_credentials",
"client_id": "XXXXXXX", // obtained when applying for an API KEY
"client_secret": "XXXXXXXXXXXXXXXXXXXXXXXXXX" // obtained when applying for an API KEY
}
}
while (1) {
client.write(JSON.stringify(msg))
var ret = client.read()
try {
var jsonObj = JSON.parse(ret)
if (jsonObj) {
deribitAcc.accessToken = jsonObj.result.access_token
deribitAcc.refToken = jsonObj.result.refresh_token
break
}
} catch (e) {
Log("error:", e)
}
}
Log("Update deribitAcc accessToken , refToken:", deribitAcc)
}
function WS_Depth() { // Visit get_order_book Public channel, to get order book depth data
var msg = {
"jsonrpc": "2.0",
"id": 8772,
"method": "public/get_order_book",
"params": {
"instrument_name": "BTC-PERPETUAL", // Specify to obtain the depth data of BTC perpetual contract
"depth": 5
}
}
client.write(JSON.stringify(msg))
var ret = client.read()
Log("depth : ", ret)
}
function main() {
client = Dial("wss://www.deribit.com/ws/api/v2")
WS_GetToken()
WS_GetAccount()
WS_Depth()
}
function onexit() {
Log("Close ws Connect")
client.close()
}Published by 发明者量化-小小梦 on the FMZ strategy square · last modified 2019-05-15. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a tested, production-ready module from strategies/Deribit-websocket.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Binance Account Cross Transfer Small ToolJavaScript · Tools & templates
- Get cryptocurrency current and max supplyJavaScript · Tools & templates
- Interaction TemplateJavaScript · Tools & templates
- KuCoin Fund Transfer PluginJavaScript · Tools & templates
- Moving Average Bot 30 linesJavaScript · Tools & templates · 1d
- OKEx V5 Candlestick Data Paginated Query ExampleJavaScript · Tools & templates