def parse_args(): # Get config file as required arguemnt and load f = argument.Arguments() f.always("config", help="Machine Config file name") arguments, errors = f.parse() if arguments.get("config") is not None: machine_config = strictyaml.load( Path("machine_config/%s.yaml" % arguments.get("config")).bytes().decode('utf8')).data if machine_config.get("currency"): schema = Map({"denominations": Seq(Str())}) notes_config = strictyaml.load( Path("machine_config/notes_config/%s.yaml" % machine_config.get("currency")).bytes().decode('utf8'), schema).data else: print("Currency must be specified") exit(0) else: print("Config file must be specified") exit(0) valid_true_values = [ 'true', '1', 't', 'y', 'yes', 'yeah', 'yup', 'certainly' ] config = Config() config.NAME = machine_config.get("name") config.BASE_CURRENCY = machine_config.get("currency") config.DEBUG = machine_config.get("debug").lower() in valid_true_values config.CAMERA_METHOD = machine_config.get("camera_method") config.ZBAR_VIDEO_DEVICE = machine_config.get("camera_device") config.RELAY_METHOD = machine_config.get("relay_method") config.MOCK_VALIDATOR = machine_config.get( "mock_validator").lower() in valid_true_values config.ZMQ_URL_MOCK_VALIDATOR = machine_config.get( "zmq_url_mock_validator") config.NOTE_VALIDATOR_NV11 = machine_config.get( "validator_nv11").lower() in valid_true_values config.VALIDATOR_PORT = machine_config.get("validator_port") config.ZMQ_URL_PRICEFEED = machine_config.get("zmq_url_pricefeed") config.NOTES_VALUES = notes_config.get("denominations") config.ZMQ_URL_RPC = machine_config.get("zmq_url_rpc") config.ZMQ_URL_STATUS = machine_config.get("zmq_url_status") config.IS_FULLSCREEN = machine_config.get( "is_fullscreen").lower() in valid_true_values config.DEFAULT_SLIPPAGE = machine_config.get("default_slippage") config.BUY_LIMIT = int(machine_config.get("buy_limit")) if not os.uname()[4].startswith("arm"): config.RELAY_METHOD = RelayMethod.NONE return config
def create_arguments(): """ Create the argument parser instance the program uses. """ f = argument.Arguments() # The Makefile to build from. f.option("makefile", "Makefile", help="The makefile to build from.", abbr="f") f.validate("makefile", lambda x: len(x) >= 1) # Number of threads to use for building. f.option("numthreads", 4, help="Number of worker threads.", abbr="n") f.process("numthreads", lambda x: int(x)) f.validate("numthreads", lambda x: x >= 1) # The build target to attempt to build. # TODO: Is there any limitations to the targetnames? f.option("target", "all", help="The target to build.", abbr="t") f.validate("target", lambda x: len(x) >= 2) # arguments we do not use but pass on to the make commands. f.option( "args", "", help="String with arguments to pass through to the make commands.", abbr="a") # Supress warnings and take default answers to all questions. f.switch("supress", help="Supress any questions/warnings, will default to 'yes'.", abbr="s") # Display verbose output or normal. f.switch("verbose", help="Display verbose output while running.", abbr="v") # Simply display the help. f.switch("help", help="Displays the usage information/help.", abbr="h") return f
# along with this program. If not, see <https://www.gnu.org/licenses/>. import zmq import json from time import time, sleep import argument port = '5557' context = zmq.Context() socket = context.socket(zmq.REP) socket.bind('tcp://*:{}'.format(port)) print("Mock web3") f = argument.Arguments() #add a switch, a flag with no argument f.switch("success", help="Auto success", abbr="s") arguments, errors = f.parse() success = arguments[ "success"] # auto success, use an arg parser to add this as cli option try: while True: # Wait for next request from client message = socket.recv().decode('utf-8') msg_json = json.loads(message) print("Received request: ", message) if msg_json['method'] == "buy": print("Buy order")