Exemplo n.º 1
0
def main():

    options = {'execution-notification': 1, 'execution-data': 1}
    m = Monitor(options=options)

    def execution(channel, data):
        print(f"{channel} {data}")
        return True

    def executions(channel, data):
        for xid, x in json.loads(data).items():
            pprint(x)
        return True

    def execution_data(channel, data):
        pprint(json.loads(data))
        return True

    def status(channel, data):
        print(f"{channel} {data}")
        if data.startswith('.Authorized'):
            m.send('executions')
        return True

    m.set_callbacks(
        callbacks={
            '*': None,
            'STATUS': status,
            'EXECUTION': execution,
            'EXECUTIONS': executions,
            'EXECUTION_DATA': execution_data,
        })
    m.run()
Exemplo n.º 2
0
def test_monitor_connect_and_wait_for_time_update(server):

    monitor = Monitor(host=test_host,
                      port=test_port,
                      username=test_username,
                      password=test_password,
                      callbacks={'*': _callback},
                      log_level='INFO')

    print(f"\ntxtrader monitor connected: {monitor}")
    assert monitor
    print('waiting for time update...')
    monitor.run()
    print('monitor run() returned')
    assert 'STATUS' in _rx
    assert 'TIME' in _rx
    assert 'SHUTDOWN' in _rx
Exemplo n.º 3
0
from txtrader_monitor import Monitor
import json
from pprint import pprint

m = Monitor()


def status(channel, data):
    trigger = '.accounts:'
    #print(f"{channel}: {data}")
    if data.startswith('.Authorized'):
        m.send(f"accounts")
    elif data.startswith(trigger):
        print(data[len(trigger) + 1:])
        return False
    return True


def main():
    m.set_callbacks(callbacks={
        '*': None,
        'STATUS': status,
    })
    m.run()


if __name__ == '__main__':
    main()
Exemplo n.º 4
0
from txtrader_monitor import Monitor
import json
from pprint import pprint

options = {'order-notification': 1, 'order-data': 1}
m = Monitor(options=options, log_level='WARNING')


def status(channel, data):
    print(f"{channel}: {data}")
    if data.startswith('.Authorized'):
        m.send(f"orders")
    return True


def orders(channel, data):
    print(f"{channel}: {data}")
    return True


def order(channel, data):
    print(f"{channel}: {data}")
    return True


def order_data(channel, data):
    print(f"{channel}: {data}")
    return True


def main():
Exemplo n.º 5
0
from txtrader_monitor import Monitor
import json
from pprint import pprint
import os

m = Monitor(log_level=os.environ.get('TXTRADER_LOG_LEVEL', 'WARNING'))


def status(channel, data):
    trigger = 'rtx.positions:'
    if data.startswith('.Authorized'):
        m.send(f"positions")
    elif data.startswith(trigger):
        print(data[len(trigger) + 1:])
        return False
    return True


def main():
    m.set_callbacks(callbacks={
        '*': None,
        'STATUS': status,
    })
    m.run()


if __name__ == '__main__':
    main()
Exemplo n.º 6
0
#!/bin/env python

import pytest
import ujson as json
from pprint import pprint

from txtrader_monitor import Monitor

m = Monitor(log_level='INFO')

ex = None


def _executions(channel, data):
    global ex
    print(f'{channel} received data: type={type(data)} len={len(data)}')
    ex = (json.loads(data))
    return False


def _status(channel, msg):
    print(f'{channel}: {msg}')
    if msg.startswith('.Authorized'):
        m.send('executions')
    return True


def test_run_query_executions():
    global ex
    m.set_callback('STATUS', _status)
    m.set_callback('EXECUTIONS', _executions)
Exemplo n.º 7
0
from txtrader_monitor import Monitor
import json
from sys import stderr


# print status channel messages to stderr
def status_callback(channel, data):
    stderr.write(f"{channel} {data}\n")
    return True


# print json execution to stdout
def execution_data_callback(channel, message):
    print(message)
    return False


# init monitor with execution-notification and execution-data options enabled
# attach our callback funcitions to the desired channels
# and run it until a callback returns False
Monitor(options={
    'execution-data': 1
},
        callbacks={
            '*': None,
            'STATUS': status_callback,
            'EXECUTION_DATA': execution_data_callback
        }).run()
Exemplo n.º 8
0
#!/bin/env python

import pytest

from txtrader_monitor import Monitor

monitor = Monitor()


def _status(channel, msg):
    global monitor
    print(f'{channel}: {msg}')
    print(f'connection_state is {monitor.connection_state.name}')
    return not msg.startswith('.Authorized')


def test_send_error():
    global monitor
    monitor.send('test')


def test_callback():
    global monitor
    # override single callback, leaving others to print
    monitor.set_callback('STATUS', _status)
    monitor.run()
Exemplo n.º 9
0
from txtrader_monitor import Monitor
import json
from pprint import pprint

options = {'symbol': 'MSFT', 'query_sent': False, 'querydata_sent': False}

m = Monitor(log_level='WARNING')


def symbol(channel, data):
    result = json.loads(data)
    pprint(json.loads(data))
    symbol = options['symbol']
    if not options['query_sent']:
        options['query_sent'] = True
        m.send(f"query {symbol}")
    elif not options['querydata_sent']:
        options['querydata_sent'] = True
        m.send(f"querydata {symbol}")
    return True


def symbol_data(channel, data):
    pprint(json.loads(data))
    return False


def status(channel, data):
    print(f"{channel}: {data}")
    if data.startswith('.Authorized'):
        options['query_sent'] = False