Format to prep for PR
parent
7142a6a7ca
commit
e5cefeb44b
|
@ -425,8 +425,8 @@ async def simulate_fills(
|
||||||
case _:
|
case _:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# iterate alcl potentially clearable book prices
|
# iterate all potentially clearable book prices
|
||||||
# in FIFO order per side.c
|
# in FIFO order per side.
|
||||||
for order_info, pred in iter_entries:
|
for order_info, pred in iter_entries:
|
||||||
(our_price, size, reqid, action) = order_info
|
(our_price, size, reqid, action) = order_info
|
||||||
|
|
||||||
|
@ -438,9 +438,7 @@ async def simulate_fills(
|
||||||
'buy': buys,
|
'buy': buys,
|
||||||
'sell': sells
|
'sell': sells
|
||||||
}[action].inverse.pop(order_info)
|
}[action].inverse.pop(order_info)
|
||||||
|
|
||||||
log.warning(f'order_info: {order_info}')
|
|
||||||
|
|
||||||
# clearing price would have filled entirely
|
# clearing price would have filled entirely
|
||||||
await client.fake_fill(
|
await client.fake_fill(
|
||||||
fqsn=sym,
|
fqsn=sym,
|
||||||
|
@ -558,14 +556,12 @@ async def trades_dialogue(
|
||||||
):
|
):
|
||||||
|
|
||||||
with open_pps(broker, 'piker-paper') as table:
|
with open_pps(broker, 'piker-paper') as table:
|
||||||
log.warning(f'pp table: {table}')
|
|
||||||
# save pps in local state
|
# save pps in local state
|
||||||
_positions.update(table.pps)
|
_positions.update(table.pps)
|
||||||
|
|
||||||
pp_msgs: list[BrokerdPosition] = []
|
pp_msgs: list[BrokerdPosition] = []
|
||||||
pos: Position
|
pos: Position
|
||||||
token: str # f'{symbol}.{self.broker}'
|
token: str # f'{symbol}.{self.broker}'
|
||||||
log.warning(f'local _positions: {_positions}')
|
|
||||||
for token, pos in _positions.items():
|
for token, pos in _positions.items():
|
||||||
pp_msgs.append(BrokerdPosition(
|
pp_msgs.append(BrokerdPosition(
|
||||||
broker=broker,
|
broker=broker,
|
||||||
|
@ -574,7 +570,6 @@ async def trades_dialogue(
|
||||||
size=pos.size,
|
size=pos.size,
|
||||||
avg_price=pos.ppu,
|
avg_price=pos.ppu,
|
||||||
))
|
))
|
||||||
log.warning(f'pp_msgs: {pp_msgs}')
|
|
||||||
# TODO: load paper positions per broker from .toml config file
|
# TODO: load paper positions per broker from .toml config file
|
||||||
# and pass as symbol to position data mapping: ``dict[str, dict]``
|
# and pass as symbol to position data mapping: ``dict[str, dict]``
|
||||||
await ctx.started((
|
await ctx.started((
|
||||||
|
@ -632,6 +627,7 @@ async def open_paperboi(
|
||||||
# (we likely don't need more then one proc for basic
|
# (we likely don't need more then one proc for basic
|
||||||
# simulated order clearing)
|
# simulated order clearing)
|
||||||
if portal is None:
|
if portal is None:
|
||||||
|
log.info('Starting new paper-engine actor')
|
||||||
portal = await tn.start_actor(
|
portal = await tn.start_actor(
|
||||||
service_name,
|
service_name,
|
||||||
enable_modules=[__name__]
|
enable_modules=[__name__]
|
||||||
|
|
|
@ -58,7 +58,7 @@ def open_trade_ledger(
|
||||||
account: str,
|
account: str,
|
||||||
) -> Generator[dict, None, None]:
|
) -> Generator[dict, None, None]:
|
||||||
'''
|
'''
|
||||||
Indempotently creat0616cbd1e and read in a trade log file from the
|
Indempotently create and read in a trade log file from the
|
||||||
``<configuration_dir>/ledgers/`` directory.
|
``<configuration_dir>/ledgers/`` directory.
|
||||||
|
|
||||||
Files are named per broker account of the form
|
Files are named per broker account of the form
|
||||||
|
@ -91,8 +91,7 @@ def open_trade_ledger(
|
||||||
# TODO: show diff output?
|
# TODO: show diff output?
|
||||||
# https://stackoverflow.com/questions/12956957/print-diff-of-python-dictionaries
|
# https://stackoverflow.com/questions/12956957/print-diff-of-python-dictionaries
|
||||||
print(f'Updating ledger for {tradesfile}:\n')
|
print(f'Updating ledger for {tradesfile}:\n')
|
||||||
ledger.update(cpy)
|
ledger.update(cpy)
|
||||||
|
|
||||||
# we write on close the mutated ledger data
|
# we write on close the mutated ledger data
|
||||||
with open(tradesfile, 'w') as cf:
|
with open(tradesfile, 'w') as cf:
|
||||||
toml.dump(ledger, cf)
|
toml.dump(ledger, cf)
|
||||||
|
@ -544,8 +543,7 @@ class PpTable(Struct):
|
||||||
) -> dict[str, Position]:
|
) -> dict[str, Position]:
|
||||||
|
|
||||||
pps = self.pps
|
pps = self.pps
|
||||||
updated: dict[str, Position] = {}
|
updated: dict[str, Position] = {}
|
||||||
|
|
||||||
# lifo update all pps from records
|
# lifo update all pps from records
|
||||||
for tid, t in trans.items():
|
for tid, t in trans.items():
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ def test_paper_trade(
|
||||||
paper_cleanup: None
|
paper_cleanup: None
|
||||||
):
|
):
|
||||||
|
|
||||||
|
cleared_price: float
|
||||||
test_exec_mode='live'
|
test_exec_mode='live'
|
||||||
test_account = 'paper'
|
test_account = 'paper'
|
||||||
test_size = 1
|
test_size = 1
|
||||||
|
@ -57,8 +58,6 @@ def test_paper_trade(
|
||||||
tuple[str, str],
|
tuple[str, str],
|
||||||
list[BrokerdPosition],
|
list[BrokerdPosition],
|
||||||
]
|
]
|
||||||
cleared_price: float
|
|
||||||
|
|
||||||
|
|
||||||
async def _async_main(
|
async def _async_main(
|
||||||
open_pikerd: AsyncContextManager,
|
open_pikerd: AsyncContextManager,
|
||||||
|
|
|
@ -9,12 +9,7 @@ import pytest
|
||||||
import trio
|
import trio
|
||||||
import tractor
|
import tractor
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
import time
|
|
||||||
from piker.log import get_logger
|
from piker.log import get_logger
|
||||||
from piker.clearing._messages import (
|
|
||||||
BrokerdFill
|
|
||||||
)
|
|
||||||
|
|
||||||
from piker._daemon import (
|
from piker._daemon import (
|
||||||
find_service,
|
find_service,
|
||||||
|
@ -34,8 +29,6 @@ from piker.clearing._client import (
|
||||||
OrderBook,
|
OrderBook,
|
||||||
)
|
)
|
||||||
|
|
||||||
log = get_logger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def test_runtime_boot(
|
def test_runtime_boot(
|
||||||
open_test_pikerd: AsyncContextManager
|
open_test_pikerd: AsyncContextManager
|
||||||
|
@ -185,6 +178,3 @@ def test_ensure_ems_in_paper_actors(
|
||||||
|
|
||||||
cancel_msg: str = '_emsd_main was remotely cancelled by its caller'
|
cancel_msg: str = '_emsd_main was remotely cancelled by its caller'
|
||||||
assert cancel_msg in exc_info.value.args[0]
|
assert cancel_msg in exc_info.value.args[0]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue