def main(): parser = argparse.ArgumentParser( description='v1.0 Copyright (C) 2020 Spire Trading Inc.') parser.add_argument('-c', '--config', type=str, help='Configuration file.', default='config.yml') parser.add_argument('-r', '--region', type=str, help='The region to reset.') args = parser.parse_args() try: stream = open(args.config, 'r').read() config = yaml.load(stream, yaml.SafeLoader) except IOError: sys.stderr.write('%s not found\n' % args.config) exit(1) except yaml.YAMLError as e: report_yaml_error(e) exit(1) section = config['service_locator'] address = parse_ip_address(section['address']) username = section['username'] password = section['password'] service_clients = nexus.ApplicationServiceClients(username, password, address) countries = service_clients.get_definitions_client().load_country_database() markets = service_clients.get_definitions_client().load_market_database() region = nexus.parse_country_code(args.region, countries) if region == nexus.CountryCode.NONE: region = nexus.parse_market_code(args.region, markets) if region != '': region = markets.from_code(region) else: region = nexus.parse_security(args.region, markets) service_clients.get_risk_client().reset(nexus.Region(region))
def test_price_retreat(self): security = nexus.parse_security('ABX.TSX') order_fields = nexus.order_execution_service.OrderFields.build_limit_order( security, nexus.Side.ASK, 1000, nexus.Money.ZERO) order = pegged_order.PeggedOrder(self.service_clients, order_fields, nexus.Money.CENT) order.start() self.environment.update_bbo_price(security, nexus.Money.from_value('1.00'), nexus.Money.from_value('1.01')) submission_queue = beam.Queue() self.environment.monitor_order_submissions(submission_queue) expected_order = submission_queue.top() submission_queue.pop() self.assertEqual(expected_order.info.fields.price, nexus.Money.from_value('1.02')) self.assertEqual(expected_order.info.fields.quantity, 1000) self.environment.accept_order(expected_order) self.environment.update_bbo_price(security, nexus.Money.from_value('0.90'), nexus.Money.from_value('0.91')) self.assertTrue( nexus.order_execution_service.tests.is_pending_cancel( expected_order)) self.environment.cancel_order(expected_order) expected_order = submission_queue.top() submission_queue.pop() self.assertEqual(expected_order.info.fields.price, nexus.Money.from_value('0.92')) self.assertEqual(expected_order.info.fields.quantity, 1000) self.environment.accept_order(expected_order) self.environment.fill_order(expected_order, 1000) order.wait() self.assertTrue(submission_queue.is_empty())
def main(): parser = argparse.ArgumentParser( description='v1.0 Copyright (C) 2020 Spire Trading Inc.') parser.add_argument('-c', '--config', type=str, help='Configuration file', default='config.yml') parser.add_argument('-s', '--symbol', type=str, help='Ticker symbol.', required=True) parser.add_argument('-n', '--name', type=str, help='Display name.', required=True) parser.add_argument('-t', '--sector', type=str, help='Sector.', default='') parser.add_argument('-b', '--board_lot', type=str, help='Board lot.', required=True) args = parser.parse_args() try: stream = open(args.config, 'r').read() config = yaml.load(stream, yaml.SafeLoader) except IOError: sys.stderr.write('%s not found\n' % args.config) exit(1) except yaml.YAMLError as e: report_yaml_error(e) exit(1) section = config['service_locator'] address = parse_ip_address(section['address']) username = section['username'] password = section['password'] service_locator_client = \ beam.service_locator.ApplicationServiceLocatorClient(username, password, address) feed_client = nexus.market_data_service.ApplicationMarketDataFeedClient( service_locator_client) security_info = nexus.SecurityInfo() security_info.security = nexus.parse_security('%s' % args.symbol) security_info.name = args.name security_info.sector = args.sector security_info.board_lot = nexus.Quantity.from_value(args.board_lot) feed_client.add(security_info)
def parse_region(service_clients, region): if region == '*': return nexus.Region.GLOBAL market_database = \ service_clients.get_definitions_client().load_market_database() countries = service_clients.get_definitions_client().load_country_database( ) region = nexus.parse_country_code(region, countries) if region == nexus.CountryCode.NONE: region = nexus.parse_market_code(region, market_database) if region != '': region = market_database.from_code(region) else: region = nexus.parse_security(region, market_database) return nexus.Region(region)
def test_rejection(self): security = nexus.parse_security('ABX.TSX') order_fields = nexus.order_execution_service.OrderFields.build_limit_order( security, nexus.Side.BID, 1000, nexus.Money.ZERO) order = pegged_order.PeggedOrder(self.service_clients, order_fields, nexus.Money.CENT) order.start() self.environment.update_bbo_price(security, nexus.Money.from_value('1.00'), nexus.Money.from_value('1.01')) submission_queue = beam.Queue() self.environment.monitor_order_submissions(submission_queue) expected_order = submission_queue.pop() self.assertEqual(expected_order.info.fields.price, nexus.Money.from_value('0.99')) self.assertEqual(expected_order.info.fields.quantity, 1000) self.environment.reject(expected_order) order.wait() self.assertIsNone(submission_queue.try_pop())
def main(): parser = argparse.ArgumentParser( description='v1.0 Copyright (C) 2020 Spire Trading Inc.') parser.add_argument('-c', '--config', type=str, help='Configuration file', default='config.yml') parser.add_argument('-s', '--start', type=parse_date, help='Start range', required=True) parser.add_argument('-e', '--end', type=parse_date, help='End range', required=True) parser.add_argument('-m', '--market', type=str, help='Market') parser.add_argument('-t', '--symbol', type=str, help='Ticker symbol') parser.add_argument('-a', '--account', type=str, help='Account') args = parser.parse_args() try: stream = open(args.config, 'r').read() config = yaml.load(stream, yaml.SafeLoader) except IOError: sys.stderr.write('%s not found\n' % args.config) exit(1) except yaml.YAMLError as e: report_yaml_error(e) exit(1) address = parse_ip_address(config['service_locator']) username = config['username'] password = config['password'] start_date = beam.time_service.to_utc_time(args.start) end_date = beam.time_service.to_utc_time(args.end) service_locator_client = beam.service_locator.ApplicationServiceLocatorClient( username, password, address) definitions_client = nexus.definitions_service.ApplicationDefinitionsClient( service_locator_client) order_execution_client = \ nexus.order_execution_service.ApplicationOrderExecutionClient( service_locator_client) market_database = definitions_client.load_market_database() time_zone_database = definitions_client.load_time_zone_database() if args.market is not None: market = nexus.parse_market_code(args.market, market_database) else: market = None if args.symbol is not None: security = nexus.parse_security(args.symbol, market_database) else: security = None if args.account is not None: account = service_locator_client.find_account(args.account) else: account = None (orders, activity_log) = execute_report(start_date, end_date, security, market, account, market_database, time_zone_database, service_locator_client, order_execution_client) output_order_log(orders) output_activity_log(activity_log)