Allocate order size using lots digits calc
parent
69a1f5e8a8
commit
ccad7cfc2a
|
@ -22,15 +22,15 @@ from __future__ import annotations
|
||||||
import enum
|
import enum
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from math import floor
|
from math import floor
|
||||||
|
from pprint import pprint
|
||||||
import sys
|
import sys
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import QWidget
|
||||||
from bidict import bidict
|
from bidict import bidict
|
||||||
from pyqtgraph import functions as fn
|
from pyqtgraph import functions as fn
|
||||||
from pydantic import BaseModel, validator
|
from pydantic import BaseModel, validator
|
||||||
# from pydantic.generics import GenericModel
|
|
||||||
# from PyQt5.QtCore import QPointF
|
|
||||||
# from PyQt5.QtGui import QGraphicsPathItem
|
|
||||||
|
|
||||||
from ._annotate import LevelMarker
|
from ._annotate import LevelMarker
|
||||||
from ._anchors import (
|
from ._anchors import (
|
||||||
|
@ -92,6 +92,7 @@ def mk_pp_alloc(
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
validate_assignment = True
|
validate_assignment = True
|
||||||
|
extra = 'allow'
|
||||||
|
|
||||||
account: Account = None
|
account: Account = None
|
||||||
_accounts: dict[str, Optional[str]] = accounts
|
_accounts: dict[str, Optional[str]] = accounts
|
||||||
|
@ -109,18 +110,24 @@ def mk_pp_alloc(
|
||||||
|
|
||||||
def get_order_info(
|
def get_order_info(
|
||||||
self,
|
self,
|
||||||
|
|
||||||
|
# TODO: apply the symbol when the chart it is selected
|
||||||
|
symbol: Symbol,
|
||||||
price: float,
|
price: float,
|
||||||
|
|
||||||
) -> dict:
|
) -> dict:
|
||||||
size = self.size / self.slots
|
|
||||||
|
|
||||||
units, r = divmod(
|
# pprint(self._position.info.dict())
|
||||||
round((self.size / self.slots)),
|
|
||||||
price,
|
|
||||||
)
|
|
||||||
print(f'# shares: {units}, r: {r}')
|
|
||||||
|
|
||||||
# Allocator.update_forward_refs()
|
fiat_size = self.size / self.slots
|
||||||
|
ld = symbol.lot_digits()
|
||||||
|
units = round(fiat_size / price, ndigits=ld)
|
||||||
|
|
||||||
|
return {'size': units, 'size_digits': ld}
|
||||||
|
|
||||||
|
def pp_update(self) -> None:
|
||||||
|
# update fill bar and labels
|
||||||
|
...
|
||||||
|
|
||||||
return Allocator(
|
return Allocator(
|
||||||
account=None,
|
account=None,
|
||||||
|
@ -137,6 +144,7 @@ class PositionTracker:
|
||||||
'''
|
'''
|
||||||
# inputs
|
# inputs
|
||||||
chart: 'ChartPlotWidget' # noqa
|
chart: 'ChartPlotWidget' # noqa
|
||||||
|
alloc: 'Allocator'
|
||||||
|
|
||||||
# allocated
|
# allocated
|
||||||
info: Position
|
info: Position
|
||||||
|
@ -180,6 +188,8 @@ class PositionTracker:
|
||||||
)
|
)
|
||||||
pp_label.render()
|
pp_label.render()
|
||||||
|
|
||||||
|
nsize = self.chart.linked.symbol.lot_digits()
|
||||||
|
|
||||||
self.size_label = size_label = Label(
|
self.size_label = size_label = Label(
|
||||||
view=view,
|
view=view,
|
||||||
color=self._color,
|
color=self._color,
|
||||||
|
@ -187,11 +197,12 @@ class PositionTracker:
|
||||||
# this is "static" label
|
# this is "static" label
|
||||||
# update_on_range_change=False,
|
# update_on_range_change=False,
|
||||||
fmt_str='\n'.join((
|
fmt_str='\n'.join((
|
||||||
':{entry_size:.0f}',
|
':{entry_size:.{size_digits}f}',
|
||||||
)),
|
)),
|
||||||
|
|
||||||
fields={
|
fields={
|
||||||
'entry_size': 0,
|
'entry_size': 0,
|
||||||
|
'size_digits': nsize
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
size_label.render()
|
size_label.render()
|
||||||
|
@ -356,7 +367,7 @@ class PositionTracker:
|
||||||
level,
|
level,
|
||||||
color=self._color,
|
color=self._color,
|
||||||
add_label=False,
|
add_label=False,
|
||||||
hl_on_hover=False,
|
highlight_on_hover=False,
|
||||||
movable=False,
|
movable=False,
|
||||||
hide_xhair_on_hover=False,
|
hide_xhair_on_hover=False,
|
||||||
use_marker_margin=True,
|
use_marker_margin=True,
|
||||||
|
|
Loading…
Reference in New Issue