The resource loading... loading...

Application of Strategy Rental Code Metadata

Author: Ninabadass, Created: 2022-04-13 09:35:06, Updated: 2022-04-13 17:13:27

Application of Strategy Rental code Metadata

Friends who develop on FMZ Quant Trading Platform may often have such needs:

When you develop a strategy for rent, you want to have different limitations of funds on the strategy, and different platform limitations (limit the platforms operated by the strategy), or you want to limit the platform account configuration (specify the strategy can only operate on pre-agreed accounts; when the strategy user uses other accounts, the strategy prompts and will no longer trade and do other operations).

These obviously cannot be hard-coded, because if they are hard-coded, all users will be subject to these limitations, and they cannot control different usage privileges for different user groups.

Based on the above demand scenarios, FMZ Quant Trading platform has expanded a new function: Strategy Rental Register Code Metadata Settings.

When creating a register code, you can specify a metadata Meta, which is a string. Note: The length of Meta cannot exceed 190 characters when it generates the register code.

  • Use FMZ Register Code Metadata to Limit Strategies

    For example, I am an export of strategy development, and I have developed a strategy with a spot trading pair of BTC_USDT. The strategy only makes long positions (initially, it only has the quote currency QuoteCurrency, namely USDT; after buying in, it will hold a position with the BaseCurrency, namely BTC). If I want to rent out this strategy, the strategy name is test1.

    As you can see, the limitations of the strategy need to be specifically designed in combination with the specific situation of the strategy. This example is a demonstration of a spot strategy, but what if the strategy is a futures strategy? Then, it is necessary to limit the futures position information (according to the position data returned by GetPosition). When the strategy finds that the position exceeds the limit, the logic of placing an order and opening a position will no longer be executed (other logic needs to be executed normally, such as closing a position and other operations).

    Therefore, the design of those limitations needs to be combined with the strategy itself; the example is just a simple instruction, without the real use value.

    Strategy Source code:

    function main() {
        // The maximum asset value of the quote currency allowed by the strategy
        var maxBaseCurrency = null
        
        // Obtain the metadata when the register code is created 
        var level = GetMeta()
        
        // Detect the corresponding conditions of Meta
        if (level == "level1") {
            // -1 means no limit 
            maxBaseCurrency = -1       
        } else if (level == "level2") {
            maxBaseCurrency = 10     
        } else if (level == "level3") {
            maxBaseCurrency = 1
        } else {
            maxBaseCurrency = 0.5
        }
        
        while(1) {
            Sleep(1000)
            var ticker = exchange.GetTicker()
            
            // Detect the assets amount 
            var acc = exchange.GetAccount()
            if (maxBaseCurrency != -1 && maxBaseCurrency < acc.Stocks + acc.FrozenStocks) {
                // Stop executing the strategy trading logic
                LogStatus(_D(), "If the position exceeds the usage limits of  register code, the strategy trading logic will no longer be executed!")
                continue
            }
            
            // Other trading logic
            
            // Normally export the information of status bar 
            LogStatus(_D(), "The strategy is operating normally!ticker data:\n", ticker)
        }
    }
    

    When creating the register code, find the strategy test1 in the “Strategy” page, and click on the right Action button, and then click Rent.

img

Click Internal Sale.

img

Click the little “wrench” icon, and set the metadate of the registration code.

img

Then, you need to write the limitation information in the Meta control, such as several usage levels of the strategy designed in this example:

  • level1: no limit for position amount;
  • level2: limit for the maximum position amount to 10 coins;
  • level3: limit for the maximum position amount to 1 coin;
  • Not set Meta: when not set, the default limit for the maximum position amount is 0.5 coin.

img

First of all, we set level1 in the Meta control, and let the created register code have the level1 of test1. After the register code is created, the strategy seller will send the register code to the strategy buyer.

For example, if I use the register code on another account (as the account of buyer) of mine, I will have the right to use the strategy test1.

img

  • How the Strategy Buyer Use the Strategy

    As a strategy buyer, you first need to add a bot, choose test1 as the strategy, and add a WexApp spot exchange object (WexApp is the simulated bot of FMZ), and then run the bot.

img

When you can see the strategy run properly, that means level1 has no limit for the position amount (the coin amount held by the spot account).

  • Modify Metadata

    When the strategy register code is used, if the strategy developer needs to adjust the Metadata of the register code to be sent, he can totally modify it.

    In the “Strategy” page, it is in the records of sale.

    img

    The Metadata can be modified.

    img

    We has changed the metadata of the old register code to level3, and the strategy user needs to restart the bot to test. It triggered the level3 to limit the maximum position amount to 1 coin.

  • Conclusion

    When rent out a strategy, according to different user groups and payment levels, you can specifically configure the Metadata, to control the strategy by levels.

    Of course, the examples mentioned above are only the most common limitations and control demands. There are still various similar demands, which can also realize the function.


More