With the development of quantitative trading of blockchain assets, more and more blockchain asset traders have recognized the tool of quantitative trading. But as a new member of this circle, you are very confused about many concepts, confused by various terms, software, information, etc. This article will take you to understand and familiarize yourself with common concepts, and understand various useful information in the quantitative trading of blockchain assets from various aspects. This article first summarizes the basic concepts, and then gives examples on FMZ Quant Trading platform corresponding to these basic concepts.
First of all, we need to understand the concept of platform. We need to speculate and invest in the blockchain assets in our hands on platforms. There are many platforms currently, senior, emerging, large scaled and small scaled. As for which platform to conduct programmatic and quantitative trading, it is necessary to select by yourself based on various information.
Platform account A platform account is an account registered and opened on the platform. Blockchain assets can be stored in this account for trading. Some platform accounts can create and set sub-accounts under the main account to facilitate the separate trades and speculation of assets. The application, mechanism, and use of sub-account for each platform are different. You need to check the information on the specific platform website. Or consult the platform customer service.
After logging in with an account on the platform website, you can usually see that the place where blockchain assets can be stored is divided into multiple “accounts” (here is a logical account, not a platform account). Usually divided into wallet account, currency trading account, financial management account, contract trading account and so on. The details may vary from platform to platform. Usually, after rush into the blockchain asset (coin), the asset is under an account (it may be in a wallet account, or directly to a currency trading account). Therefore, after recharging, you need to check where the assets are, and transfer when you need to transfer (for example, when you need to trade in futures).
Platform system API Many students who have not used the function on the platform may ask: “What is an API interface?” The API interface is the interface given by a platform system that allows program operations. Simply put, the exchange gives a channel to allow (bot script) programs in the platform system (imagine a certain trading pair market on a platform website) to place orders, cancel orders, check orders, account assets and positions, as well as perform other operations in the platform system .
The platform API is divided into various types of interfaces; usually, there are REST
protocol interfaces and WebSocket
protocol interfaces. Few platforms also provide FIX
protocol interfaces. We only need to have a understanding of those interfaces. The most commonly used interface is the REST protocol. The documentation of these interfaces can usually be found in the link with the word API at the bottom of the official website of those platforms. Sometimes, to query some interface error information, you still need to check the interface documentation. The API system of each platform is different, and the differences are relatively large. For specific problems, you need to check their documentation. If you’re not a strategy developer, these are just for understanding.
API KEY of the account The account API KEY must be carefully understood, because this is related to the security of blockchain assets stored in the platform you use. It is said that the API interface is a channel, then the API KEY can be understood as the pass of the channel. If there is an access channel, not all programs can be allowed to access, for it is dangerous. Therefore, the verification is required, and the API KEY is used to verify the identity. Therefore, the API KEY is related to the security of your assets, so it must be properly kept.
Usually, the APIKEY of a platform is created in the upper right corner of the platform page, on the account management page (there may also be platforms placing it elsewhere on the web page, find the link with the “API” keyword and click to find it). API KEY is of two strings; the first string is usually called access key
, and the second string is usually called secret key
. There are also platforms whose API KEY also has other information. For example, the OKEX V5 and V3 interfaces also have a PassPhrase
, which is also of one string (a string that needs to be set by yourself to strengthen security verification).
When setting the API KEY, it is usually necessary to set the permissions of this API KEY. Generally, there are permissions such as “trade” and “withdrawal”. It should be set according to the purpose of the API KEY, and the permission to withdraw coins needs to be used with caution. In addition to permissions, API KEY can also set an IP address whitelist. If you use an IP other than this IP address whitelist (you can search on Baidu if you do not understand the concept of IP address) to access the interface, the access will be denied (that is, the network outside the IP whitelist cannot access or operate your account).
Exchange object The concept of exchange object is the concept on FMZ Quant Trading Platform (FMZ.COM). Simply put, it refers to an object generated by the encapsulation of the platform interface. This object is “exchange” in the FMZ strategy codes. Calling the “exchange.GetTicker” function actually calls the interface for accessing the platform market data. For details, please refer to the FMZ API documentation: https://www.fmz.com/api#exchange A platform may have a futures module and a spot module. Since the futures exchange object and the spot exchange object defined on FMZ are different types of exchange objects, the modules are distinguished (the futures exchange object has several more functions than the spot exchange object, such as the function of setting the leverage and the function of querying positions, etc. refer to the API documentation for more details).
If the strategy is to operate futures exchange objects, add futures, and if you want to operate spot exchange objects, add spot. The reason for this design is that a platform may have completely different futures and spot interfaces, and even different interface base addresses, so they are encapsulated separately.
On the FMZ platform, “exchange” is an exchange object, which represents a platform account. For details, check out: https://www.fmz.com/api#exchanges
The trading market mentioned here refers to a specific trading market situation (imagine a trade page), usually trading in multiple modules. For example: currency trading, spot margin trading, contract trading, etc.
Trading pair What we usually mean by “trading pair” is simply what we buy and sell, such as when we go to the market to buy cabbage. Then, “cabbage_money” is a trading pair (using underscore" _ " to split). A buyer pays for the cabbage, and the seller gives the cabbage to the buyer to get the money. It is the same for the specific trading pair on a platform. For example: BTC_USDT; we buy in this trading pair, which means paying USDT to get BTC. The selling operation is to pay BTC to get USDT. Taking BTC_USDT as an example, we usually call BTC the trading currency symbol and USDT the quote currency symbol.
Spot
currency trading and spot margin trading are classified as spot trading. Spot trading only needs to specify the trading pair to describe which market it is traded on.
For example, when you use it on FMZ Quant, if you want to make a trading pair of exchanging BTC for USDT. The trading currency is BTC, and the quote currency is USDT.
We use the function exchange.SetCurrency("BTC_USDT")
on FMZ platform exchange.SetCurrency("BTC_USDT")
to switch the current trading pair to: BTC_USDT
.
For students who do not understand SetCurrency
, you can refer to: https://www.fmz.com/api#exchange.setcurrency.
For students who do not understand exchange
, you can refer to: https://www.fmz.com/api#exchange.
Contract (futures & options)
Contract trading is very different from spot trading. At present, platform contracts are divided into crypto-margined contracts
and USDT-margined contracts
. For programmatic trading and quantitative trading, it is necessary to determine not only the trading pair, but also the contract type. For example, if we want to trade with BTC, then there are many BTC contracts, including quarterly contracts (delivery when expired each quarter), weekly contracts (delivery when expired every Friday), perpetual contracts (non-delivery), etc. Then if only one tranding pair is used for identification, which kind of contract will be used? Therefore, a specific contract code is required to describe and determine that.
In this way, when we describe which contract market to trade in, we need to describe what currency symbol (trading pair) and what contract type (contract code) it is.
Crypto-margined contract
Contracts that use cryptocurrency as margin (such as BTC crypto-margined contract, which uses BTC as margin, and the return is also BTC), their return is also cryptocurrency. Usually, the quote currency of the trading pair of the crypto-margined contract is expressed in USD (it is not necessary to go deeply on that, most platforms use it to express). So the trading pair is BTC_USD, and the contract is a quarterly contract. It means that the trading market we are talking about is the BTC crypto-margined quarterly contract
market.
On FMZ Quant Trading Platform, exchange.SetCurrency("BTC_USD")
sets the trading pair, and then exchange.SetContractType("quarter")
sets the quarterly contract. In this way, the current trading symbol is BTC crypto-margined quarterly contract
.
USDT-margined contract
Contracts that use USDT as margin (such as BTC USDT-margined perpetual contract, which uses USDT as margin, and the return is also USDT), their return is also USDT. Usually, the quote currency of the trading pair of the USDT-margined contract is expressed in USDT. Therefore, the trading pair is BTC_USDT, and the contract is a perpetual contract. It means that the trading market we are talking about is the BTC USDT-margined perpetual contract
market.
On FMZ Quant Trading Platform, exchange.SetCurrency("BTC_USDT")
sets the trading pair, and then exchange.SetContractType("swap")
sets the perpetual contract. In this way, the current trading symbol is BTC USDT-margined perpetual contract
.
Order What does an order exactly mean? An order is the order ticket we submit to a platform when we buy or sell on the platform. Orders are divided into market orders, limit orders, conditional orders, etc. The most basic attributes of an order are: the subject matter of the order (simply put, what to buy or sell), the order amount (how much to buy or sell), and the order price (at what price to buy or sell). If the next order does not matter how much it is, it only determines the amount to buy or sell and what to buy or sell, then such an order is called a market order. Of course, there are also conditional orders (stop-loss orders, iceberg orders, etc.), which are related to the platforms. Some platforms provide conditional orders, and some do not. For details, you can check the API documentation of FMZ.
Spot Spot orders and market orders usually need to pay attention to buy orders. The order amount of buying spot market orders is not the currency symbol amount but the money amount. Because the market order does not determine the price, only the money amount can be used to determine how much to buy. The amount of selling market order is the currency symbol amount, because even if the price is uncertain, the amount of the sold currency symbols can be determined.
Contract The order amount of a contract is special, usually the contract amount. The contract order interface of a platform is basically the the contract amount, and there is no interface that takes the currency symbol amount as the order amount. Binance USDT-margined BTC perpetual contracts can order BTC perpetual contracts in an amount of 0.01, but it is not the currency symbol amount, but the contract amount, except that one contract happens to be one BTC. Generally speaking,no matter it is a market order or limit order, the order amount is the number of the contract amount.
Taker order & maker order A taker order is an order that provides liquidity. Simply put, it means that the current market price is 10 for buying one and 11 for selling one. At this time, I pend a buy order with a buy price of 9, or a sell order with a sell price of 12. Then, I provide an order for the depth in the market. This order of mine is maker. Still this example, if I place a buy order at a price of 11; at this time, my order will be traded with a sell order at a price of 11 on the market. At this time, I take an order from the market, the buy order I placed at that time was the taker order.
For example, the order placing functions exchange.Sell
and exchange.Buy
encapsulated on FMZ Quant have the common limit order and market order interfaces encapsulated. When placing an order, whether the order is classified as a taker or a maker depends on the order price and the current market, and whether the order provides liquidity or reduces liquidity.
When importing a price of -1 on FMZ Quant, it is to place a market order. Note that the order amount of the spot market buy order is the money amount, then the market order certainly reduces the liquidity, and it must be a taker order.
Platform conditional order
Many platforms also support conditional orders, such as iceberg order
, stop loss order
, stop profit order
, post_only: only place maker order
, fok: all executed or canceled immediately
, ioc: executed immediately or cancel the rest
, etc.
These orders can use the exchange.IO
function on FMZ Quant to directly access the platform order interface to specify the parameters to be set (specify which conditional order to place) to place an order. For the use of the exchange.IO
function, please refer to the FMZ API documentation: https://www.fmz.com/api#exchange.io...
A quantitative trading platform can be regarded as a quantitative trading tool, it may be an online software system, a website, or a local executable program, or even an open source project on GITHUB. To be simply, you can think of it as a tool for quantitative trading.
FMZ Quant Trading Platform FMZ Quant Trading platform is an online distributed system; for the acquaintance with the platform and tutorials, you can refer to: https://www.fmz.com/bbs-topic/4145
Backtest system of FMZ Quant Trading Platform What is a backtest system? Simply speaking, the backtest system is to replay the history data of a certain trading symbol, and let a certain strategy be included in the replay, and get the trading performance of the strategy when simulating the history data replay. Therefore, the backtest system is just a sandbox environment (imagine the sand pile played by kids and the sand pile can be created into various things; that is only a model, which has nothing to do with real objects), then it is impossible for the backtest system to have any function of a real platform.
FMZ Quant Trading Backtest System:
Name | Type | Instruction |
---|---|---|
Bitfinex | spot exchange object | supporting limited trading pairs, such as: BTC_USD, ETH_USD and LTC_USD, etc. (notice the quote currency of the trading pairs is USD dollar) |
Binance | spot exchange object | supporting limited trading pairs, such as: BTC_USDT, ETH_USDT, ETH_BTC and LTC_BTC, etc. |
OKEX | spot exchange object | supporting limited trading pairs, such as: BTC_USDT, ETH_USDT, ETH_BTC and LTC_BTC, etc. |
Huobi | spot exchange object | supporting limited trading pairs, such as: BTC_USDT, ETH_USDT, ETH_BTC and LTC_BTC, etc. |
OKEX Futures | futures exchange object | supporting limited trading pairs, such as: BTC_USD and ETH_USD, etc.; the quote currency of the trading pairs is USD; after the setting of specific contract code (please refer to the function exchange.SetContractType), the contract is crypto-margined contract; the supported contract codes include: this_week, next_week, quarter and swap |
HuobiDM | futures exchange object | HuobiDM is Huobi Futures (Huobi Contract), supporting limited trading pairs, such as: BTC_USD and ETH_USD,etc.; the quote currency of the trading pairs is USD; after the setting of specific contract code (please refer to the function exchange.SetContractType), the contract is crypto-margined contract; the supported contract codes include: this_week, next_week, quarter and swap. |
BitMEX | futures exchange object | the trading pair is XBT_USD; after the setting of specific contract code (please refer to the function exchange.SetContractType), the contract is a crypto-margined contract; the supported contract code is: XBTUSD |
Binance Futures | futures exchange object | supporting limited trading pairs, such as: BTC_USDT and ETH_USDT, etc.; the quote currency of the trading pairs is USD; after the setting of specific contract code (please refer to the function exchange.SetContractType), the contract is a USDT-margined contract; the supported contract code is swap |
Deribit Options | futures exchange object | trading pairs are: BTC_USD and ETH_USD; after the setting of specific contract code (please refer to the function exchange.SetContractType), the contract is a crypto-margined contract; specific options contract codes need to be set |
API KEY of quantitative trading
All platforms have API interfaces, and the quantitative trading platform also has API interfaces. Taking FMZ Quant trading platform as an example, the API interface of FMZ is called extended API
. Some functions of FMZ platform can be operated programmatically. For example, adding bots in batches, starting bots in batches, modifying the configuration of bots in batches, etc. For details, please refer to: https://www.fmz.com/api#fmz平台扩展api.
The extended API also can be used to do something interesting, for exampleUse the extended API on FMZ Quant to realize “TradingView” Alert Signal Trading
What exactly is automatically controlling my platform account for trading? That is the specific embodiment of program trading and quantitative trading - programmed trading scripts. These real-time programs can be written in various languages. For example, FMZ Quant Trading Platform supports writing real-time trading strategies in JavaScript, Python, and C++ languages. These script programs carry out various operations such as buying and selling of an account through the platform API interfaces.
The device on which the programmed trading script runs
A script program of bot must have a device carrier (in short, the bot must have a place for it to run). Quantitative trading in the cryptocurrency circle usually deploy a bot program to Alibaba Cloud server in Hong Kong (of course, you can also use servers from other places, other operators). In view of the fact that many platforms currently require overseas network access, it is impossible to use domestic servers to run many platform API interfaces. Generally speaking, if the interface is not accessible, an error of timeout
will be reported.
On FMZ Quant, you can usually deploy your own software program on Alibaba Cloud server in Hong Kong (the bot carrier software of FMZ Quant is called “Docker”, and a quantitative trading bot is run based on the docker software).
Script language options There are so many programming languages, and basically all of them can be used to write the script programs of bots. Here we will also take FMZ Quant Trading Platform as an example to make you understand the advantages of various languages. On FMZ Quant, we can write strategies (bot script programs) in the following programming languages.
JavaScript It is simple and easy to use, almost without dependency on the device environment, and supports the ES6 standard. Its strategy program execution speed is only after C++ strategy. (it is recommended for beginners on FMZ Quant trading.)
Python Python depends on the device environment to a certain extent, and various libraries can be installed, so its extensibility is strong. (it is recommended for students who are familiar with FMZ platform and familiar with Python).
C++
The strategies of C++ have the fastest execution speed, the highest efficiency, and also is more difficult to use.
After you master the language, you will find out the others so easy!
Mylanguage Mylanguage supported by FMZ is only for the most basic commands.
Visualization module Merged Strategy Creating strategies in a visual way are only for interest, improvement and understanding of program logic. It can be used to create some simple logic, but it is not suitable to design a slightly complicated strategy, because it is difficult to maintain and extend, and more difficult to design complex logic.