当前位置: 首页>>代码示例>>Python>>正文


Python Logger.info方法代码示例

本文整理汇总了Python中befh.util.Logger.info方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.info方法的具体用法?Python Logger.info怎么用?Python Logger.info使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在befh.util.Logger的用法示例。


在下文中一共展示了Logger.info方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_message_handler

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
    def on_message_handler(self, instmt, messages):
        """
        Incoming message handler
        :param instmt: Instrument
        :param message: Message
        """
        for message in messages:
            keys = message.keys()
            if 'channel' in keys:
                if 'data' in keys:
                    if message['channel'] == instmt.get_order_book_channel_id():
                        data = message['data']
                        instmt.set_prev_l2_depth(instmt.get_l2_depth().copy())
                        self.api_socket.parse_l2_depth(instmt, data)

                        # Insert only if the first 5 levels are different
                        if instmt.get_l2_depth().is_diff(instmt.get_prev_l2_depth()):
                            instmt.incr_order_book_id()
                            self.insert_order_book(instmt)

                    elif message['channel'] == instmt.get_trades_channel_id():
                        for trade_raw in message['data']:
                            trade = self.api_socket.parse_trade(instmt, trade_raw)
                            if trade.trade_id != instmt.get_exch_trade_id():
                                instmt.incr_trade_id()
                                instmt.set_exch_trade_id(trade.trade_id)
                                self.insert_trade(instmt, trade)

                elif 'success' in keys:
                    Logger.info(self.__class__.__name__, "Subscription to channel %s is %s" \
                        % (message['channel'], message['success']))
            else:
                Logger.info(self.__class__.__name__, ' - ' + json.dumps(message))
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:35,代码来源:exch_okcoin.py

示例2: insert

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
    def insert(self, table, columns, types, values, primary_key_index=[], is_orreplace=False, is_commit=True):
        """
        Insert into the table
        :param table: Table name
        :param columns: Column array
        :param types: Type array
        :param values: Value array
        :param primary_key_index: An array of indices of primary keys in columns,
                          e.g. [0] means the first column is the primary key
        :param is_orreplace: Indicate if the query is "INSERT OR REPLACE"
        """
        if len(columns) != len(values):
            return False

        column_names = ','.join(columns)
        value_string = ','.join([SqlClient.convert_str(e) for e in values])
        if is_orreplace:
            sql = "%s %s (%s) values (%s)" % (self.replace_keyword(), table, column_names, value_string)
        else:
            sql = "insert into %s (%s) values (%s)" % (table, column_names, value_string)

        self.lock.acquire()
        try:
            self.execute(sql)
            if is_commit:
                self.commit()
        except Exception as e:
            Logger.info(self.__class__.__name__, "SQL error: %s\nSQL: %s" % (e, sql))
        self.lock.release()
        return True
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:32,代码来源:sql_client.py

示例3: on_open_handler

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
    def on_open_handler(self, instmt, ws):
        """
        Socket on open handler
        :param instmt: Instrument
        :param ws: Web socket
        """
        Logger.info(self.__class__.__name__, "Instrument %s is subscribed in channel %s" % \
                  (instmt.get_instmt_code(), instmt.get_exchange_name()))
        if not instmt.get_subscribed():
            instmt_code_split = instmt.get_instmt_code().split('_')
            if len(instmt_code_split) == 3:
                # Future instruments
                instmt.set_order_book_channel_id("ok_sub_%s_%s_depth_%s_20" % \
                                                 (instmt_code_split[0],
                                                  instmt_code_split[1],
                                                  instmt_code_split[2]))
                instmt.set_trades_channel_id("ok_sub_%s_%s_trade_%s" % \
                                               (instmt_code_split[0],
                                                instmt_code_split[1],
                                                instmt_code_split[2]))
            else:
                # Spot instruments
                instmt.set_order_book_channel_id("ok_sub_%s_depth_20" % instmt.get_instmt_code())
                instmt.set_trades_channel_id("ok_sub_%s_trades" % instmt.get_instmt_code())

            ws.send(self.api_socket.get_order_book_subscription_string(instmt))
            ws.send(self.api_socket.get_trades_subscription_string(instmt))
            instmt.set_subscribed(True)
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:30,代码来源:exch_okcoin.py

示例4: __on_close

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
 def __on_close(self, ws):
     Logger.info(self.__class__.__name__, "Socket <%s> is closed." % self.id)
     self._connecting = False
     self._connected = False
     if len(self.on_close_handlers) > 0:
         for handler in self.on_close_handlers:
             handler(ws)
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:9,代码来源:ws_api_socket.py

示例5: on_message_handler

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
    def on_message_handler(self, instmt, message):
        """
        Incoming message handler
        :param instmt: Instrument
        :param message: Message
        """
        if isinstance(message, dict):
            keys = message.keys()
            if 'event' in keys and message['event'] == 'info' and  'version' in keys:
                Logger.info(self.__class__.__name__, "Bitfinex version: %s" % message['version'])
            elif 'event' in keys and message['event'] == 'subscribed':
                if instmt.get_instmt_code() == message['pair']:
                    if message['channel'] == 'book':
                        instmt.set_order_book_channel_id(message['chanId'])
                    elif message['channel'] == 'trades':
                        instmt.set_trades_channel_id(message['chanId'])
                    else:
                        raise Exception("Unknown channel %s : <%s>" % (message['channel'], message))

                    Logger.info(self.__class__.__name__, 'Subscription: %s, pair: %s, channel Id: %s' % \
                              (message['channel'], instmt.get_instmt_code(), message['chanId']))
        elif isinstance(message, list):
            if message[0] == instmt.get_order_book_channel_id():
                if isinstance(message[1], list):
                    self.api_socket.parse_l2_depth(instmt, message[1])
                elif len(message) != 2:
                    instmt.set_prev_l2_depth(instmt.get_l2_depth().copy())
                    self.api_socket.parse_l2_depth(instmt, message)
                else:
                    return

                if instmt.get_l2_depth().is_diff(instmt.get_prev_l2_depth()):
                    instmt.incr_order_book_id()
                    self.insert_order_book(instmt)

            elif message[0] == instmt.get_trades_channel_id():
                # No recovery trade
                
                # if isinstance(message[1], list):
                #     raw_trades = message[1]
                #     raw_trades.sort(key=lambda x:x[0])
                #     for raw in raw_trades:
                #         trade = self.api_socket.parse_trade(instmt, raw)
                #         try:
                #             if int(trade.trade_id) > int(instmt.get_exch_trade_id()):
                #                 instmt.incr_trade_id()
                #                 instmt.set_exch_trade_id(trade.trade_id)
                #                 self.insert_trade(instmt, trade)
                #         except Exception as e:
                #             Logger.info('test', "trade.trade_id(%s):%s" % (type(trade.trade_id), trade.trade_id))
                #             Logger.info('test', "instmt.get_exch_trade_id()(%s):%s" % (type(instmt.get_exch_trade_id()), instmt.get_exch_trade_id()))
                #             raise e                            

                if message[1] == 'tu':
                    trade = self.api_socket.parse_trade(instmt, message[3:])
                    if int(trade.trade_id) > int(instmt.get_exch_trade_id()):
                        instmt.incr_trade_id()
                        instmt.set_exch_trade_id(trade.trade_id)
                        self.insert_trade(instmt, trade)
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:61,代码来源:exch_bitfinex.py

示例6: create

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
    def create(self, table, columns, types, primary_key_index=[], is_ifnotexists=True):
        """
        Create table in the database.
        Caveat - Assign the first few column as the keys!!!
        :param table: Table name
        :param columns: Column array
        :param types: Type array
        :param is_ifnotexists: Create table if not exists keyword
        """
        if len(columns) != len(types):
            raise Exception("Incorrect create statement. Number of columns and that of types are different.\n%s\n%s" % \
                (columns, types))

        if is_ifnotexists:
            ret = self.conn("\\v")
            if ret is not None:
                for t in ret:
                    if table == self.decode_qtypes(t):
                        Logger.info(self.__class__.__name__, "Table %s has been created." % table)
                        return True
                        
            Logger.info(self.__class__.__name__, "Table %s is going to be created." % table)
            
        c = columns[:]
        
        for i in range(0, len(types)):
            t = self.convert_type(types[i])
            if t is str:
                if columns[i].find('date_time') > -1:
                    c[i] += ":`timestamp$()"
                else:
                    c[i] += ":`symbol$()"
            elif t is float:
                c[i] += ":`float$()"
            elif t is int:
                c[i] += ":`long$()"
        
        keys = []
        for i in primary_key_index:
            keys.append(c[i])
        
        for i in sorted(primary_key_index, reverse=True):
            del c[i]
        
        if len(keys) > 0:
            command = '%s:([%s] %s)' % (table, '; '.join(keys), '; '.join(c))
        else:
            command = '%s:(%s)' % (table, '; '.join(c))

        self.lock.acquire()
        try:
            self.conn.sync(command)
        except Exception as e:
            Logger.error(self.__class__.__name__, "Error in creat statement(%s).\n%s" % (command, e))
        finally:
            self.lock.release()
        
        return True
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:60,代码来源:kdbplus_client.py

示例7: connect

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
 def connect(self, **kwargs):
     """
     Connect
     :param path: sqlite file to connect
     """
     addr = kwargs['addr']
     Logger.info(self.__class__.__name__, 'Zmq client is connecting to %s' % addr)
     self.conn.bind(addr)
     return self.conn is not None
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:11,代码来源:zmq_client.py

示例8: on_close_handler

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
 def on_close_handler(self, instmt, ws):
     """
     Socket on close handler
     :param instmt: Instrument
     :param ws: Web socket
     """
     Logger.info(self.__class__.__name__, "Instrument %s is subscribed in channel %s" % \
               (instmt.get_instmt_code(), instmt.get_exchange_name()))
     instmt.set_subscribed(False)
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:11,代码来源:exch_ws_template.py

示例9: on_open_handler

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
 def on_open_handler(self, instmt, ws):
     """
     Socket on open handler
     :param instmt: Instrument
     :param ws: Web socket
     """
     Logger.info(self.__class__.__name__, "Instrument %s is subscribed in channel %s" % \
               (instmt.get_instmt_code(), instmt.get_exchange_name()))
     if not instmt.get_subscribed():
         ws.send(self.api_socket.get_trades_subscription_string(instmt))
         instmt.set_subscribed(True)
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:13,代码来源:exch_gdax.py

示例10: on_message_handler

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
 def on_message_handler(self, instmt, message):
     """
     Incoming message handler
     :param instmt: Instrument
     :param message: Message
     """
     keys = message.keys()
     if 'info' in keys:
         Logger.info(self.__class__.__name__, message['info'])
     elif 'subscribe' in keys:
         Logger.info(self.__class__.__name__, 'Subscription of %s is %s' % \
                     (message['request']['args'], \
                      'successful' if message['success'] else 'failed'))
     elif 'table' in keys:
         if message['table'] == 'trade':
             for trade_raw in message['data']:
                 if trade_raw["symbol"] == instmt.get_instmt_code():
                     # Filter out the initial subscriptions
                     trade = self.api_socket.parse_trade(instmt, trade_raw)
                     if trade.trade_id != instmt.get_exch_trade_id():
                         instmt.incr_trade_id()
                         instmt.set_exch_trade_id(trade.trade_id)
                         self.insert_trade(instmt, trade)
         elif message['table'] == 'orderBook10':
             for data in message['data']:
                 if data["symbol"] == instmt.get_instmt_code():
                     instmt.set_prev_l2_depth(instmt.get_l2_depth().copy())
                     self.api_socket.parse_l2_depth(instmt, data)
                     if instmt.get_l2_depth().is_diff(instmt.get_prev_l2_depth()):
                         instmt.incr_order_book_id()
                         self.insert_order_book(instmt)
         else:
             Logger.info(self.__class__.__name__, json.dumps(message,indent=2))
     else:
         Logger.error(self.__class__.__name__, "Unrecognised message:\n" + json.dumps(message))
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:37,代码来源:exch_ws_template.py

示例11: connect

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
    def connect(self, url,
                on_message_handler=None,
                on_open_handler=None,
                on_close_handler=None,
                on_error_handler=None,
                reconnect_interval=10):
        """
        :param url: Url link
        :param on_message_handler: Message handler which take the message as
                           the first argument
        :param on_open_handler: Socket open handler which take the socket as
                           the first argument
        :param on_close_handler: Socket close handler which take the socket as
                           the first argument
        :param on_error_handler: Socket error handler which take the socket as
                           the first argument and the error as the second
                           argument
        :param reconnect_interval: The time interval for reconnection
        """
        Logger.info(self.__class__.__name__, "Connecting to socket <%s>..." % self.id)
        if on_message_handler is not None:
            self.on_message_handlers.append(on_message_handler)
        if on_open_handler is not None:
            self.on_open_handlers.append(on_open_handler)
        if on_close_handler is not None:
            self.on_close_handlers.append(on_close_handler)
        if on_error_handler is not None:
            self.on_error_handlers.append(on_error_handler)

        if not self._connecting and not self._connected:
            self._connecting = True
            self.ws = websocket.WebSocketApp(url,
                                             on_message=self.__on_message,
                                             on_close=self.__on_close,
                                             on_open=self.__on_open,
                                             on_error=self.__on_error)
            self.wst = threading.Thread(target=lambda: self.__start(reconnect_interval=reconnect_interval))
            self.wst.start()

        return self.wst
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:42,代码来源:ws_api_socket.py

示例12: create

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
    def create(self, table, columns, types, is_ifnotexists=True):
        """
        Create table in the database
        :param table: Table name
        :param columns: Column array
        :param types: Type array
        :param is_ifnotexists: Create table if not exists keyword
        """
        file_path = os.path.join(self.file_directory, table + ".csv")
        print(file_path)
        columns = [e.split(' ')[0] for e in columns]
        if len(columns) != len(types):
            return False

        self.lock.acquire()
        if os.path.isfile(file_path):
            Logger.info(self.__class__.__name__, "File (%s) has been created already." % file_path)
        else:
            with open(file_path, 'w+') as csvfile:
                csvfile.write(','.join(["\"" + e + "\"" for e in columns])+'\n')

        self.lock.release()
        return True
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:25,代码来源:file_client.py

示例13: connect

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
 def connect(self, **kwargs):
     """
     Connect
     :param path: sqlite file to connect
     """
     host = kwargs['host']
     port = kwargs['port']
     Logger.info(self.__class__.__name__, 'Kdb+ database client is connecting to %s:%d' % (host, port))
     self.conn = qconnection.QConnection(host=host, port=port)
     self.conn.open()
     if self.conn.is_connected():
         Logger.info(self.__class__.__name__, 'Connection to %s:%d is successful.' % (host, port))    
     else:
         Logger.info(self.__class__.__name__, 'Connection to %s:%d is failed.' % (host, port))    
         
     return self.conn.is_connected()
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:18,代码来源:kdbplus_client.py

示例14: Exception

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
            raise Exception("Unknown type (%s) in kdb client select statement.\n%s" % (type(select_ret), select_ret))


        return ret

    def delete(self, table, condition='1==1'):
        """
        Delete rows from the table
        :param table: Table name
        :param condition: Where condition
        """
        if condition == '1==1':
            statement = 'delete from `%s' % (table)
        else:
            statement = 'delete from `%s where %s' % (table, self.parse_condition(condition))
        self.conn.sync(statement)
        return True

if __name__ == '__main__':
    Logger.init_log()
    db_client = KdbPlusClient()
    db_client.connect(host='localhost', port=5000)
    db_client.create('test', ['c1', 'c2', 'c3', 'c4'], ['varchar(20)', 'int', 'decimal(8, 20)', 'int'], [0], False)
    db_client.insert('test', ['c1', 'c2', 'c3', 'c4'], ['abc', 1, 1.1, 5])
    db_client.insert('test', ['c1', 'c2', 'c3', 'c4'], ['efg', 2, 2.2, 6])
    db_client.insert('test', ['c1', 'c2', 'c3', 'c4'], ['hij', 3, 3.3, 7])
    # Logger.info('test', db_client.select('test', columns=['*']))
    Logger.info('test', db_client.select('test', columns=['c2', 'c3'], condition='c1 >= "abc" and c2 > 1'))
    # Logger.info('test', db_client.select('test', columns=['*'], orderby='c1 desc', limit=1))
    db_client.delete('test', 'c1="abc"')
    
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:32,代码来源:kdbplus_client.py

示例15: main

# 需要导入模块: from befh.util import Logger [as 别名]
# 或者: from befh.util.Logger import info [as 别名]
def main():
    parser = argparse.ArgumentParser(description='Bitcoin exchange market data feed handler.')
    parser.add_argument('-instmts', action='store', help='Instrument subscription file.', default='subscriptions.ini')
    parser.add_argument('-exchtime', action='store_true', help='Use exchange timestamp.')
    parser.add_argument('-kdb', action='store_true', help='Use Kdb+ as database.')
    parser.add_argument('-csv', action='store_true', help='Use csv file as database.')
    parser.add_argument('-sqlite', action='store_true', help='Use SQLite database.')
    parser.add_argument('-mysql', action='store_true', help='Use MySQL.')
    parser.add_argument('-zmq', action='store_true', help='Use zmq publisher.')
    parser.add_argument('-mysqldest', action='store', dest='mysqldest',
                        help='MySQL destination. Formatted as <name:[email protected]:port>',
                        default='')
    parser.add_argument('-mysqlschema', action='store', dest='mysqlschema',
                        help='MySQL schema.',
                        default='')
    parser.add_argument('-kdbdest', action='store', dest='kdbdest',
                        help='Kdb+ destination. Formatted as <host:port>',
                        default='')
    parser.add_argument('-zmqdest', action='store', dest='zmqdest',
                        help='Zmq destination. For example \"tcp://127.0.0.1:3306\"',
                        default='')
    parser.add_argument('-sqlitepath', action='store', dest='sqlitepath',
                        help='SQLite database path',
                        default='')
    parser.add_argument('-csvpath', action='store', dest='csvpath',
                        help='Csv file path',
                        default='')
    parser.add_argument('-output', action='store', dest='output',
                        help='Verbose output file path')
    args = parser.parse_args()

    Logger.init_log(args.output)

    db_clients = []
    is_database_defined = False
    if args.sqlite:
        db_client = SqliteClient()
        db_client.connect(path=args.sqlitepath)
        db_clients.append(db_client)
        is_database_defined = True
    if args.mysql:
        db_client = MysqlClient()
        mysqldest = args.mysqldest
        logon_credential = mysqldest.split('@')[0]
        connection = mysqldest.split('@')[1]
        db_client.connect(host=connection.split(':')[0],
                          port=int(connection.split(':')[1]),
                          user=logon_credential.split(':')[0],
                          pwd=logon_credential.split(':')[1],
                          schema=args.mysqlschema)
        db_clients.append(db_client)
        is_database_defined = True
    if args.csv:
        if args.csvpath != '':
            db_client = FileClient(dir=args.csvpath)
        else:
            db_client = FileClient()
        db_clients.append(db_client)
        is_database_defined = True
    if args.kdb:
        db_client = KdbPlusClient()
        db_client.connect(host=args.kdbdest.split(':')[0], port=int(args.kdbdest.split(':')[1]))
        db_clients.append(db_client)
        is_database_defined = True
    if args.zmq:
        db_client = ZmqClient()
        db_client.connect(addr=args.zmqdest)
        db_clients.append(db_client)
        is_database_defined = True

    if not is_database_defined:
        print('Error: Please define which database is used.')
        parser.print_help()
        sys.exit(1)

    # Subscription instruments
    if args.instmts is None or len(args.instmts) == 0:
        print('Error: Please define the instrument subscription list. You can refer to subscriptions.ini.')
        parser.print_help()
        sys.exit(1)
        
    # Use exchange timestamp rather than local timestamp
    if args.exchtime:
        ExchangeGateway.is_local_timestamp = False

    subscription_instmts = SubscriptionManager(args.instmts).get_subscriptions()
    ExchangeGateway.init_snapshot_table(db_clients)

    Logger.info('[main]', 'Subscription file = %s' % args.instmts)
    log_str = 'Exchange/Instrument/InstrumentCode:\n'
    for instmt in subscription_instmts:
        log_str += '%s/%s/%s\n' % (instmt.exchange_name, instmt.instmt_name, instmt.instmt_code)
    Logger.info('[main]', log_str)
    
    exch_gws = []
    exch_gws.append(ExchGwBtccSpot(db_clients))
    exch_gws.append(ExchGwBtccFuture(db_clients))
    exch_gws.append(ExchGwBitmex(db_clients))
    exch_gws.append(ExchGwBitfinex(db_clients))
    exch_gws.append(ExchGwOkCoin(db_clients))
#.........这里部分代码省略.........
开发者ID:MarekJavurek,项目名称:BitcoinExchangeFH,代码行数:103,代码来源:bitcoinexchangefh.py


注:本文中的befh.util.Logger.info方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。