Sumber daya yang dimuat... Pemuatan...

Strategi pengujian opsi Deribit

Penulis:Penemu Kuantitas - Mimpi Kecil, Tanggal: 2019-12-25 13:42:25
Tag:Opsi

Strategi pengujian opsi Deribit

Test code, test option trading, clearing trading, order withdrawal, market acquisition, dan lain sebagainya. Menggunakan lingkungan pengujian Deribit, digunakan untuk hard disk yang sebenarnya, dapat dihapusexchange.IO("base", "https://test.deribit.com")Kode baris.

img


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")    // 测试,使用deribit的模拟测试环境,如果实盘,请删除此句
    exchange.SetContractType(contract)     // 设置期权合约
    
    // 取消当前所有挂单
    CancelAll()
    
    // 获取当前账户信息
    LogStatus(exchange.GetAccount())
    Sleep(500)
    
    // 获取当前行情信息
    Log(exchange.GetTicker())
    Sleep(500)

    // 获取当前深度信息
    Log(exchange.GetDepth())
    Sleep(500)
    
    // 获取当前市场最近成交记录
    Log(exchange.GetTrades())
    Sleep(500)
    
    // 获取当前K线数据
    Log(exchange.GetRecords())
    Sleep(500)
    
    // 测试下单
    exchange.SetDirection("buy")
    var id = exchange.Buy(0.002, 0.1)   // 第一个参数指的是 权利金,第二个参数指的是标的物数量
    Log("id:", id)
    Sleep(500)
    
    // 获取订单信息
    Log(exchange.GetOrder(id))
    Sleep(500)
    
    // 获取当前所有挂单
    Log(exchange.GetOrders())
    Sleep(500)
    
    // 获取当前期权持仓
    Log(exchange.GetPosition())
    Sleep(500)
    
    // 撤销挂单
    exchange.CancelOrder(id)
    Sleep(500)
    
    // 再次获取当前挂单,检查是否撤销
    Log(exchange.GetOrders())
    Sleep(500)
    
    // 吃单成交
    exchange.SetDirection("sell")
    var ticker = exchange.GetTicker()
    var id2 = exchange.Sell(ticker.Buy, 0.1)
    Sleep(500)
    
    // 获取持仓
    Log(exchange.GetPosition())
    Sleep(500)
    
    // 平仓
    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)
}

Berkaitan

Lebih banyak

Wa-emmnn_Dream Sum, Opsi Belakang Akan Mendukung Binance

Wa-emmnn_Bagus sekali.

Penemu Kuantitas - Mimpi KecilYa, sudah didukung, hanya saja tidak ada pembaruan administrator, jika perlu, bisa telegram ke @mygroup, untuk mengirim versi uji coba.