Skip to main content

Python websocket logger for Arquant's Strategies.

Project description

arqLogger

This library is intended to be used by developers seeking to send logs generated by the strategy outside Arquants infrastructure to be analyze and process.

Installation

Use the package manager pip to install arqLogger.

pip install -U arqLogger

In the case you used it in an Arquant Strategy. You import the package directly in the strategy and you are good to go.

Usage

The library can be used to create the server and the client side of the connection.

Client

Simple Strategy

How to use arqLogger in an Arquant Strategy

from arquants import Strategy
from arquants import Order

import arqLogger

class ExampleStrategy(Strategy):

    def __init__(self):
        # Init websocket logger connection
        self.logger = arqLogger.ArquantLogger(
           url="ws://ip:port/", # URL to connect 
           strategy=self, # Reference to the strategy
           strategy_id="My_Strategy_1", # Unique ID of the strategy
           param_list=locals()) # parameter list used to run the strategy, this information is send in the init message. (local function send all the variable define in the scope)

        # Establish a connection with the server and send the initial message
        self.logger.connect()


    def next(self):
        # Example on how to log Market Data message received.
        # data_list: list of n instrument to be log
        # entry_list: list with n list (one per instrument) in which we indicate the entries we want to log
        # additional: dict with additional information
        self.logger.log_md_event(data_list=[self.data0, self.data1],
                                 entry_list=[['bid_px','bid_qty','bid_px_2','bid_qty_2'], ['bid_px','bid_qty']],
                                 additional={
                                     "other_data": 0,
                                     "another_data": "Important Info",
                                 })

        # Send buy order for instrument data0 
        order = self.buy(data=self.data0, price=3000, size=10, exectype=Order.Limit)

        # Example on how to log when we send a New Order to the market.
        # order: new order.
        # additional: dict with additional information
        self.logger.log_new_order_response(order=order,
                                           additional={
                                                "other_data": 0,
                                                "another_data": "Important Info",
                                           })


    def notify_order(self, order):
        # Example on how to log when the strategy received an Update on an order.
        self.logger.log_er_event(order=order,
                                 additional={
                                     "important_info": 555,
                                 })
        if order.status is Order.Accepted:
            # Cancelling order
            self.cancel(order)
            # Example on how to log when we cancel an order.
            self.logger.log_cancel_order_response(order=order, 
                                                  additional={
                                                        "important_info": 555,
                                                  })
        if order.status is Order.Partial:
            # Replacing order
            replaced_order = self.replace(size=order.size, price=3001, order=order)
            # Example on how to log when we replace an order.
            self.logger.log_replace_order_response(order=replaced_order, 
                                                   additional={
                                                        "important_info": 555,
                                                   })
        # Example on how to log messages related with the strategy.
        # data: dict with the data we want to send in the log
        amount = 10
        self.ws.log_strategy(data={"internal_log": "calculating new rate.", "internal_amount": amount})        

    def on_pause(self):
        # Example on how to log a pause event.
        # description: describe what the strategy do when this happend
        self.logger.log_pause_event(description="Se apreto pausa, cancelando ordenes")

    def on_error(self):
        # Example on how to log an error event.
        # description: describe what the strategy do when this happend
        self.logger.log_error_event(description="Ocurrio un error en la estrategia, cancelando ordenes")     

Server

Example on how to create a websocket server using arqLogger

Simple Logging Server

How to setup a simple websocket server that print in the stdout all message received.

import arqLogger

# Function to be call when a new message is received by the server
def on_new_log(log):
   print("Message received: {0}".format(log))


# start new Websocket Sever in localhost port 8001 and specify function to be call when new message arrived
arqLogger.start_websocket(8001, on_new_log)
Advance Logging Server

How to to create a server that logs all the messages received in a new file.

import logging
from datetime import datetime
from logging.handlers import RotatingFileHandler

import arqLogger

# create new logger
logger = logging.getLogger("Rotating Log")
logger.setLevel(logging.INFO)

# add a rotating handler
handler = RotatingFileHandler("log_file.log", maxBytes=1000000, backupCount=5)
logger.addHandler(handler)


def on_new_log(log):
    logger.info("%s - %s" % (datetime.now(), log))


# start new Websocket Sever in localhost port 8001 and specify function to be call when new message arrived
arqLogger.start_websocket(8001, on_new_log)

Author/Maintainer

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arqLogger-0.0.1b12.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

arqLogger-0.0.1b12-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file arqLogger-0.0.1b12.tar.gz.

File metadata

  • Download URL: arqLogger-0.0.1b12.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

File hashes

Hashes for arqLogger-0.0.1b12.tar.gz
Algorithm Hash digest
SHA256 b3b173689b188bf6c6cdc532aa5f45538c852462e93d54837f31f80df4c8bd9c
MD5 23e6aa163a7dfeb4d9d0afa89ff20f89
BLAKE2b-256 0e9c1a8d2f27bd84db77d5371aaa15c5fdbb3e94c8161c1e073b9b725763ed78

See more details on using hashes here.

File details

Details for the file arqLogger-0.0.1b12-py3-none-any.whl.

File metadata

  • Download URL: arqLogger-0.0.1b12-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

File hashes

Hashes for arqLogger-0.0.1b12-py3-none-any.whl
Algorithm Hash digest
SHA256 2ddc2a8e01add413c63b61d25625b04f0b7dda2517d75f57304a604f620966d6
MD5 8d7ce66eee5b8c2c09d6ae7da6b8723d
BLAKE2b-256 3d384234e05f4208fdd8d325c0b9c4a7ed8311f2d9ef60a323916fa399db4d4d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page