def connect_and_stream_account_data(ip, port):
    try:
        socket_client = SocketClient(ip, port)
        gateway = GatewayInterface(socket_client)
        gateway.set_data_handlers(account_data=on_account_data)
        gateway.request_account_updates()
        socket_client.loop()
    except KeyboardInterrupt:
        pass
    except Exception as e:
        print e

    socket_client.shutdown()
def connect_and_stream_market_data(ip, port, contracts):
    try:
        socket_client = SocketClient(ip, port)
        gateway = GatewayInterface(socket_client)
        gateway.set_data_handlers(market_data=on_market_data)

        for contract in contracts:
            gateway.request_market_data(contract)

        socket_client.loop()
    except KeyboardInterrupt:
        pass
    except Exception as e:
        print e

    socket_client.shutdown()
Example #3
0
def connect_and_stream_position_data(ip, port):
    try:
        socket_client = SocketClient(ip, port)
        gateway = GatewayInterface(socket_client)
        gateway.set_data_handlers(position_data=on_position_data)
        gateway.request_position_updates()
        socket_client.loop()
    except KeyboardInterrupt:
        pass
    except Exception as e:
        print e

    socket_client.shutdown()
def connect_and_stream_order_data(ip, port):
    try:
        socket_client = SocketClient(ip, port)
        gateway = GatewayInterface(socket_client)
        gateway.set_data_handlers(unhandled_data=on_unhandled_server_data,
                                  account_data=on_account_data,
                                  order_data=on_order_data)
        gateway.request_order_updates()
        socket_client.loop()
    except KeyboardInterrupt:
        pass
    except Exception as e:
        print e

    socket_client.shutdown()
def connect_and_stream_market_data(ip, port, contracts):
    try:
        socket_client = SocketClient(ip, port)
        gateway = GatewayInterface(socket_client)
        gateway.set_data_handlers(market_data=on_market_data)

        for contract in contracts:
            gateway.request_market_data(contract)

        socket_client.loop()
    except KeyboardInterrupt:
        pass
    except Exception as e:
        print e

    socket_client.shutdown()
from classes.socket_client import SocketClient
from classes.gateway_interface import GatewayInterface

ip, port = "localhost", 4000  # Connection details
contract, price, is_buy, qty = "XCME_Eq NQ (M15)", 443350, False, 1  # Order details

socket_client = SocketClient(ip, port)
gateway = GatewayInterface(socket_client)
gateway.send_limit_order(contract, is_buy, price, qty)