def init_pubsub(): """Initiate pubsub module, create default publisher""" try: this.hub = aiopubsub.Hub() this.publisher = aiopubsub.Publisher(this.hub, prefix=aiopubsub.Key()) except Exception: logger.exception('Error initiationg pubsub module') raise
def __init__(self): logwood.basic_config() self.hub = aiopubsub.Hub() self.publisher = aiopubsub.Publisher(self.hub, prefix=aiopubsub.Key('peer')) self.subscriber_epoch = aiopubsub.Subscriber(self.hub, 'epoch_subscr') self.subscriber_connection = aiopubsub.Subscriber( self.hub, 'conn_subscr') self.subscriber_pom = aiopubsub.Subscriber(self.hub, 'pom_subsrc') sub_key_epoch = aiopubsub.Key('peer', 'epoch') self.subscriber_epoch.subscribe(sub_key_epoch) sub_key_conn = aiopubsub.Key('peer', 'connection') self.subscriber_connection.subscribe(sub_key_conn) sub_key_pom = aiopubsub.Key('peer', 'pom') self.subscriber_pom.subscribe(sub_key_pom)
async def run_backtest(file: str, start, end, capital: float, bar: str, threshold: int) -> None: hub = aiopubsub.Hub() bar_generator = new_bar_generator(bar, hub, threshold) bar_writer = CSVBarWriter(hub, 'output.csv') p1s = [5, 11, 17, 20] p2s = [40, 60, 80] for p1, p2 in zip(p1s, p2s): logger.info("{p1} {p2} starting", p1=p1, p2=p2) broker = BacktestBroker(hub) strategy = read_and_run_strategy_file(file)(hub, broker, p1=p1, p2=p2) if start is not None: print(start) print(end) date_range = DateRange(start, end) else: date_range = None trade_processor = ArcticTradeProcessor(hub, strategy.exchange, strategy.market, date_range) trade_processor.run() logger.info( f"total realized pnl: {strategy.position_manager.total_realized_pnl()}" ) asyncio.get_event_loop().stop()
import aiopubsub import functools from galacteek import log from galacteek.core import runningApp gHub = aiopubsub.Hub() publisher = aiopubsub.Publisher(gHub, prefix=aiopubsub.Key('g')) @functools.lru_cache(maxsize=256) def makeKey(*args): if isinstance(args, str): return aiopubsub.Key(args) elif isinstance(args, tuple): return aiopubsub.Key(*args) def makeKeyChatChannel(channel): return makeKey('g', 'chat', 'channels', channel) def makeKeyChatUsersList(channel): return makeKey('g', 'pubsub', 'chatuserslist', channel) def makeKeyPubChatTokens(channel): return makeKey('g', 'pubsub', 'tokens', 'pubchat', channel)
def hub(): return aiopubsub.Hub()
def backtest_broker(): hub = aiopubsub.Hub() return BacktestBroker(hub)
def main(): parser = argparse.ArgumentParser(description='Select streaming regions') parser.add_argument('--area',type=area,nargs="+",help="specify areas --area x1,y1,w1,h1 x2,y2,w2,h2 .... Not specified means full desktop",default=None) parser.add_argument('--http',type=int,default=8080,help="http port, use 0 for disable") parser.add_argument('--rtsp',type=int,default=8666,help="rtsp port, use 0 for disable") parser.add_argument('--rtp', type=str2bool, nargs='?', const=True, default=True,help="support for RTP") parser.add_argument('--netmode', type=str2bool, nargs='?', const=True, default=False,help="support for RTP") parser.add_argument('--jpegopt',help="jpeg options for ffmpeg",default="") parser.add_argument('--h264opt',help="h264 options for ffmpeg",default="") parser.add_argument('--mp4fragms',help="mp4 fragment millisconds",default=200,type=int) parser.add_argument('--grabrate',help="grabbing rate (Hz)",default=30,type=int) parser.add_argument("--piljpeg", type=str2bool, nargs='?', const=True, default=False,help="uses PIL for jpeg computation") parser.add_argument('--rate',type=int,default=30,help="data rate") args = parser.parse_args() hub = aiopubsub.Hub() udppublishers = dict() # setup single grabber and splitter sc = ScreenGrabber(hub,args.area,rate=args.rate) handlers = [ (r'/', MainHandler,dict(args=args,count=len(sc.parts))) ] ffmpegs = [] for i in range(0,len(sc.parts)): print ("part is",sc.parts[i]) sdpfilename = "area%d.sdp"%i q = FFmpegCompressor(hub,"area%d"%i,sdpfilename=sdpfilename,w=sc.parts[i][2],h=sc.parts[i][2],netmode=args.netmode,dojpeg=not args.piljpeg,dortp=args.rtp,h264info=args.h264opt,jpeginfo=args.jpegopt) ffmpegs.append(q) if args.piljpeg: # PIL JPEG p = PILCompressor(hub,"area%d"%i) # publis image handlers.append(("/jpeg%d" % i, JpegHandler, dict(hub=hub,name=("area%d"%i,"jpeg")))) handlers.append(("/mjpeg%d" % i, MJpegHandler, dict(hub=hub,name=("area%d"%i,"jpeg")))) if args.rtp: # start and describe rtp like in RTSP handlers.append((r"/rtp%d/([^/]+)/(\d+)" % i, RTPHandler, dict(hub=hub,name=("area%d"%i,"rtp"),udppublishers=udppublishers))) handlers.append((r"/sdp%d" % i, SDPHandler, dict(filename=sdpfilename))) print ("finalizing") # stop and list RTPs (equivalent to RTSP) handlers.append((r"/stop/([^/]+)/(\d+)", StopRTPHandler, dict(hub=hub,udppublishers=udppublishers))) handlers.append((r"/rtps", ListRTPsHandler, dict(hub=hub,udppublishers=udppublishers))) app = web.Application( handlers, debug=True ) print ("registerd",handlers) io = ioloop.IOLoop() server = HTTPServer(app) if args.http != 0: print ("listening on port",args.http) server.listen(args.http) signal.signal(signal.SIGINT, lambda x, y: IOLoop.instance().stop()) IOLoop.instance().spawn_callback(sc.grabber) IOLoop.instance().spawn_callback(lambda: [q.start() for q in ffmpegs]) print ("loop starting") IOLoop.instance().start()