4141 round_to_tick_size ,
4242)
4343
44- portfolio = AsyncTyper (help = "View positions and stats for your portfolio." )
44+ portfolio = AsyncTyper (
45+ help = "View positions and stats for your portfolio." , no_args_is_help = True
46+ )
4547
4648
4749def get_indicators (today : date , metrics : MarketMetricInfo ) -> str :
@@ -186,7 +188,7 @@ async def positions(
186188 table .add_column ("Net Liq" , justify = "right" )
187189 table .add_column ("Indicators" , justify = "center" )
188190 sums = defaultdict (lambda : ZERO )
189- closing : dict [ int , TradeableTastytradeData ] = {}
191+ closing : list [ TradeableTastytradeData ] = []
190192 for i , pos in enumerate (positions ):
191193 row = [f"{ i + 1 } " ]
192194 mark = pos .mark or ZERO
@@ -199,7 +201,7 @@ async def positions(
199201 # instrument-specific calculations
200202 if pos .instrument_type == InstrumentType .EQUITY_OPTION :
201203 o = options_dict [pos .symbol ]
202- closing [ i + 1 ] = o
204+ closing . append ( o )
203205 # BWD = beta * stock price * delta / index price
204206 delta = greeks_dict [o .streamer_symbol ].delta * 100 * m
205207 theta = greeks_dict [o .streamer_symbol ].theta * 100 * m
@@ -216,7 +218,7 @@ async def positions(
216218 pnl_day = day_change * pos .quantity * pos .multiplier
217219 elif pos .instrument_type == InstrumentType .FUTURE_OPTION :
218220 o = future_options_dict [pos .symbol ]
219- closing [ i + 1 ] = o
221+ closing . append ( o )
220222 delta = greeks_dict [o .streamer_symbol ].delta * 100 * m
221223 theta = greeks_dict [o .streamer_symbol ].theta * 100 * m
222224 gamma = greeks_dict [o .streamer_symbol ].gamma * 100 * m
@@ -243,7 +245,7 @@ async def positions(
243245 metrics = metrics_dict [pos .symbol ]
244246 e = equity_dict [pos .symbol ]
245247 ticks = e .tick_sizes or []
246- closing [ i + 1 ] = e
248+ closing . append ( e )
247249 beta = metrics .beta or 0
248250 indicators = get_indicators (today , metrics )
249251 bwd = beta * mark_price * delta / spy
@@ -258,7 +260,7 @@ async def positions(
258260 delta = pos .quantity * m * 100
259261 f = futures_dict [pos .symbol ]
260262 ticks = f .tick_sizes or []
261- closing [ i + 1 ] = f
263+ closing . append ( f )
262264 # BWD = beta * stock price * delta / index price
263265 metrics = metrics_dict [f .future_product .root_symbol ] # type: ignore
264266 indicators = get_indicators (today , metrics )
@@ -281,7 +283,7 @@ async def positions(
281283 pos .quantity = round (pos .quantity , 2 )
282284 c = crypto_dict [pos .symbol ]
283285 ticks = [TickSize (value = c .tick_size )]
284- closing [ i + 1 ] = c
286+ closing . append ( c )
285287 day_change = mark_price - prev_close (c .symbol )
286288 pnl_day = day_change * pos .quantity * pos .multiplier
287289 else :
@@ -350,14 +352,18 @@ async def positions(
350352 close = get_confirmation ("Close out a position? y/N " , default = False )
351353 if not close :
352354 return
353- # get the position(s) to close
354- to_close = input (
355- "Enter the number(s) of the leg(s) to include in closing order, separated by commas: "
356- )
357- if not to_close :
358- return
359- to_close = [int (i ) for i in to_close .split ("," )]
360- close_objs = [closing [i ] for i in to_close ]
355+ if len (closing ) > 1 :
356+ # get the position(s) to close
357+ to_close = input (
358+ "Enter the number(s) of the leg(s) to include in closing order, separated by commas: "
359+ )
360+ if not to_close :
361+ return
362+ to_close = [int (i ) for i in to_close .split ("," )]
363+ close_objs = [closing [i - 1 ] for i in to_close ]
364+ else :
365+ print ("Auto-selected the only position available." )
366+ close_objs = [closing [0 ]]
361367 account_number = pos_dict [close_objs [0 ].symbol ].account_number
362368 if any (pos_dict [o .symbol ].account_number != account_number for o in close_objs ):
363369 print ("All legs must be in the same account!" )
0 commit comments