Inventors' quantitative trading platforms, small partners who develop may often have the following needs:
When developing a strategy lease, you want to have different capital limits for the strategy, different exchange limits for the strategy lease (exchanges that operate the strategy are restricted), or you want to have exchange account configuration restrictions for the strategy lease (specify that the policy will only operate the pre-agreed accounts, the strategy user will use other accounts when the policy is prompted and will no longer trade).
These obviously cannot be written dead in the code, because if they are written dead in the code. All users will be restricted by these conditions, and it is not possible to control different permissions for different user groups.
Based on the above demand scenario, the inventor of the quantitative trading platform has expanded new features:The policy is to set up the metadata of the rental registry code
You can specify a metadata when you create a registration code.Meta
, the data is a string. Note: Meta cannot exceed 190 characters in length when generating the registration code.
For example, I'm a strategy builder, and I've developed a strategy for a spot trading pair for BTC_USDT, a strategy that only does more (originally only quotes coins).QuoteCurrency
USDT is a currency that can be traded on a stock exchange if bought.BaseCurrency
I'm going to lease this strategy, which is called the Bitcoin strategy.test1
。
This is a demonstration of a spot strategy. If the strategy is a futures strategy, it is to limit the holdings of the periodic commodity (according to the holdings data returned by GetPosition). When the strategy finds that the holdings exceed the limit, it no longer executes the single-opening logic (other logics need to be executed normally, such as a placement operation).
So these designs need to be combined with the specifics of the strategy itself, and this example is just a simple illustrative example and may not have any practical use value.
The source code of the strategy:
function main() {
// 策略允许的计价币最大资产数值
var maxBaseCurrency = null
// 获取创建注册码时的元数据
var level = GetMeta()
// 检测Meta对应的条件
if (level == "level1") {
// -1为不限制
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()
// 检测资产数值
var acc = exchange.GetAccount()
if (maxBaseCurrency != -1 && maxBaseCurrency < acc.Stocks + acc.FrozenStocks) {
// 停止执行策略交易逻辑
LogStatus(_D(), "持仓超过注册码的使用限定,不再执行策略交易逻辑!")
continue
}
// 其它交易逻辑
// 正常输出状态栏信息
LogStatus(_D(), "策略正常运行!ticker数据:\n", ticker)
}
}
When you create a registration code, you can find the test1 policy in the policy library and click on the one on the right.Operating itemsClick hereThe sale。
Click hereInternally sold。
Click on the button to set the registration code metadata.
And then you write the information you want to limit.MetaControls, for example, use several of the strategies designed in this case:
We're going to set up the Meta controller first.level1
Let's say that this registry code is created with a test1 policy.level1
I'm not going to lie.
I've created a registration code:
购买地址: https://www.fmz.com/m/s/282900
注册码: 7af0c24404b268812c97b55d073c1867
The policy landlord sends this registration code to the policy tenant.
For example, this time I used this registration code for my other account (the policy tenant) and got permission to use the policy test1.
Strategy tenant, create a virtual disk, use test1, add a WexApp exchange object (WexApp is an FMZ platform analog disk), and run the virtual disk.
You can see that the strategy is working properly.level1
The ranking does not limit the number of holdings (number of coins held in a cash account).
When the policy registration code has been used, it can be modified if the policy developer needs to adjust the meta data of the issued registration code.
In the strategy library, in the sales records.
You can modify the meta data.
We changed the metadata from the previous registration code tolevel3
In this case, the user will be asked to restart the test on the hard disk.
As you can see in the diagram above, it triggers.level3
The ranking limits holdings to a maximum of one coin.
Meta data is configured according to different user groups, different pay-level rental strategies, to achieve policy hierarchy control.
Of course, this is just a list of the most common constraint and control needs. There are a variety of similar needs that can be implemented using this feature.