The resource loading... loading...

Quantified trading tools for open-source digital currency options

Author: Inventors quantify - small dreams, Created: 2019-12-27 17:35:30, Updated: 2023-10-17 21:26:52

开箱即用的数字货币期权量化交易工具

Quantified trading tools for open-source digital currency options

1, Quantitization of digital currency options, processed trading

Recently, many exchanges have opened the trading function of this derivative of digital currency options, and similar to traditional options, options trading and futures trading, etc. can be combined to combine many trading strategies, trading methods. Although there are many open source quantitative trading tools on the market, these tools require knowledge of the underlying framework, familiarity with the programming language of the framework or need to manually perform complex debugging, configuration, modification.

发明者量化(FMZ.COM)在早期架构设计时,就考虑了各种金融衍生品量化、程序化交易的支持,非常快捷的接入了期权交易。期权交易基本上和期货交易类似,甚至更加简单。并且没有增加新接口,熟悉使用FMZ的用户不会增加其它学习成本,只用把期权合约当做期货合约一样设置,就可以对期权合约进行行情获取,下单、撤单、查询持仓等操作。

2, directly access the Deribit exchange using the native programming language

Let's take the example of an option contract on the Deribit exchange, for example, we want to get the index price of a current option contract.

The Go language is used to:

package main 

import "net/http"
import "io/ioutil"
import "fmt"
import "encoding/json"



func main() {
    // 获取行情, 访问接口:https://www.deribit.com/api/v2/public/ticker?instrument_name=BTC-27DEC19-7250-P

    resp, err := http.Get("https://www.deribit.com/api/v2/public/ticker?instrument_name=BTC-27DEC19-7250-P")
    if err != nil {
        panic(err)
    }

    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }

    ret := string(body)
    fmt.Println("这只是字符串数据ticker:", ret)
    fmt.Println("需要转换为JSON格式") 

    type js struct {
        data interface{}
    }

    ticker := new(js)

    json.Unmarshal([]byte(ret), &ticker.data)

    fmt.Println("ticker:", ticker) 
    fmt.Println("ticker 中的标记价格数据index_price:", ticker.data.(map[string]interface{})["result"].(map[string]interface{})["index_price"])
}

开箱即用的数字货币期权量化交易工具

You can see that just to get this data, you write N more stacks of code.

3 The interface used by the inventor to quantify the platform packaging

We've solved it with two simple sentences from FMZ.

function main() {
    exchange.IO("base", "https://test.deribit.com")   # 切换为 交易所提供的模拟盘
    exchange.SetContractType("BTC-3JAN20-7250-P")     # 设置期权合约
    var ticker = exchange.GetTicker()                 # 获取期权行情
    Log(ticker.Info.result.index_price)               # 打印需要的数据,观察
}

开箱即用的数字货币期权量化交易工具

As you can see, with just a few lines of code, it's easy to get the data you need.

This is simply a public API interface for non-signature access to an exchange, which is more complicated if you access a private interface for signature.

Each interface also handles a bunch of signatures, parameters, etc.:

        strBody := ""
	strQuery := ""
	ts := toString(time.Now().UnixNano() / 1e6)
	nonce := toString(time.Now().UnixNano() / 1e6)
	uri := resource
	if httpMethod == "GET" {
		strQuery = encodeParams(params, false)
		uri = fmt.Sprintf("%s?%s", resource, strQuery)
	} else if httpMethod == "POST" {
		if len(raw) > 0 && len(raw[0]) > 0 {
			strBody = raw[0]
		} else {
			strBody = json_encode(params)
		}
	}

	strRequestDate := fmt.Sprintf("%s\n%s\n%s\n", httpMethod, uri, strBody)
	strToSign := fmt.Sprintf("%s\n%s\n%s", ts, nonce, strRequestDate)
	h := hmac.New(sha256.New, []byte(p.secretKey))
	h.Write([]byte(strToSign))
	strSign := hex.EncodeToString(h.Sum(nil))

	req := Request{
		Method:  httpMethod,
		Uri:     fmt.Sprintf("%s%s", p.apiBase, uri),
		Timeout: p.timeout,
		Body:    strBody,
	}

4, more complex needs, functions

Not only that, if you need to use a database that requires concurrency, asynchronous acquisition, ordering, and processing of asynchronous code, you need to write a more complex asynchronous processing logic, and a non-resident can also cause logical design problems such as deadlock. If you need to use a graph to show, then you need to learn how to use a large database, even a programming-based quantitative trader, it will take some time to learn.

function main(){
    exchange.IO("base", "https://test.deribit.com")
    exchange.SetContractType("BTC-27DEC19-7250-P")
    while(1){
        var records = exchange.GetRecords()
        Log(records)
        $.PlotRecords(records, "K")
        Sleep(1000)
    }
}

Using the template library "Draw Line Library" provided by the platform, it is very simple to draw a K-line chart:开箱即用的数字货币期权量化交易工具

There are more features to explore and develop!

5 in the background

If implemented directly in a language like go (or python, etc.), it may be possible for new students to be dissuaded immediately >_< The following is a list of examples of strategies for operating Deribit options:https://www.fmz.com/strategy/179475


Related

More