Exemplo n.º 1
0
def spawn(dllroot,outdir,intrvl,val_type,*symbols):   
    if val_type not in ['OHLCV','OHLC','CV','C']:
        raise ValueError("invalid val_type (OHLCV,OHLC,CV or C)")

    exc_cmd = "from tosdb.intervalize import " + CLS_BASE + val_type + " as _Goti"
    exec(exc_cmd, globals())
    
    tosdb.init(root=dllroot)
    
    # create block
    blk = tosdb.TOSDB_DataBlock(BLOCK_SIZE, date_time=True)
    blk.add_items(*(symbols))
    blk.add_topics('last')
    if 'V' in val_type:
        blk.add_topics('volume')
        
    # generate filename          
    dprfx = _strftime("%Y%m%d", _localtime())
    isec = int(intrvl * 60)  
    iobjs = list()

    for s in symbols:
        #
        # create GetOnTimeInterval object for each symbol
        # 
        p = _path(outdir) + '/' + dprfx + '_' \
            + s.replace('/','-S-').replace('$','-D-').replace('.','-P-') \
            + '_' + val_type + '_' + str(intrvl) + 'min.tosdb'       
        iobj = _Goti.send_to_file(blk, s, p, getattr(_TI,_TI.val_dict[isec]), isec/10)
        print( repr(iobj) )
        iobjs.append( iobj )
    
    return iobjs
Exemplo n.º 2
0
    def __call__(self, pipe):
        print('starting plotter...')
        tosdb.init(
            dllpath=
            "C:/TOSDataBridge-master/bin/Release/Win32/tos-databridge-0.9-x86.dll"
        )
        b1 = tosdb.TOSDB_DataBlock(50, False)

        b1.add_topics('Volume')
        b1.add_topics('Last')
        b1.add_topics('LAST_SIZE')

        b1.add_items('SPY')
        self.b1 = b1

        for item in b1.items():
            self.volumeData2[item] = [[], [], []]
            self.priceData[item] = [[], [], []]
            self.colors[item] = [[], [], []]

        self.pipe = pipe
        self.fig, self.ax = plt.subplots(1, sharex=False)
        self.fig.set_size_inches((4, 2.5))
        self.fig.tight_layout()
        self.fig.subplots_adjust(top=.95)

        timer = self.fig.canvas.new_timer(interval=refreshInterval * 1000)
        timer.add_callback(self.call_back)
        timer.start()
        #self.socketIO = sio('localhost', 5001,  wait_for_connection=False)
        print('...done')
        plt.show()
Exemplo n.º 3
0
    def __call__(self, pipe):

        tosdb.init(
            dllpath=
            "C:/TOSDataBridge-master/bin/Release/Win32/tos-databridge-0.9-x86.dll"
        )
        b1 = tosdb.TOSDB_DataBlock(50, True)

        b1.add_topics('CUSTOM19')
        b1.add_topics('Last')

        b1.add_topics('ASK')

        b1.add_topics('BID')
        b1.add_items('SPY')
        self.b1 = b1

        for item in b1.items():
            self.priceData[item] = [[], [], []]

        self.pipe = pipe
        self.fig, self.ax = plt.subplots(1, 1, sharex=False)
        self.fig.set_size_inches((1, 1))
        self.fig.tight_layout()

        timer = self.fig.canvas.new_timer(interval=refreshInterval)
        timer.add_callback(self.call_back)
        timer.start()

        plt.show()
Exemplo n.º 4
0
def spawn(dllroot,outdir,intrvl,val_type,*symbols):
   
    if val_type not in ['OHLCV','OHLC','CV','C']:
         raise ValueError("invalid val_type (OHLCV,OHLC,CV or C)")

    exec( "from tosdb.intervalize import " + CLS_BASE + val_type + " as _Goti",
          globals() )
    
    tosdb.init( root=dllroot )
    
    # create block
    blk = tosdb.TOSDB_DataBlock( BLOCK_SIZE, date_time=True)
    blk.add_items( *(symbols) )
    blk.add_topics( 'last' )
    if 'V' in val_type:
        blk.add_topics( 'volume' )
        
    # generate filename                
    dprfx = _strftime("%Y%m%d", _localtime())
    isec = int(intrvl * 60)    
    iobjs = list()
    for s in symbols:
        #
        # create GetOnTimeInterval object for each symbol
        # 
        p = _path(outdir) + '/' + dprfx + '_' + \
                s.replace('/','-S-').replace('$','-D-').replace('.','-P-') + \
                '_' + val_type + '_' + str(intrvl) + 'min.tosdb'           
        iobj = _Goti.send_to_file( blk, s, p, getattr(_TI,_TI.val_dict[ isec ]),
                                   isec/10)
        print( repr(iobj) )
        iobjs.append( iobj )
    
    return iobjs
Exemplo n.º 5
0
def init():
    global vaddr

    print()
    if args.path:
        print('+ lib path:', args.path)
    elif args.root:
        print('+ lib root:', args.root)
    else:
        print(
            'error: tosdb_test.py requires a --root or --path arg for library')
        return False

    if _system() not in ["Windows", "windows", "WINDOWS"]:
        print("error: can only run '--virtual' on non Windows systems")
        return False
    try:
        tosdb.init(dllpath=args.path, root=args.root)
        print('+ init successful')
    except Exception as e:
        print('- init failed:', str(e))
        return False

    print()
    return True
Exemplo n.º 6
0
def init():
    global vaddr

    print()
    if args.path:
        print('+ lib path:', args.path)
    elif args.root:
        print('+ lib root:', args.root)
    else:
        print(
            'error: tosdb_test.py requires a --root or --path arg for library')
        return False

    if args.virtual:
        raw = args.virtual.split(' ')
        try:
            v = ((raw[0], int(raw[1])), )
        except IndexError:
            print("usage: tosdb_test --virtual 'address port [timeout]'",
                  file=_stderr)
            return False
        vaddr = v[0]
        v += (int(raw[2]), ) if len(raw) > 2 else ()
        v = v[:1] + (args.auth, ) + v[1:]
        try:
            tosdb.admin_init(*v)
            print('+ admin_init successful')
        except Exception as e:
            print('- admin_init failed:', str(e))
            return False
        try:
            res = tosdb.vinit(dllpath=args.path, root=args.root)
            print('+ vinit successful')
        except Exception as e:
            print('- vinit failed:', str(e))
            return False
    else:
        if _system() not in ["Windows", "windows", "WINDOWS"]:
            print("error: can only run '--virtual' on non Windows systems")
            return False
        try:
            res = tosdb.init(dllpath=args.path, root=args.root)
            print('+ init successful')
        except Exception as e:
            print('- init failed:', str(e))
            return False

    print()
    return True
Exemplo n.º 7
0
def init():
    global vaddr

    print()
    if args.path:
        print('+ lib path:', args.path)
    elif args.root:
        print('+ lib root:', args.root)
    else:
        print('error: tosdb_test.py requires a --root or --path arg for library')
        return False

    if _system() not in ["Windows","windows","WINDOWS"]:
        print("error: can only run '--virtual' on non Windows systems")
        return False
    try:
        tosdb.init(dllpath=args.path, root=args.root)
        print('+ init successful')
    except Exception as e:
        print('- init failed:',str(e))
        return False
    
    print()
    return True
Exemplo n.º 8
0
def init():
    global vaddr

    print()
    if args.path:
        print("+ lib path:", args.path)
    elif args.root:
        print("+ lib root:", args.root)
    else:
        print("error: tosdb_test.py requires a --root or --path arg for library")
        return False

    if args.virtual:
        raw = args.virtual.split(" ")
        try:
            v = ((raw[0], int(raw[1])),)
        except IndexError:
            print("usage: tosdb_test --virtual 'address port [timeout]'", file=_stderr)
            return False
        vaddr = v[0]
        v += (int(raw[2]),) if len(raw) > 2 else ()
        if args.auth:
            v = v[:2] + (args.auth,) + v[2:]
        try:
            tosdb.admin_init(*v)
            print("+ admin_init successful")
        except Exception as e:
            print("- admin_init failed:", str(e))
            return False
        try:
            res = tosdb.vinit(dllpath=args.path, root=args.root)
            print("+ vinit successful")
        except Exception as e:
            print("- vinit failed:", str(e))
            return False
    else:
        if _system() not in ["Windows", "windows", "WINDOWS"]:
            print("error: can only run '--virtual' on non Windows systems")
            return False
        try:
            res = tosdb.init(dllpath=args.path, root=args.root)
            print("+ init successful")
        except Exception as e:
            print("- init failed:", str(e))
            return False

    print()
    return True
Exemplo n.º 9
0
def init():
    global args
    parser = _ArgumentParser()
    parser.add_argument('build', type=str, help='build: x86 or x64')
    args = parser.parse_args()

    if args.build not in ('x86', 'x64'):
        print('invalid build argument', file=_stderr)
        print('usage: tosdb_test.py [x86|x64]', file=_stderr)
        return

    bdir = "../bin/Release/" + ("Win32" if args.build == 'x86' else "x64")
    if not tosdb.init(root=bdir):
        print("--- INIT FAILED ---", file=_stderr)
        return False
    print()
    return True
Exemplo n.º 10
0
        fout.write(' ')
        _try_write(sdata,i,10,1)                
    else:
        _try_write(mdata,i,50)
        fout.write('\t')
        _try_write(sdata,i,50)
    fout.write('\n')

    
if __name__ == '__main__':
    parser = _ArgumentParser()
    parser.add_argument('--root', help='root directory to search for the library')
    parser.add_argument('--path', help='the exact path of the library')
    args = parser.parse_args()
    if not args.path and not args.root:  
        print('error: --root or --path arg requried')
        exit(1)  
    try:
        res = tosdb.init(dllpath=args.path, root=args.root)        
    except Exception as e:
        print('error: exception during init:', str(e))
        exit(1)  
    print("+ BEGIN")
    test_marker_func('stream_snapshot_from_marker')
    test_marker_func('n_from_marker', N)
    tosdb.clean_up()
    print("+ END")
 


Exemplo n.º 11
0
import tosdb
import time
import csv
import numpy as np
import pandas as pd
from datetime import datetime
from tosdb.intervalize import ohlc
from timeit import default_timer

tosdb.init(
    dllpath=r"C:\TOSDataBridge\bin\Release\x64\tos-databridge-0.9-x64.dll")
block = tosdb.TOSDB_DataBlock(100000, True)
ohlcblock = ohlc.tosdb.TOSDB_ThreadSafeDataBlock(100000)
block.add_items("/MES:XCME", "/MYM:XCBT")
block.add_topics(
    "OPEN",
    "HIGH",
    "LOW",
    "bid",
    "ask",
    "volume",
    "LAST",
    "LASTX",
    "BIDX",
    "ASKX",
    "LAST_SIZE",
    "CUSTOM5",
    "CUSTOM9",
)
time.sleep(2)
Exemplo n.º 12
0
import tosdb
import csv
import threading
import time
from config import *
tosdb.init(root=dir)
tosdb.set_block_limit(20)
block1 = tosdb.TOSDB_DataBlock(10000, True)
block1.add_topics(topics_for_items[0], topics_for_items[1], topics_for_items[2])
block1.add_items(items[0], items[1], items[2])

topics = [block1.items()[2], block1.items()[1], block1.items()[0]]

vol_changes = [0, 0, 0]
price_changes = [0, 0, 0]
last_vols = [0, 0 ,0]
last_prices = [0, 0, 0]

data_SPY = []
data_GOOG = []
data_AAPL = []

def printResults(num):
    if num == 0:
        with open('outputSPY.csv', 'a') as f1:
            writer = csv.writer(f1, delimiter=',', lineterminator='\n')
            writer.writerow(data_SPY)
    elif num == 1:
        with open('outputGOOG.csv', 'a') as f2:
            writer = csv.writer(f2, delimiter=',', lineterminator='\n')
            writer.writerow(data_GOOG)
Exemplo n.º 13
0
def _write(item, s):
    with open(_paths[item], 'a') as f:
        f.write(s)
            

if __name__ == '__main__':
    parser = _ArgumentParser()  
    parser.add_argument('--root', help='root directory to search for the library')
    parser.add_argument('--path', help='the exact path of the library')
    parser.add_argument('outdir', type=str, help='directory to output data to')
    parser.add_argument('interval', type=int, help="interval size in seconds")
    parser.add_argument('--ohlc', action="store_true", 
                        help="use open/high/low/close instead of close")
    parser.add_argument('--vol', action="store_true", help="use volume")
    parser.add_argument('symbols', nargs='*', help="symbols to pull")
    args = parser.parse_args()

    if not args.path and not args.root:
        print("need --root or --path argument", file=_stderr)
        exit(1)

    # connect        
    tosdb.init(args.path,args.root)    
    spawn(args.outdir, args.interval, bool(args.ohlc), bool(args.vol), *args.symbols)