Out of the box digital currency options quantitative trading tool

1. Quantitative and procedural trading of digital currency options

Recently, many exchanges have successively opened the trading function of digital currency options, a derivative. Similar to traditional options, options trading and futures trading can combine to form many trading strategies and methods. Although there are many open-source quantitative trading tools on the market, these tools often need to understand the bottom layer of the framework, be familiar with the programming language of the framework, or manually conduct complex debugging, configuration, modification. It's not very convenient for novices who are beginning to program and quantify transactions. A lot of time should have been devoted to trading strategy, trading ideas have been put into program debugging, programming language learning.

Inventor quantification( FMZ.COM )In the early architecture design, we considered the support of various financial derivatives quantitative and procedural transactions, and very quickly access to options trading. Options trading is basically similar to futures trading, or even simpler. And there is no new interface. Users who are familiar with FMZ will not increase other learning costs. They can only set option contracts as futures contracts to obtain market prices, place orders, cancel orders, query positions and other operations.

2. Direct access to Deribit exchange using native programming language

Let's take the Deribit exchange option contract as an example. For example, we want to obtain the index price of a current option contract.

Implemented in Go language:

package main 

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

func main() {
    // Access to the market: 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 {

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

    ret := string(body)
    fmt.Println("This is just string data ticker:", ret)
    fmt.Println("Need to convert to JSON format") 

    type js struct {
        data interface{}

    ticker := new(js)

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

    fmt.Println("ticker:", ticker) 
    fmt.Println("ticker Tag price data in index_price: ", ticker.data.(map[string]interface{})["result"].(map[string]interface{})["index_price"])

You can see that in order to get this data, more than N piles of code have been written.

3. Using the interface encapsulated by the inventor's quantitative trading platform

We can use FMZ in two simple sentences.

function main() {
    exchange.IO("base", "https://test.deribit.com ") (switch to the simulation disk provided by the exchange
    exchange.SetContractType("BTC-3JAN20-7250-P")     # Setting up option contracts
    var ticker = exchange.GetTicker()                 # Access to options
    Log(ticker.Info.result.index_price)               # Print required data, observe

As you can see, in a few lines of code, you can simply get the data you need.

This is just to access the non signed public API interface of the exchange. If you access the private interface of the signature, it will be more complex.

Each interface also needs to do a lot of signature and parameter processing:

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))
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 requirements and functions

Not only that, if we need to use concurrent and asynchronous access to the market, order operation, but also use the asynchronous code base, we need to write more complex asynchronous processing logic, a careless may also cause locking and other logic design problems. If you need to use chart display again, then you need to learn a lot about the use of libraries. Even if you are a quantitative trader with programming basis, you need to learn a certain amount of time. However, it is much easier to use inventor quantification, because these functions have been encapsulated, and the designed call interfaces are very simple and easy to use. It can realize the functions of various requirements with little code.

function main(){
    exchange.IO("base", "https://test.deribit.com")
        var records = exchange.GetRecords()
        $.PlotRecords(records, "K")

Using the template library "drawing line class library" provided by the platform, you can easily draw K-line chart:

There are more functions to explore and develop!

5, postscript

If you directly use the go language (or python, etc.) above, maybe new students will be dissuaded directly_<
For example strategies of Deribit option operation, please refer to: https://www.fmz.com/strategy/179475

Tags: Blockchain Programming JSON Go encoding

Posted on Thu, 20 Feb 2020 04:30:47 -0500 by genius