add basic func to load paper_trades file
parent
26146097eb
commit
af4fb59fe8
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue