1. Quantitative and program trading of digital currency options

Recently, many exchanges have successively opened the trading function of digital currency options as a derivative. Similar to traditional options, options trading and futures trading can be combined 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 underlying framework, be familiar with the programming language for writing the framework, or manually perform complex debugging, configuration, and modification. It is not very convenient for beginners of program trading and quantitative trading. A lot of time should have been devoted to trading strategies and trading ideas have been invested in program debugging and programming language learning.

In the early architecture design, the FMZ Quant (FMZ.COM) took into account the support of various financial derivatives quantification and program trading, and quickly accessed the option trading. Options trading is basically similar to futures trading, or even simpler. In addition, there is no new interface. Users who are familiar with FMZ platform will not increase other learning costs. They can only set the option contract as a futures contract to obtain market information, place orders, cancel orders, query positions, and so on.

2. Access Deribit Exchange directly using native programming language

Let's take the option contract of Deribit Exchange as an example. For example, we need 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() {
    // Get ticker, access interface: 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("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("index_price, marked price data in ticker:", ticker.data.(map[string]interface{})["result"].(map[string]interface{})["index_price"])
}

3. Using the interface encapsulated by the FMZ Quant Trading platform

We finished it by using FMZ platform in two simple sentences.

function main() {
    exchange.IO("base", "https://test.deribit.com")   # Switch to the demo offered by the exchange
    exchange.SetContractType("BTC-3JAN20-7250-P")     # Set up options contracts
    var ticker = exchange.GetTicker()                 # Get options ticker
    Log(ticker.Info.result.index_price)               # Print the required data and observe
}

As we can see, it is very simple to get the required data in just a few lines of code.

This is just accessing the non-signed public API interface of the exchange; accessing the signed private interface would be more complicated.

Each interface has to do a lot of signing, parameter processing, 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 requirements and functions

Not only that, if you need to use concurrent, asynchronous access to the market, order operations, and the code library to handle asynchronous, you need to write more complex asynchronous processing logic. An inattention may also cause logic design problems such as locking. If you need to use chart display again, then you need to learn how to use a lot of libraries. Even a quantitative trader with a programming foundation needs some time to learn. However, it is much easier to use FMZ Quant platform, because these functions have been encapsulated, and the designed call interfaces are very simple and easy to use. You can use very little code to implement the functions of various requirements.

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 "Plot Library" provided by the platform, it is easy to draw a K-line chart:

There are more functions to explore and develop!

5. Postscript

If it is implemented directly in the go language (or python, etc.) like the above, the new students may be discouraged directly>_<
For example strategies of Deribit option operation, see: https://www.fmz.com/strategy/179475

Leave a Reply

Your email address will not be published. Required fields are marked *