0bps

Strategy vault / Tools & templates

Local Storage

FMZLocal storage calls simplified tool For local storage, please visit [FMZ API Documentation]](https://www.fmz.com/api) Simplified the way FMZ local storage is called, more elegant, no need to call G() anymore…

Author
FawkesPan
Complexity
Starter · 68 lines
Parameters
0

What?

FMZLocal storage calls simplified tool For local storage, please visit [FMZ API Documentation]](https://www.fmz.com/api)

What's the use?

Simplified the way FMZ local storage is called, more elegant, no need to call _G() anymore.

How to use

Import template

First copy this template to your strategy library, then check this template in the strategy where you want to use this tool.

In Strategy Code

Create an object with the following code at the beginning of the strategy

PS = ext.PersistentStorage()

Done This object PS can be used as an ordinary Python dictionary, but it can only store content that can be JSON serialized.**

About this library

Use WTFPL – Do What the Fuck You Want to Public License

Source Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# encoding: utf-8
#
#  Persistent Storage for FMZ
#
# Copyright 2020 FawkesPan
# Contact : [email protected] / Telegram@FawkesPan
#
#            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
#                    Version 2, December 2004 
#
# Copyright (C) 2004 Sam Hocevar <[email protected]> 
#
# Everyone is permitted to copy and distribute verbatim or modified 
# copies of this license document, and changing it is allowed as long 
# as the name is changed. 
#
#            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
#   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 
#
#  0. You just DO WHAT THE FUCK YOU WANT TO.
#

class PersistentStorage:
    
    def __init__(self):
        keys = _G('__keys__')
        if isinstance(keys, list):
            self.__keys__ = keys
        else:
            self.__keys__ = []
            self.__setitem__('__keys__', self.__keys__)
        return
    
    def _add_key(self, key):
        if key == '__keys__':
            return
        self.__keys__.append(key)
        self.__setitem__('__keys__', self.__keys__)
        return
        
    def _del_key(self, key):
        if key == '__keys__':
            return
        if key in self.__keys__:
            del self.__keys__[self.__keys__.index(key)]
        self.__setitem__('__keys__', self.__keys__)
        return
    
    def __setitem__(self, key, value):
        _G(key, value)
        self._add_key(key)
        return
    
    def __delitem__(self, key):
        _G(key, None)
        self._del_key(key)
        return
    
    def __getitem__(self, key):
        return _G(key)

    def keys(self):
        return self.__keys__
        

ext.PersistentStorage = PersistentStorage

Published by FawkesPan on the FMZ strategy square · last modified 2020-04-22. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a tested, production-ready module from strategies/Local-Storage.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open