Compare commits
No commits in common. "0f3754ca56a9bd33e6a32ddf8563efea3d2ab16b" and "17aebf44a92a658bd86d03b7dd96e11018316c2f" have entirely different histories.
0f3754ca56
...
17aebf44a9
|
|
@ -2,29 +2,22 @@
|
||||||
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 ;)
|
||||||
|
|
||||||
|
|
@ -54,13 +47,9 @@ async def max_pain_daemon(
|
||||||
kind=kind
|
kind=kind
|
||||||
)
|
)
|
||||||
|
|
||||||
log.info(
|
print(f'Available expiration dates for {currency}-{kind}:')
|
||||||
f'Available expiries for {currency!r}-{kind}:\n'
|
print(f'{expiry_dates}')
|
||||||
f'{expiry_dates}\n'
|
expiry_date = input('Please enter a valid expiration date: ').upper()
|
||||||
)
|
|
||||||
expiry_date: str = input(
|
|
||||||
'Please enter a valid expiration date: '
|
|
||||||
).upper()
|
|
||||||
print('Starting little daemon...')
|
print('Starting little daemon...')
|
||||||
|
|
||||||
# maybe move this type annot down to the assignment line?
|
# maybe move this type annot down to the assignment line?
|
||||||
|
|
@ -203,13 +192,10 @@ async def max_pain_daemon(
|
||||||
),
|
),
|
||||||
], dtype=dtype)
|
], dtype=dtype)
|
||||||
|
|
||||||
path: Path = await client.write_oi(
|
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]]
|
||||||
|
|
@ -272,7 +258,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)
|
||||||
|
|
@ -312,27 +298,14 @@ async def max_pain_daemon(
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
|
||||||
async with tractor.open_nursery(
|
async with tractor.open_nursery() as n:
|
||||||
debug_mode=True,
|
|
||||||
loglevel='info',
|
|
||||||
) as an:
|
|
||||||
from tractor import log
|
|
||||||
log.get_console_log(level='info')
|
|
||||||
|
|
||||||
ptl: tractor.Portal = await an.start_actor(
|
p: tractor.Portal = await n.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 ptl.run(max_pain_daemon)
|
await p.run(max_pain_daemon)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
trio.run(main)
|
trio.run(main)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
# piker: trading gear for hackers
|
# piker: trading gear for hackers
|
||||||
# Copyright (C) Guillermo Rodriguez (in stewardship for pikers)
|
# Copyright (C) Guillermo Rodriguez (in stewardship for piker0)
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
|
@ -80,6 +80,7 @@ from piker.accounting import (
|
||||||
from piker.data import (
|
from piker.data import (
|
||||||
def_iohlcv_fields,
|
def_iohlcv_fields,
|
||||||
match_from_pairs,
|
match_from_pairs,
|
||||||
|
# Struct,
|
||||||
)
|
)
|
||||||
from piker.data._web_bs import (
|
from piker.data._web_bs import (
|
||||||
open_jsonrpc_session
|
open_jsonrpc_session
|
||||||
|
|
@ -194,11 +195,7 @@ def cb_sym_to_deribit_inst(sym: Symbol) -> str:
|
||||||
|
|
||||||
|
|
||||||
def get_values_from_cb_normalized_date(expiry_date: str) -> str:
|
def get_values_from_cb_normalized_date(expiry_date: str) -> str:
|
||||||
'''
|
# deribit specific
|
||||||
Convert the `cryptofeed` (expiry) datetime format to our own,
|
|
||||||
a simple 3 token `str: f'{day}{month}{year}'.
|
|
||||||
|
|
||||||
'''
|
|
||||||
cb_norm = [
|
cb_norm = [
|
||||||
'F', 'G', 'H', 'J',
|
'F', 'G', 'H', 'J',
|
||||||
'K', 'M', 'N', 'Q',
|
'K', 'M', 'N', 'Q',
|
||||||
|
|
@ -331,6 +328,7 @@ class Client:
|
||||||
'''
|
'''
|
||||||
Return the set of currencies for deribit.
|
Return the set of currencies for deribit.
|
||||||
'''
|
'''
|
||||||
|
assets = {}
|
||||||
resp = await self._json_rpc_auth_wrapper(
|
resp = await self._json_rpc_auth_wrapper(
|
||||||
'public/get_currencies',
|
'public/get_currencies',
|
||||||
params={}
|
params={}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue