In the previous articles, we have learned that the so-called programmatic and quantitative trading is a script program based on the data obtained from the exchange through a series of calculations, judgments, and triggers to make some operations, and operate the exchange account to trade. These actions of acquiring data and operating accounts are all carried out through the exchange API interface. Simply put, the script program interacts with the exchange. Since it is an interaction, there must be normal interaction and abnormal interaction. When an abnormal interaction occurs, the interface returns the exception message.

Of course, there are all kinds of error prompts and error messages in the programmatic and quantitative trading systems on the market, or in the programs developed by ourselves. These error messages are not limited to the error messages reported by the exchange API interface. There are also program runtime exception errors, configuration errors, program grammar errors and so on.

On FMZ Quant Trading Platform, error messages can be roughly divided into several categories:

  • Strategy syntax error
    This kind of error is the most common error, which is usually caused by the situation that the beginners are unfamiliar with programming, and the their code writing during study has syntax errors. For example:The code was written without characters like brackets. For this kind of error, the error prompt can be usually seen on the strategy editing page, and under the circumstance, the strategy is unable to run (once the strategy is run, there will be an error reported, as is shown in the image).
    Therefore, you can make it a habit to have a glance of the strategy editing page after finishing writing the code, to see if there is a little red cross; if there is one, that means there is definitely an obvious error.
  • Program exception during operation caused by strategy program BUG
    If a program has bugs during its operation, the trigger of the exception will make the program stop abnormally, and this kind of error messages will be displayed.This kind of errors can all cause the program exception, and stop the program from running.
  • Error caused by improper configuration & settingsOn FMZ platform, all trading pairs are defined in the form of X_Y, in which "X" represents the name of the trading currency, and "Y" represents the name of quote currency (the quote currency of the trading pair in futures crypto-margined contract is usually expressed by USD, and that is introduced in the previous articles). For example, BTC_USDT; suppose that I write it wrong, I write it into BTC-USDT.Error reporting in the backtest system on FMZ platform:Error reporting in a bot:Or, the most common error that beginners often encounter:This kind of error is caused by the invalidation of the API KEY in the configured exchange object after the modification of the password of a FMZ account (the API KEYs of users are all encrypted by the browser end and configured on FMZ platform). That will make a strategy unable to start, which will cause an error reported.
  • Error caused by calling interfaceInterface call errors are often encountered when running strategies. In previous articles, we have studied and learned that the interfaces on FMZ platform are divided into interfaces that make network requests and interfaces that do not make network requests. The interface error will not directly cause the strategy program to stop. Usually, due to the interface call exception, the wrong data is returned, and the strategy does not do the fault tolerance. Then, the program exception error caused by the wrong data makes the program stop (the concept of fault tolerance is already introduced in the previous articles).Here I list several error messages of the interfaces that make network requests:
    • Network timeoutOne of the error messages that beginners often encounter is caused by the use of domestic network device ( PC or domestic servers). Since most platforms are blocked, many platforms are basically inaccessible by the domestic network (in China), and the access interface will report a timeout (mentioned in previous articles).http 429 errorIt is one of the classic error messages; the reason is that a platform interface is called too frequently, exceeding the frequency limit of the platform. (mentioned in the previous articles).
      Some new students may say that the error will not be raised if they apply for API KEYs of several more platforms or several more platform accounts. We need to know that the frequency limit of accessing interfaces by platforms is usually based on IP addresses. Simply put, as long as all requests sent from an IP address are counted on the address, the platform server will deny the access of the IP, if the request number exceeds the limit.Error of platform interface serviceThe timeout and 429 errors mentioned above are errors in the network layer. If there is a problem in the layer of the platform interface service, an error will also be reported. For example, I want to obtain the spot market quotes, but I set up a non-existing trading pair. I test it in the debugging tool of FMZ platform. The debugging tool is a very convenient testing tool, which is very suitable for real bot test of function calls and data acquisition.The execution result of the debugging tool; there is no difference between the execution of the debugging tool and the execution of the bot.
      Huobi error GetTicker: Invalid ticker: {"Info":{"err-code":"invalid-parameter","err-msg":"invalid symbol","status":"error","ts":1620872079355},"High":0,"Low":0,"Sell":0,"Buy":0,"Last":0,"Volume":0,"OpenInterest":0,"Time":0} The error message here means that the trading pair is invalid (see here: "err-msg":"invalid symbol").
      For example, there are many such service-related errors. For example, when setting leverage, some platforms do not support leverage values with decimals. If a leverage value has decimals, it will also cause an error in the interface call.
    List an interface call that does not generate a network request:
    • Set futures contract code
      Some interfaces only set some global variables in the system, and do not make network requests. For example:However, if parameters are passed or written wrong, errors will also be reported.
    No matter what kind of error it is, the error message displayed is the key information for finding the problem, that is, you can tell the problem from the error message. You can use a translation tool to translate the error information in the language you can read, to extract the key words. For instance, "err-msg":"invalid symbol". You can probably know the error is caused by the wrong setting of the trading pair, for the "symbol" usually represents trading code and trading pair in English.
    For the error messages, we will close the discussion here. We have a post where the FAQs are collected and will be updated constantly, for search: https://www.fmz.com/bbs-topic/9158.

Backtest System

The backtest system is also the key point of a quantitative tool. The backtest system can easily test the prototype of a strategy, and initially check out the potential bugs and logical problems in the strategy, but the backtest system needs to be viewed rationally. The backtest system can reflect some problems of a strategy to a certain extent.

The following is a brief description of the backtest system on FMZ platform from the level of different strategy languages supported by FMZ. (Some introductions of the backtest system were mentioned in the previous articles.)

  • JavaScriptThe backtest is performed on the browser, and it uses the local hardware resources.
  • PythonIn the backtest on a docker, you can choose which docker to assign to (either the docker deployed by yourself, or the public docker of FMZ platform). In view of the large load of the public docker on FMZ platform, it is recommended to use the local docker backtest (That will also be faster. In the backtest of the public docker, when it is overloaded, some backtest tasks will be canceled, with the result of the backtest interrupted).
  • C++Unlike scripting languages, C++ strategies need to be compiled and then executed. The C++ language strategy will be compiled first on FMZ platform (server) (if there is a problem with the code writing, the compilation may not pass, and an error message will prompt directly). After the compilation is passed, it will be backtested on FMZ platform (server).
  • MylangaugeThe underlayer is implemented by JavaScript, and the backtest is also performed on the browser.
  • VisualizationThe underlayer is implemented by JavaScript, and the backtest is also performed on the browser

The backtest system of FMZ Quant Trading platform has two backtest modes (no matter what language a strategy is written in, the backtest mode is a setting of backtest system, and the setting options are the same for all languages supported on FMZ).

For the instruction of the backtest system, you can refer to the related part of the strategy writing tutorial on FMZ platform:

https://www.fmz.com/bbs-topic/9091

    1. Simulation Level Backtest
      The simulation level backtest, generally speaking, is to generate the price data of successive time nodes based on K-line data in a simulation way.
    There are the highest, the lowest, open and close prices in one bar, which forms a price structure. Within the time range represented by the K-line, the prices are all in the price structure. Therefore, as long as the generated price is within the K-line structure of the four prices, the simulated price is reasonable. Just like the simulation displayed in the following image:
    Sure, it is slightly more complicated than what is shown in the picture to realize the simulation in the backtest system, which will not be further discussed here. You only need to understand the mechanism of the simulation-level backtest.
    After Knowing the principle, you need to pay attention to the drawbacks of the simulation-level backtest. Although the simulation-level backtest is very fast (because the prices generated by the simulation are not real second-by-second prices released successively). However, if the strategy matches with the simulated tick changing trend, the strategy will perform excellently (but in reality, the price may not change with the trend, although the price is within the structure of the K-line bar).
    The K-line used to generate the simulated tick data here is called the bottom K-line, and the period of the K-line is called the bottom K-line period, which is set on the strategy setting page as the following picture:Here I set 1 minute, which means using the K-line data with a period of 1 minute as the data source to generate the simulated tick data.There is one more point that, for a high-frequency strategy, the simulation-level backtest is obviously not appropriate. But, for a trend strategy, the simulation-level backtest can, to some extend, show the performance of the strategy.
    1. Real Market Level Backtest
      After talking about the simulation level, let's talk about the real market level. Generally speaking, the real market level backtest is to truly release the second-by-second price data in the test, and let the strategy to backtrack the the price of each second in the market. This kind of backtest mode can test some trading strategies with high frequency, and get a result with a certain reference value.
      The disadvantage is that the amount of backtest data at the real market level is too large, and it cannot be tested in a large time range (usually the time range is less than 1 day). You can lower the depth data level by choosing no need for trades history (the history data of trades, and market depth data also has second-by-second snapshots in the real market level backtest, so the amount of real market level backtest data is huge). Appropriately, increase the range of backtest, as shown in the figure:

Where is the data source of FMZ Quant backtest system? The backtest system uses the data of the dashboard on FMZ platform by default. The dashboard of FMZ automatically collects the set market data of each currency on each platform and provides it to the backtest system of the platform.

  1. Use the data of FMZ dashboard
    It is mentioned in the previous articles: https://www.fmz.com/bbs-topic/9245#Quantitative Trading Platform.
    The backtest data provided by the platform only supports a limited number of trading pairs. (the backtest data of the whole market and all currencies is of an astronomical number, and it is unrealistic to collect all of them. The platform has collected market data of mainstream platforms and mainstream currencies.)

There are also some instructions about custom data source in the FMZ API documentation:
https://www.fmz.com/api#Custom Data Source

There are also some schemes in the Digest on FMZ platform. Beginners, who are interested in that, can refer to those schemes and study them.

Study, Test and Think

You cannot do programmed and quantitative trading without studyingtesting and thinking.
It is inefficient to think about questions from nothing. The most efficient way to solve a problem and think about a question is to search for information, then try by yourself, and think and analyze. If the problem is not solved, repeat the above actions.

But, usually when the beginners encounter problems, they will feel:

"Oh, writing programmed and quantitative strategies is super difficult!"
"Still confused about it, even I've been studying it for a while!"
"Just want to give up before even get started!"
...

Getting started with FMZ platform is actually very easy and simple. First of all, you must be good at searching for information. There are a lot of information in the "Square", "Forums" and "Digest" on FMZ Quant Trading Platform.

Then, there is the operational ability; using the backtest system and the debugging tool can easily make a test. This does not mean to test a complete strategy. In fact, if you has completely zero basics, you can even learn the basics of JavaScript programs directly on the backtest system of FMZ Quant.

This is the tutorial website where I often study JS: https://www.runoob.com/js/js-loop-for.html ; the website is not limited to JS, and all kinds of IT knowledge can be queried and learned here.
For example, I don't know how to use the regular expression of JS, what should I do?
Of course, search for the information first, and then try it out!

I saw an example like this:

If I want to test it, I can use the backtest system of FMZ to test it for study.

Randomly set a platform on the backtest system.

Test the following code:

function IsEmail(str) {
    var reg=/^\w+@[a-zA-Z0-9]{2,10}(?:\.[a-z]{2,4}){1,3}$/;
    return reg.test(str);
}

function main() {
    var strEmailAddress1 = "13512345678"
    Log(strEmailAddress1, " Is it the email address? ", " Answer:", IsEmail(strEmailAddress1))
    
    var strEmailAddress2 = "123456789@qq.com"
    Log(strEmailAddress2, " Is it the email address? ", " Answer:", IsEmail(strEmailAddress2))
}

See, what a wonderful tool for study!
For example, if I want to learn how to write the loop logic of the JavaScript language, and then try it out:

According to the sequence of an array, print every element of an array variable in a loop:

function main() {
    var arr = [{coinName: "BTC", price: 10000}, {coinName: "LTC", price: 100}, {coinName: "ETH", price: 2000}, {coinName: "ETC", price: 500}]
    for (var i = 0 ; i < arr.length ; i++) {
        Log(arr[i])
    }
}

Do you feel motivated to learn immediately?
In fact, on FMZ, you can completely learn the basics of JavaScript by trying operations on the backtest system while watching the JavaScript tutorials. After the JavaScript syntax is almost mastered, you can enter the next stage, to actually use the platform interface to obtain data and test. You can also use the debug tool on FMZ to conduct real interface testing.
Then, you need to think more, draw inferences from one case, with tests, verification, and comparative analysis, etc. That makes learning and getting started very fast.

Leave a Reply

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