Show unit vlm on LHS for now
							parent
							
								
									51f9511669
								
							
						
					
					
						commit
						e93edc2acb
					
				
							
								
								
									
										117
									
								
								piker/ui/_fsp.py
								
								
								
								
							
							
						
						
									
										117
									
								
								piker/ui/_fsp.py
								
								
								
								
							| 
						 | 
					@ -120,7 +120,6 @@ def update_fsp_chart(
 | 
				
			||||||
        array,
 | 
					        array,
 | 
				
			||||||
        array_key=array_key or graphics_name,
 | 
					        array_key=array_key or graphics_name,
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    chart._set_yrange()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # XXX: re: ``array_key``: fsp func names must be unique meaning we
 | 
					    # XXX: re: ``array_key``: fsp func names must be unique meaning we
 | 
				
			||||||
    # can't have duplicates of the underlying data even if multiple
 | 
					    # can't have duplicates of the underlying data even if multiple
 | 
				
			||||||
| 
						 | 
					@ -400,72 +399,69 @@ async def maybe_open_vlm_display(
 | 
				
			||||||
        log.warning(f"{linked.symbol.key} does not seem to have volume info")
 | 
					        log.warning(f"{linked.symbol.key} does not seem to have volume info")
 | 
				
			||||||
        yield
 | 
					        yield
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    else:
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # shm, opened = maybe_mk_fsp_shm(
 | 
					    async with open_fsp_sidepane(
 | 
				
			||||||
        #     linked.symbol.key,
 | 
					        linked, {
 | 
				
			||||||
        #     'vlm',
 | 
					            'vlm': {
 | 
				
			||||||
        #     readonly=True,
 | 
					                'params': {
 | 
				
			||||||
        # )
 | 
					                    'price_func': {
 | 
				
			||||||
 | 
					                        'default_value': 'chl3',
 | 
				
			||||||
        async with open_fsp_sidepane(
 | 
					                        # tell target ``Edit`` widget to not allow
 | 
				
			||||||
            linked, {
 | 
					                        # edits for now.
 | 
				
			||||||
                'vlm': {
 | 
					                        'widget_kwargs': {'readonly': True},
 | 
				
			||||||
                    'params': {
 | 
					 | 
				
			||||||
                        'price_func': {
 | 
					 | 
				
			||||||
                            'default_value': 'chl3',
 | 
					 | 
				
			||||||
                            # tell target ``Edit`` widget to not allow
 | 
					 | 
				
			||||||
                            # edits for now.
 | 
					 | 
				
			||||||
                            'widget_kwargs': {'readonly': True},
 | 
					 | 
				
			||||||
                        },
 | 
					 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                }
 | 
					                },
 | 
				
			||||||
            },
 | 
					            }
 | 
				
			||||||
        ) as sidepane:
 | 
					        },
 | 
				
			||||||
 | 
					    ) as sidepane:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # built-in $vlm
 | 
					        # built-in $vlm
 | 
				
			||||||
            shm = ohlcv
 | 
					        shm = ohlcv
 | 
				
			||||||
            chart = linked.add_plot(
 | 
					        chart = linked.add_plot(
 | 
				
			||||||
                name='volume',
 | 
					            name='volume',
 | 
				
			||||||
                array=shm.array,
 | 
					            array=shm.array,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                array_key='volume',
 | 
					            array_key='volume',
 | 
				
			||||||
                sidepane=sidepane,
 | 
					            sidepane=sidepane,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                # curve by default
 | 
					            # curve by default
 | 
				
			||||||
                ohlc=False,
 | 
					            ohlc=False,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                # Draw vertical bars from zero.
 | 
					            # Draw vertical bars from zero.
 | 
				
			||||||
                # we do this internally ourselves since
 | 
					            # we do this internally ourselves since
 | 
				
			||||||
                # the curve item internals are pretty convoluted.
 | 
					            # the curve item internals are pretty convoluted.
 | 
				
			||||||
                style='step',
 | 
					            style='step',
 | 
				
			||||||
            )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # XXX: ONLY for sub-chart fsps, overlays have their
 | 
					        # show volume units value on LHS (for dinkus)
 | 
				
			||||||
            # data looked up from the chart's internal array set.
 | 
					        chart.hideAxis('right')
 | 
				
			||||||
            # TODO: we must get a data view api going STAT!!
 | 
					        chart.showAxis('left')
 | 
				
			||||||
            chart._shm = shm
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # should **not** be the same sub-chart widget
 | 
					        # XXX: ONLY for sub-chart fsps, overlays have their
 | 
				
			||||||
            assert chart.name != linked.chart.name
 | 
					        # data looked up from the chart's internal array set.
 | 
				
			||||||
 | 
					        # TODO: we must get a data view api going STAT!!
 | 
				
			||||||
 | 
					        chart._shm = shm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # sticky only on sub-charts atm
 | 
					        # should **not** be the same sub-chart widget
 | 
				
			||||||
            last_val_sticky = chart._ysticks[chart.name]
 | 
					        assert chart.name != linked.chart.name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # read from last calculated value
 | 
					        # sticky only on sub-charts atm
 | 
				
			||||||
            value = shm.array['volume'][-1]
 | 
					        last_val_sticky = chart._ysticks[chart.name]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            last_val_sticky.update_from_data(-1, value)
 | 
					        # read from last calculated value
 | 
				
			||||||
 | 
					        value = shm.array['volume'][-1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            chart.update_curve_from_array(
 | 
					        last_val_sticky.update_from_data(-1, value)
 | 
				
			||||||
                'volume',
 | 
					 | 
				
			||||||
                shm.array,
 | 
					 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # size view to data once at outset
 | 
					        chart.update_curve_from_array(
 | 
				
			||||||
            chart._set_yrange()
 | 
					            'volume',
 | 
				
			||||||
 | 
					            shm.array,
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            yield chart
 | 
					        # size view to data once at outset
 | 
				
			||||||
 | 
					        chart.view._set_yrange()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        yield chart
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async def run_fsp_ui(
 | 
					async def run_fsp_ui(
 | 
				
			||||||
| 
						 | 
					@ -494,7 +490,10 @@ async def run_fsp_ui(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async with (
 | 
					    async with (
 | 
				
			||||||
        # side UI for parameters/controls
 | 
					        # side UI for parameters/controls
 | 
				
			||||||
        open_fsp_sidepane(linkedsplits, {display_name: conf},) as sidepane,
 | 
					        open_fsp_sidepane(
 | 
				
			||||||
 | 
					            linkedsplits,
 | 
				
			||||||
 | 
					            {display_name: conf},
 | 
				
			||||||
 | 
					        ) as sidepane,
 | 
				
			||||||
    ):
 | 
					    ):
 | 
				
			||||||
        await started.wait()
 | 
					        await started.wait()
 | 
				
			||||||
        profiler(f'fsp:{func_name} attached to fsp ctx-stream')
 | 
					        profiler(f'fsp:{func_name} attached to fsp ctx-stream')
 | 
				
			||||||
| 
						 | 
					@ -511,6 +510,7 @@ async def run_fsp_ui(
 | 
				
			||||||
                data=shm.array,
 | 
					                data=shm.array,
 | 
				
			||||||
                overlay=True,
 | 
					                overlay=True,
 | 
				
			||||||
                color='default_light',
 | 
					                color='default_light',
 | 
				
			||||||
 | 
					                array_key=func_name,
 | 
				
			||||||
                separate_axes=conf.get('separate_axes', False),
 | 
					                separate_axes=conf.get('separate_axes', False),
 | 
				
			||||||
                **conf.get('chart_kwargs', {})
 | 
					                **conf.get('chart_kwargs', {})
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
| 
						 | 
					@ -575,7 +575,7 @@ async def run_fsp_ui(
 | 
				
			||||||
            level_line(chart, 70, orient_v='bottom')
 | 
					            level_line(chart, 70, orient_v='bottom')
 | 
				
			||||||
            level_line(chart, 80, orient_v='top')
 | 
					            level_line(chart, 80, orient_v='top')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        chart._set_yrange()
 | 
					        chart.view._set_yrange()
 | 
				
			||||||
        # done()  # status updates
 | 
					        # done()  # status updates
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        profiler(f'fsp:{func_name} starting update loop')
 | 
					        profiler(f'fsp:{func_name} starting update loop')
 | 
				
			||||||
| 
						 | 
					@ -669,7 +669,6 @@ async def start_fsp_displays(
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            'dolla_vlm': {
 | 
					            'dolla_vlm': {
 | 
				
			||||||
 | 
					 | 
				
			||||||
                'func_name': 'dolla_vlm',
 | 
					                'func_name': 'dolla_vlm',
 | 
				
			||||||
                'zero_on_step': True,
 | 
					                'zero_on_step': True,
 | 
				
			||||||
                'overlay': 'volume',
 | 
					                'overlay': 'volume',
 | 
				
			||||||
| 
						 | 
					@ -701,8 +700,10 @@ async def start_fsp_displays(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        trio.open_nursery(),
 | 
					        trio.open_nursery(),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # TODO: fast startup of volume overlayed with $_vlm
 | 
					        maybe_open_vlm_display(
 | 
				
			||||||
        maybe_open_vlm_display(linkedsplits, ohlcv),
 | 
					            linkedsplits,
 | 
				
			||||||
 | 
					            ohlcv,
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    )) as (admin, n, vlm_chart):
 | 
					    )) as (admin, n, vlm_chart):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue