0bps

Strategy vault / Other

Deribit Options Testing Strategy

Test code for testing option opening, closing, order placement and cancellation, market data retrieval, etc. UsingDeribitTest environment, can be used for actual live trading, can be deleted Line of Code.

JavaScriptOther
Author
发明者量化-小小梦
Complexity
Starter · 87 lines
Parameters
0

DeribitOption test strategy

Test code for testing option opening, closing, order placement and cancellation, market data retrieval, etc. UsingDeribitTest environment, can be used for actual live trading, can be deletedexchange.IO("base", "https://test.deribit.com")Line of Code.

IMG

Source JavaScript

function CancelAll() {
    while (1) {
        var orders = exchange.GetOrders()
        for (var i = 0; i < orders.length; i++) {
            exchange.CancelOrder(orders[i].Id, orders[i])
            Sleep(500)
        }
        if (orders && orders.length == 0) {
            break
        }
        Sleep(500)
    }
    Log(exchange.GetOrders())
}

function main() {
    contract = "BTC-27DEC19-7250-P"
    exchange.IO("base", "https://test.deribit.com")    // Test, usingderibitSimulated test environment, if trading live, please delete this sentence
    exchange.SetContractType(contract)     // Set option contract
    
    // Cancel all current pending orders
    CancelAll()
    
    // Get current account information
    LogStatus(exchange.GetAccount())
    Sleep(500)
    
    // Get current market information
    Log(exchange.GetTicker())
    Sleep(500)

    // Get current depth information
    Log(exchange.GetDepth())
    Sleep(500)
    
    // Get the latest transaction records in the current market
    Log(exchange.GetTrades())
    Sleep(500)
    
    // Get CurrentKLine Data
    Log(exchange.GetRecords())
    Sleep(500)
    
    // Test Order
    exchange.SetDirection("buy")
    var id = exchange.Buy(0.002, 0.1)   // The first parameter refers to the royalty, and the second parameter refers to the quantity of the underlying object.
    Log("id:", id)
    Sleep(500)
    
    // Get order information
    Log(exchange.GetOrder(id))
    Sleep(500)
    
    // Get all current pending orders
    Log(exchange.GetOrders())
    Sleep(500)
    
    // Get current option positions
    Log(exchange.GetPosition())
    Sleep(500)
    
    // Cancel pending order
    exchange.CancelOrder(id)
    Sleep(500)
    
    // Retrieve current pending orders again to check if they are canceled
    Log(exchange.GetOrders())
    Sleep(500)
    
    // Taker transaction
    exchange.SetDirection("sell")
    var ticker = exchange.GetTicker()
    var id2 = exchange.Sell(ticker.Buy, 0.1)
    Sleep(500)
    
    // Get a position
    Log(exchange.GetPosition())
    Sleep(500)
    
    // Close Position
    exchange.SetDirection("closesell")
    var pos = exchange.GetPosition(contract)
    Log("pos", pos)
    var id3 = exchange.Buy(ticker.Sell, pos[0].Amount)
    Log(exchange.GetPosition())
    Sleep(500)
}

Published by 发明者量化-小小梦 on the FMZ strategy square · last modified 2019-12-25. 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.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Deribit-Options-Testing-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open