add basic func to load paper_trades file
parent
26146097eb
commit
af4fb59fe8
|
@ -30,11 +30,12 @@ from typing import (
|
||||||
Callable,
|
Callable,
|
||||||
)
|
)
|
||||||
import uuid
|
import uuid
|
||||||
|
import os.path
|
||||||
from bidict import bidict
|
from bidict import bidict
|
||||||
import pendulum
|
import pendulum
|
||||||
import trio
|
import trio
|
||||||
import tractor
|
import tractor
|
||||||
|
import logging
|
||||||
|
|
||||||
from .. import data
|
from .. import data
|
||||||
from ..data._source import Symbol
|
from ..data._source import Symbol
|
||||||
|
@ -56,6 +57,7 @@ from ._messages import (
|
||||||
BrokerdError,
|
BrokerdError,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from ..config import load
|
||||||
|
|
||||||
log = get_logger(__name__)
|
log = get_logger(__name__)
|
||||||
|
|
||||||
|
@ -84,6 +86,17 @@ class PaperBoi(Struct):
|
||||||
last_ask: tuple[float, float] = (float('inf'), 0) # price, size
|
last_ask: tuple[float, float] = (float('inf'), 0) # price, size
|
||||||
last_bid: tuple[float, float] = (0, 0)
|
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(
|
async def submit_limit(
|
||||||
self,
|
self,
|
||||||
oid: str, # XXX: see return value
|
oid: str, # XXX: see return value
|
||||||
|
@ -271,6 +284,7 @@ class PaperBoi(Struct):
|
||||||
dt=pendulum.from_timestamp(fill_time_s),
|
dt=pendulum.from_timestamp(fill_time_s),
|
||||||
bsuid=key,
|
bsuid=key,
|
||||||
)
|
)
|
||||||
|
self.record_paper_trade()
|
||||||
pp.add_clear(t)
|
pp.add_clear(t)
|
||||||
|
|
||||||
pp_msg = BrokerdPosition(
|
pp_msg = BrokerdPosition(
|
||||||
|
|
|
@ -115,6 +115,7 @@ _conf_names: set[str] = {
|
||||||
'pps',
|
'pps',
|
||||||
'trades',
|
'trades',
|
||||||
'watchlists',
|
'watchlists',
|
||||||
|
'paper_trades'
|
||||||
}
|
}
|
||||||
|
|
||||||
_watchlists_data_path = os.path.join(_config_dir, 'watchlists.json')
|
_watchlists_data_path = os.path.join(_config_dir, 'watchlists.json')
|
||||||
|
@ -212,6 +213,10 @@ def load(
|
||||||
# if one exists.
|
# if one exists.
|
||||||
if os.path.isfile(template):
|
if os.path.isfile(template):
|
||||||
shutil.copyfile(template, path)
|
shutil.copyfile(template, path)
|
||||||
|
else:
|
||||||
|
# create an empty file
|
||||||
|
with open(path, 'x'):
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
with open(path, 'r'):
|
with open(path, 'r'):
|
||||||
pass # touch it
|
pass # touch it
|
||||||
|
|
Loading…
Reference in New Issue