@@ -733,6 +733,11 @@ app.post<{ Body: Record<string, unknown> }>('/api/instruments/quotes', async (re
733733 return { success : r . success , data : r . data , message : r . message }
734734} )
735735
736+ app . post < { Body : Record < string , unknown > } > ( '/api/instruments/quote' , async ( req ) => {
737+ const r = await hub . dispatch ( 'instrument_quote' , req . body ?? { } )
738+ return { success : r . success , data : r . data , message : r . message }
739+ } )
740+
736741app . post < { Body : Record < string , unknown > } > ( '/api/instruments/chart' , async ( req ) => {
737742 const r = await hub . dispatch ( 'instrument_chart' , req . body ?? { } )
738743 return { success : r . success , data : r . data , message : r . message }
@@ -1992,16 +1997,39 @@ app.put<{ Body: { groups?: Array<{ id: string; title: string; sortOrder: number;
19921997 } ,
19931998)
19941999
1995- app . post < { Body : { code : string ; shares : number ; price : number ; side ?: string ; date ?: string ; market ?: string } } > (
2000+ app . post < { Body : {
2001+ code : string
2002+ shares : number
2003+ price : number
2004+ side ?: string
2005+ date ?: string
2006+ market ?: string
2007+ assetClass ?: string
2008+ instrument ?: { market : string ; assetClass : string ; symbol : string ; exchange ?: string }
2009+ } } > (
19962010 '/api/portfolio/trade' ,
19972011 async ( req , reply ) => {
1998- const { code, shares, price, side = 'buy' , date, market } = req . body ?? { }
2012+ const { code, shares, price, side = 'buy' , date, market, assetClass , instrument } = req . body ?? { }
19992013 if ( ! code || ! shares || ! price ) return reply . code ( 400 ) . send ( { error : 'code, shares, price required' } )
20002014 const pm = hub . de . portfolio
20012015 const m = market ?. trim ( ) || undefined
2002- const result = side === 'sell'
2003- ? await pm . sell ( code , shares , price , date , '' , m as import ( '@opptrix/shared' ) . Market | undefined )
2004- : await pm . buy ( code , shares , price , date , '' , m as import ( '@opptrix/shared' ) . Market | undefined )
2016+ const ac = assetClass ?. trim ( ) || undefined
2017+ const inst = instrument && typeof instrument === 'object'
2018+ ? instrument as import ( '@opptrix/shared' ) . InstrumentRef
2019+ : undefined
2020+ const result = await pm . recordTrade (
2021+ side === 'sell' ? 'sell' : 'buy' ,
2022+ code ,
2023+ shares ,
2024+ price ,
2025+ {
2026+ date,
2027+ name : '' ,
2028+ market : m as import ( '@opptrix/shared' ) . Market | undefined ,
2029+ assetClass : ac as import ( '@opptrix/shared' ) . AssetClass | undefined ,
2030+ instrument : inst ,
2031+ } ,
2032+ )
20052033 return { success : true , trade : result }
20062034 } ,
20072035)
0 commit comments