From af4fb59fe856f3058a8f5ac22fb03170d5b9f103 Mon Sep 17 00:00:00 2001 From: algorandpa Date: Fri, 13 Jan 2023 01:14:47 +0000 Subject: [PATCH] add basic func to load paper_trades file --- piker/clearing/_paper_engine.py | 16 +++++++++++++++- piker/config.py | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/piker/clearing/_paper_engine.py b/piker/clearing/_paper_engine.py index 33ca5761..4f5cfee8 100644 --- a/piker/clearing/_paper_engine.py +++ b/piker/clearing/_paper_engine.py @@ -30,11 +30,12 @@ from typing import ( Callable, ) import uuid - +import os.path from bidict import bidict import pendulum import trio import tractor +import logging from .. import data from ..data._source import Symbol @@ -56,6 +57,7 @@ from ._messages import ( BrokerdError, ) +from ..config import load log = get_logger(__name__) @@ -84,6 +86,17 @@ class PaperBoi(Struct): last_ask: tuple[float, float] = (float('inf'), 0) # price, size last_bid: tuple[float, float] = (0, 0) + + def record_paper_trade(self): + try: + #create paper trades record + + print('RECORDING PAPER TRADE') + config, path = load('paper_trades') + except Exception as Arguement: + logging.exception('ERROR RECORDING PAPER TRADE') + pass + async def submit_limit( self, oid: str, # XXX: see return value @@ -271,6 +284,7 @@ class PaperBoi(Struct): dt=pendulum.from_timestamp(fill_time_s), bsuid=key, ) + self.record_paper_trade() pp.add_clear(t) pp_msg = BrokerdPosition( diff --git a/piker/config.py b/piker/config.py index cb250386..59532eac 100644 --- a/piker/config.py +++ b/piker/config.py @@ -115,6 +115,7 @@ _conf_names: set[str] = { 'pps', 'trades', 'watchlists', + 'paper_trades' } _watchlists_data_path = os.path.join(_config_dir, 'watchlists.json') @@ -212,6 +213,10 @@ def load( # if one exists. if os.path.isfile(template): shutil.copyfile(template, path) + else: + # create an empty file + with open(path, 'x'): + pass else: with open(path, 'r'): pass # touch it