Exemplo n.º 1
0
 def handle_trade_block_response(self, header, body):
     collector = self.find_request_by_id(header['_id'])
     if collector is None:
         logger.critical('Cannot find collector(trade response) %s', header)
         return
     collector.set_pending(False)
     stream_write(collector.request_socket(), header, body, self)
Exemplo n.º 2
0
 def handle_block_request(self, sock, header, body, vendor=message.CYBOS):
     collector = self.get_available_request_collector(vendor)
     if collector is None:
         logger.critical('Cannot find collector(request) %s', header)
         return
     collector.set_request(sock, header['_id'], True)
     stream_write(collector.sock, header, body, self)
Exemplo n.º 3
0
 def handle_trade_block_request(self, sock, header, body):
     collector = self.get_available_trade_collector()
     if collector is None:
         logger.critical('Cannot find collector(trade) %s', header)
         return
     collector.set_request(sock, header['_id'], True)
     stream_write(collector.sock, header, body, self)
Exemplo n.º 4
0
    def broadcast_subscribe_data(self, code, header, body):
        if code not in self.code_subscribe_info:
            logger.error('code is not in code_subscribe_info %s', code)
            return

        for s in self.code_subscribe_info[code][1]:
            stream_write(s, header, body, self)
Exemplo n.º 5
0
 def disconnect_to_subscribe(self, code, sock, header, body):
     if code in self.code_subscribe_info:
         self.code_subscribe_info[code][1].remove(sock) 
         if len(self.code_subscribe_info[code][1]) == 0:
             collector = self.code_subscribe_info[code][0]
             collector.remove_subscribe_code(code)
             self.code_subscribe_info.pop(code, None)
             stream_write(collector.sock, header, body, self)
     else:
         logger.warning('No subscribe but try to disconnect %s', code)
Exemplo n.º 6
0
    def disconnect_to_trade_subscribe(self, sock, vendor=message.CYBOS):
        collector = self.get_trade_subscribe_collector(vendor)
        if collector is None:
            logger.error('NO TRADE collector %s', vendor)
            return
        if sock in self.trade_subscribe_sockets[vendor]:
            self.trade_subscribe_sockets[vendor].remove(sock)

            if len(self.trade_subscribe_sockets[vendor]) == 0:
                header = stream_readwriter.create_header(message.TRADE_SUBSCRIBE, message.MARKET_STOCK, message.STOP_TRADE_DATA)
                stream_write(collector.sock, header, [], self)
Exemplo n.º 7
0
    def connect_to_trade_subscribe(self, sock, header, body, vendor=message.CYBOS):
        collector = self.get_trade_subscribe_collector(vendor)
        if collector is None:
            logger.error('NO TRADE Subscribe collector %s', vendor)
            return

        if sock not in self.trade_subscribe_sockets[vendor]:
            self.trade_subscribe_sockets[vendor].append(sock)
            logger.info('ADD NEW TRADE SUBSCRIBE')
            stream_write(collector.sock, header, body, self)
        else:
            logger.warning('Sock is already connected to trade subscriber %s', vendor)
Exemplo n.º 8
0
 def _handle_trade_subscribe_disconnection(self, sock):
     for vendor in self.vendors:
         collector = self.get_trade_subscribe_collector(vendor)
         if collector is None:
             continue
         
         if sock in self.trade_subscribe_sockets[vendor]:
             self.trade_subscribe_sockets[vendor].remove(sock)
             logger.info('trade subscribe found and remove, left %d', len(self.trade_subscribe_sockets[vendor]))
             if len(self.trade_subscribe_sockets[vendor]) == 0:
                 header = stream_readwriter.create_header(message.TRADE_SUBSCRIBE, message.MARKET_STOCK, message.STOP_TRADE_DATA)
                 stream_write(collector.sock, header, [], self)
Exemplo n.º 9
0
 def _send_stop_msg(self, collector_sock, code):
     stop_methods = {message.STOCK_ALARM_CODE: message.STOP_ALARM_DATA,
                     message.BIDASK_SUFFIX: message.STOP_BIDASK_DATA,
                     message.SUBJECT_SUFFIX: message.STOP_SUBJECT_DATA,
                     message.WORLD_SUFFIX: message.STOP_WORLD_DATA,
                     message.INDEX_SUFFIX: message.STOP_INDEX_DATA,}
     processed = False
     for stop_k, stop_v in stop_methods.items():
         if code.endswith(stop_k):
             header = stream_readwriter.create_header(message.SUBSCRIBE, message.MARKET_STOCK, stop_v)
             header['code'] = code
             stream_write(collector_sock, header, [])
             processed = True
     if not processed:
         header = stream_readwriter.create_header(message.SUBSCRIBE, message.MARKET_STOCK, message.STOP_STOCK_DATA)
         header['code'] = code
         stream_write(collector_sock, header, [])
Exemplo n.º 10
0
 def connect_to_subscribe(self, code, sock, header, body):
     """
     if code == 'Z000001' or code == 'T000001':
         for c in self.get_vendor_collector(message.CYBOS):
             stream_write(c.sock, header, body, None)
         return
     """
     if code in self.code_subscribe_info:
         found = False
         for s in self.code_subscribe_info[code][1]:
             if s == sock:
                 found = True
                 break
         if not found:
             self.code_subscribe_info[code][1].append(sock)
     else:
         collector = self.get_available_subscribe_collector()
         if collector is None:
             logger.error('NO AVAILABLE Subscribe collector')
         else:
             collector.append_subscribe_code(code)
             self.code_subscribe_info[code] = (collector, [sock])
             logger.info('ADD NEW SUBSCRIBE %s', code)
             stream_write(collector.sock, header, body, self)
Exemplo n.º 11
0
 def broadcast_trade_data(self, header, body, vendor=message.CYBOS):
     for s in self.trade_subscribe_sockets[vendor]:
         stream_write(s, header, body, self)