From e2e3ff3cfb6fd02260b3269caba6b013996199ac Mon Sep 17 00:00:00 2001 From: Keivan Ipchi Hagh Date: Thu, 21 Mar 2024 21:30:21 +0330 Subject: [PATCH] feat: update Athena protos and remove Athena CS --- protos/athena/athena.proto | 8 ++-- protos/athena/athena_struct.proto | 9 +++-- src/rpc/athena/client.py | 47 ------------------------ src/rpc/athena/server.py | 61 ------------------------------- 4 files changed, 9 insertions(+), 116 deletions(-) delete mode 100644 src/rpc/athena/client.py delete mode 100644 src/rpc/athena/server.py diff --git a/protos/athena/athena.proto b/protos/athena/athena.proto index c7661df..e71a96e 100644 --- a/protos/athena/athena.proto +++ b/protos/athena/athena.proto @@ -8,18 +8,18 @@ import "candlestick_struct.proto"; // GetBacktestRequest message GetBacktestRequest { // Backtest configurations. - BacktestConfig config = 1; + Configuration config = 1; // Candlesticks data. Candlestick candlesticks = 2; } // GetBacktestResponse message GetBacktestResponse { - // Backtest statistics + // Backtest statistics. Statistics statistics = 1; - // Backtest orders' history + // Backtest orders' history. repeated Order orders = 2; - // Backtest trades' history + // Backtest trades' history. repeated Trade trades = 3; } diff --git a/protos/athena/athena_struct.proto b/protos/athena/athena_struct.proto index 0b00db2..a900e88 100644 --- a/protos/athena/athena_struct.proto +++ b/protos/athena/athena_struct.proto @@ -4,12 +4,13 @@ import "google/protobuf/timestamp.proto"; package athena.v1; -// Config -message BacktestConfig { +// Configuration +// Represents the configurations for the backtest. +message Configuration { // Commission rate charged by the broker for each trade. float commission = 1; // Initial balance for trading. - float cache = 2; + float cash = 2; // Capital risk limit imposed by the broker. float capital_risk = 3; // Indicates whether to trade on open or close. @@ -34,7 +35,7 @@ message Order { // Is order contingent. bool is_contingent = 6; // Hash. - string hash = 6; + string hash = 7; } // Trade diff --git a/src/rpc/athena/client.py b/src/rpc/athena/client.py deleted file mode 100644 index 690c580..0000000 --- a/src/rpc/athena/client.py +++ /dev/null @@ -1,47 +0,0 @@ -########################################################## -# -# Copyright (C) 2023-PRESENT: Keivan Ipchi Hagh -# -# Email: keivanipchihagh@gmail.com -# GitHub: https://github.com/keivanipchihagh -# -########################################################## - -import grpc -from grpc_health.v1 import health_pb2_grpc - -# Third-party imports -from src.rpc.base_client import BaseClient -from protos.athena import athena_pb2 -from protos.athena import athena_pb2_grpc -from google.protobuf.json_format import MessageToDict - - -class AthenaClient(BaseClient): - - def __init__( - self, - host: str = 'localhost', - port: int = 50051 - ) -> 'AthenaClient': - """ - AthenaClient Constructor. - - Parameters: - - host (str): Server hostname. Defaults to `localhost`. - - port (int): Server port number. Defaults to `50051`. - """ - super().__init__(host, port) - - self.service = 'Athena' - self.channel = grpc.insecure_channel(self.target) - - # Stubs - self.stub = athena_pb2_grpc.AthenaStub(self.channel) - self.health_stub = health_pb2_grpc.HealthStub(self.channel) # Healthcheck - - - def GetBacktest(self) -> dict: - request = athena_pb2.GetBacktestRequest() # Create request - response = self.stub.GetBacktest(request) # Get response - return MessageToDict(response) # Return message as dict diff --git a/src/rpc/athena/server.py b/src/rpc/athena/server.py deleted file mode 100644 index 65b90a2..0000000 --- a/src/rpc/athena/server.py +++ /dev/null @@ -1,61 +0,0 @@ -########################################################## -# -# Copyright (C) 2023-PRESENT: Keivan Ipchi Hagh -# -# Email: keivanipchihagh@gmail.com -# GitHub: https://github.com/keivanipchihagh -# -########################################################## - -import grpc - -# Third-party imports -from protos.athena import athena_pb2 -from protos.athena import athena_pb2_grpc -from src.rpc.base_server import BaseServer - - -class GetBacktestService(athena_pb2_grpc.AthenaServicer): - - def GetBacktest( - self, - request: athena_pb2.GetBacktestRequest, - context: grpc.ServicerContext, - ) -> athena_pb2.GetBacktestResponse: - """ - Executes a backtest based on the provided request. - - Parameters: - - request (athena_pb2.GetBacktestRequest): The backtest request. - - context (grpc.ServicerContext): The gRPC context. - - Returns: - - (athena_pb2.GetBacktestResponse): The backtest response. - """ - response = athena_pb2.GetBacktestResponse() - return response - - -class AthenaServer(BaseServer): - - def __init__( - self, - host: str = 'localhost', - port: int = 50051, - n_workers: int = 1, - healthcheck_n_workers: int = 1, - ) -> 'AthenaServer': - """ - AthenaServer Constructor. - - Parameters: - - host (str): Server hostname. Defaults to `localhost`. - - port (int): Server port number. Defaults to `50051`. - - n_workers (int): Number of threads. Defaults to `1`. - - healthcheck_n_workers (int): Number of threads for healthchec. Defaults to `1`. - """ - super().__init__(host, port, n_workers, healthcheck_n_workers) - - # Register GetBacktest service - athena_pb2_grpc.add_AthenaServicer_to_server(GetBacktestService(), self.server) - self.set_service_to_serving("Athena.GetBacktest")