max_pain: add piker logging, tweak var names, notes and todos
parent
bc72e3d206
commit
d655e81290
|
@ -2,22 +2,29 @@
|
||||||
from decimal import (
|
from decimal import (
|
||||||
Decimal,
|
Decimal,
|
||||||
)
|
)
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import polars as pl
|
# import polars as pl
|
||||||
import trio
|
import trio
|
||||||
import tractor
|
import tractor
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pprint import pformat
|
# from pprint import pformat
|
||||||
from piker.brokers.deribit.api import (
|
from piker.brokers.deribit.api import (
|
||||||
get_client,
|
get_client,
|
||||||
maybe_open_oi_feed,
|
maybe_open_oi_feed,
|
||||||
)
|
)
|
||||||
from piker.storage import open_storage_client, StorageClient
|
from piker.storage import open_storage_client, StorageClient
|
||||||
|
from piker.log import get_logger
|
||||||
import sys
|
import sys
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from PyQt6 import QtCore
|
from PyQt6 import QtCore
|
||||||
from pyqtgraph import ScatterPlotItem, InfiniteLine
|
from pyqtgraph import ScatterPlotItem, InfiniteLine
|
||||||
from PyQt6.QtWidgets import QApplication
|
from PyQt6.QtWidgets import QApplication
|
||||||
|
from cryptofeed.symbols import Symbol
|
||||||
|
|
||||||
|
|
||||||
|
log = get_logger(__name__)
|
||||||
# XXX, use 2 newlines between top level LOC (even between these
|
# XXX, use 2 newlines between top level LOC (even between these
|
||||||
# imports and the next function line ;)
|
# imports and the next function line ;)
|
||||||
|
|
||||||
|
@ -192,10 +199,13 @@ async def max_pain_daemon(
|
||||||
),
|
),
|
||||||
], dtype=dtype)
|
], dtype=dtype)
|
||||||
|
|
||||||
path = await client.write_oi(
|
path: Path = await client.write_oi(
|
||||||
col_sym_key,
|
col_sym_key,
|
||||||
data,
|
data,
|
||||||
)
|
)
|
||||||
|
# TODO, use std logging like this throughout for status
|
||||||
|
# emissions on console!
|
||||||
|
log.info(f'Wrote OI history to {path}')
|
||||||
|
|
||||||
def get_max_pain(
|
def get_max_pain(
|
||||||
oi_by_strikes: dict[str, dict[str, Decimal]]
|
oi_by_strikes: dict[str, dict[str, Decimal]]
|
||||||
|
@ -258,7 +268,7 @@ async def max_pain_daemon(
|
||||||
# hardcoded to something, sorry.)
|
# hardcoded to something, sorry.)
|
||||||
timestamp = msg[1]['timestamp']
|
timestamp = msg[1]['timestamp']
|
||||||
max_pain = get_max_pain(oi_by_strikes)
|
max_pain = get_max_pain(oi_by_strikes)
|
||||||
intrinsic_values = get_total_intrinsic_values(oi_by_strikes)
|
# intrinsic_values = get_total_intrinsic_values(oi_by_strikes)
|
||||||
|
|
||||||
# graph here
|
# graph here
|
||||||
plot_graph(oi_by_strikes, plot)
|
plot_graph(oi_by_strikes, plot)
|
||||||
|
@ -298,14 +308,27 @@ async def max_pain_daemon(
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
|
||||||
async with tractor.open_nursery() as n:
|
async with tractor.open_nursery(
|
||||||
|
debug_mode=True,
|
||||||
|
loglevel='info',
|
||||||
|
) as an:
|
||||||
|
from tractor import log
|
||||||
|
log.get_console_log(level='info')
|
||||||
|
|
||||||
p: tractor.Portal = await n.start_actor(
|
ptl: tractor.Portal = await an.start_actor(
|
||||||
'max_pain_daemon',
|
'max_pain_daemon',
|
||||||
enable_modules=[__name__],
|
enable_modules=[__name__],
|
||||||
infect_asyncio=True,
|
infect_asyncio=True,
|
||||||
|
# ^TODO, we can actually run this in the root-actor now
|
||||||
|
# if needed as per 2nd "section" in,
|
||||||
|
# https://pikers.dev/goodboy/tractor/pulls/2
|
||||||
|
#
|
||||||
|
# NOTE, will first require us porting to modern
|
||||||
|
# `tractor:main` though ofc!
|
||||||
|
|
||||||
)
|
)
|
||||||
await p.run(max_pain_daemon)
|
await ptl.run(max_pain_daemon)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
trio.run(main)
|
trio.run(main)
|
||||||
|
|
Loading…
Reference in New Issue