Ejemplo n.º 1
0
    @parse(QSYMBOL_LIST)
    def _read_symbol_list(self, qtype):
        self._buffer.skip()
        length = self._buffer.get_int()
        symbols = self._buffer.get_symbols(length)
        return [s.decode(self._encoding)[::-1] for s in symbols]

    @parse(QSYMBOL)
    def _read_symbol(self, qtype=QSYMBOL):
        return np.string_(self._buffer.get_symbol()).decode(
            self._encoding)[::-1]


if __name__ == '__main__':
    with qconnection.QConnection(host='localhost',
                                 port=5000,
                                 reader_class=StringQReader) as q:
        symbols = q.sync('`foo`bar')
        print(symbols, type(symbols), type(symbols[0]))

        symbol = q.sync('`foo')
        print(symbol, type(symbol))

    with qconnection.QConnection(host='localhost',
                                 port=5000,
                                 reader_class=ReverseStringQReader) as q:
        symbols = q.sync('`foo`bar')
        print(symbols, type(symbols), type(symbols[0]))

        symbol = q.sync('`foo')
        print(symbol, type(symbol))
Ejemplo n.º 2
0
                print(f'type: {type(msg)}, message type: {msg.type}, '
                      f'data size: {msg.size}, is_compressed: {msg.is_compressed}')

                if isinstance(msg.data, list):
                    # unpack upd message
                    if len(msg.data) == 3 and msg.data[0] == b'upd' and isinstance(
                            msg.data[2], QTable):
                        for row in msg.data[2]:
                            print(row)

            except QException as e:
                print(e)


if __name__ == '__main__':
    with qconnection.QConnection(host='localhost', port=17010) as q:
        print(q)
        print('IPC version: %s. Is connected: %s' % (q.protocol_version, q.is_connected()))
        print('Press <ENTER> to close application')

        # subscribe to tick
        response = q.sync('.u.sub', numpy.string_('trade'), numpy.string_(''))
        # get table model 
        if isinstance(response[1], QTable):
            print('%s table data model: %s' % (response[0], response[1].dtype))

        t = ListenerThread(q)
        t.start()
        sys.stdin.readline()
        t.stopit()
Ejemplo n.º 3
0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#

import qpython3
from qpython3 import qconnection
from qpython3.qtype import QException

if __name__ == '__main__':
    print(f'qPython {qpython3.__version__} '
          f'Cython extensions enabled: {qpython3.__is_cython_enabled__)}')
    with qconnection.QConnection(host='localhost', port=5000) as q:
        print(q)
        print('IPC version: %s. Is connected: %s' %
              (q.protocol_version, q.is_connected()))

        while True:
            try:
                x = input('Q)')
            except EOFError:
                print('')
                break

            if x == '\\\\':
                break

            try: