Esempio n. 1
0
def csvReadandPublish(dir,files):
    for i in files:
        path = dir + '/' + i
        info ('Reading in csv file from '+ path)

        with open(path) as csv_file:
            csv_reader = csv.reader(csv_file,delimiter=',')
            row_count = 0

            for row in csv_reader:
                if i == 'trade.csv':
                    if row_count > 0:
                        #print('Row values at index '+ str(row_count) + ':\n {} {} {} {}'.format(row[0],row[1],row[2],row[3]))
                        #print('Row type: \n {} \n {} \n {} \n {}'.format(type(row[0]),type(row[1]),type(row[2]),type(row[3])))
                        # CSV reader reads all values as str. Cast each value to the appropriate type
                        '''
                        Trade Table types
                        
                        time - timespan (.z.N) --> we will cast this to a long value which will be casted to timespan datatype on kdb
                        sym - symbol (no casting required) --> python str are automatically casted to kdb sym type
                        price - float
                        size - int
                        '''
                        row[0] = K.timespan(convertTimeToLong(row[0]))
                        row[2] = K.float(int(row[2]))
                        row[3] = K.int(int(row[3]))
                        
                        #Send the converted row values to the TP process through the handle
                        handle(('.u.upd','trade',(row[0],row[1],row[2],row[3])))
                    row_count += 1
                
                elif i == 'quote.csv':
                    if row_count > 0:
                        #print('Row values at index '+ str(row_count) + ':\n {} {} {} {}'.format(row[0],row[1],row[2],row[3]))
                        #print('Row type: \n {} \n {} \n {} \n {}'.format(type(row[0]),type(row[1]),type(row[2]),type(row[3])))
                        # CSV reader reads all values as str. Cast each value to the appropriate type
                        '''
                        Quote Table types
                        
                        time - timespan (.z.N) --> we will cast this to a long value which will be casted to timespan datatype on kdb
                        sym - symbol (no casting required) --> python str are automatically casted to kdb sym type
                        bid - float
                        ask - float
                        bsize - int
                        asize - int
                        '''
                        row[0] = K.timespan(convertTimeToLong(row[0]))
                        row[2] = K.float(int(row[2]))
                        row[3] = K.float(int(row[3]))
                        row[4] = K.int(int(row[4]))
                        row[5] = K.int(int(row[5]))

                        #Send the converted row values to the TP process through the handle
                        handle(('.u.upd','quote',(row[0],row[1],row[2],row[3],row[4],row[5])))
                    row_count += 1
Esempio n. 2
0
def test_closed_connection(kdb_server):
    cmd = K.string("exit 0")
    with pytest.raises(kerr) as info:
        kdb_server(cmd)
    msg = info.value.args[0]
    if WIN:
        assert msg.startswith('rcv.')
    else:
        assert msg == 'close'
Esempio n. 3
0
def test_no_numpy(monkeypatch):
    monkeypatch.setitem(sys.modules, 'numpy', None)
    pyq_modules = [
        m for m in sys.modules if m == 'pyq' or m.startswith('pyq.')
    ]
    for m in pyq_modules:
        monkeypatch.delitem(sys.modules, m)
    from pyq import K
    # TODO: Figure out how to run all tests that don't require numpy.
    assert K(0) == 0
Esempio n. 4
0
def test_convert_path(x):
    p = pathlib.Path(x)
    assert str(K(p)) == ':' + x.replace(os.sep, '/')
Esempio n. 5
0
def test_async_call(kdb_server):
    c = -kdb_server
    c(K.string("x:42"))
    assert kdb_server('x') == 42
Esempio n. 6
0
def test_convert_path(x):
    p = pathlib.Path(x)
    assert str(K(p)) == ':' + x
Esempio n. 7
0
def test_closed_connection(kdb_server):
    cmd = K.string("exit 0")
    with pytest.raises(kerr) as info:
        kdb_server(cmd)
    assert info.value.args[0] == 'close'