in fix-client.py [0:0]
def main(config_file):
try:
config = configparser.ConfigParser()
config.read(config_file)
sender_pwd = config["SESSION"]["SenderPassword"] if "SESSION" in config and "SenderPassword" in config["SESSION"] else None
if not sender_pwd:
print("Warning: SESSION SenderPassword is not specified in config file: " + config_file)
settings = fix.SessionSettings(config_file)
application = Application()
application.setSessionPassword(sender_pwd)
store_factory = fix.FileStoreFactory(settings)
log_factory = fix.FileLogFactory(settings)
initiator = fix.SocketInitiator(application, store_factory, settings, log_factory)
initiator.start()
parser = argparse.ArgumentParser(description='CLI Command', prog="command", usage="help | exit | {buy,sell} -s SYMBOL -q QUANTITY [-t {LIMIT,MARKET}] [-p PRICE] [-d DESTINATION] [-e EXCHANGE] [-n ORDER_COUNT] [-i INTERVAL]")
parser.add_argument("command", type=str, choices=["buy", "sell"], help="Command")
parser.add_argument("-s", "--symbol", type=str, required=True, help="Order instrument symbol")
parser.add_argument("-q", "--quantity", type=float, required=True, help="Order quantity")
parser.add_argument("-t", "--order_type", type=str, choices=["LIMIT", "MARKET"], default="MARKET", help="Order type")
parser.add_argument("-p", "--price", type=float, default=None, help="Order limit price")
parser.add_argument("-d", "--destination", type=str, default="SIM", help="Destination ID")
parser.add_argument("-e", "--exchange", type=str, default=None, help="Exchange ID")
parser.add_argument("-n", "--order_count", type=int, default=1, help="Number of orders to submit")
parser.add_argument("-i", "--interval", type=int, default=5, help="Number of seconds between orders")
# wait for the client to login
while not application.sessionID and not application.logged_out:
time.sleep(0.5)
if not application.sessionID:
print("Login failed")
exit(1)
while 1:
print("--> ", end='')
command = input().strip()
if not command:
continue
command_args = command.split(' ') if ' ' in command else [ command ]
command = command_args[0]
if command == "buy" or command == "sell":
try :
args = parser.parse_args(command_args)
side = fix.Side_BUY if command == "buy" else fix.Side_SELL
order_type = fix.OrdType_LIMIT if args.order_type == "LIMIT" else fix.OrdType_MARKET
if order_type == fix.OrdType_LIMIT and args.price is None:
print("Please specify LIMIT order price")
continue
for x in range(args.order_count):
if x > 0:
time.sleep(args.interval)
application.submit_order(args.symbol, side, order_type, args.quantity, args.price, args.destination, args.exchange)
time.sleep(0.5) # wait a bit for response
except:
print(sys.exc_info()[1])
elif command == "quit" or command == "exit":
sys.exit(0)
elif command == "help":
parser.print_usage()
else:
print("Unknown command: %s" % command)
parser.print_usage()
except (fix.ConfigError, fix.RuntimeError) as e:
print(e)