fix: avg_price from netprice, hardcode VIX/crude/USDINR tokens, UI market cache fallback
This commit is contained in:
parent
580c03e959
commit
aba1dcbdda
3 changed files with 10 additions and 16 deletions
|
|
@ -328,12 +328,9 @@ async function loadMarket(){
|
||||||
{key:'USDINR', label:'INR/USD', unit:'\u20b9'},
|
{key:'USDINR', label:'INR/USD', unit:'\u20b9'},
|
||||||
];
|
];
|
||||||
const map=Object.fromEntries(data.map(q=>[q.key,q]));
|
const map=Object.fromEntries(data.map(q=>[q.key,q]));
|
||||||
grid.innerHTML=SLOTS.map(slot=>{
|
if(!window._mktCache)window._mktCache={};(data||[]).forEach(function(q){window._mktCache[q.key]=q;});grid.innerHTML=SLOTS.map(slot=>{
|
||||||
const q=map[slot.key];
|
const q=map[slot.key];
|
||||||
if(!q){
|
if(!q){var c=(window._mktCache||{})[slot.key];if(c){q=c;}else{return '<div class="card mcard"><div class="mlbl">+slot.label+"</div><div class="mprice" style="color:var(--text3)">—</div><div class="mchg" style="color:var(--text3)">—</div></div>';}}
|
||||||
// Placeholder — keep slot, show last known or dash
|
|
||||||
return '<div class="card mcard"><div class="mlbl">'+slot.label+'</div><div class="mprice" style="color:var(--text3)">\u2014</div><div class="mchg" style="color:var(--text3)">no data</div></div>';
|
|
||||||
}
|
|
||||||
const up=q.changePct>=0,cl=up?'up':'dn',arrow=up?'\u25b2':'\u25bc';
|
const up=q.changePct>=0,cl=up?'up':'dn',arrow=up?'\u25b2':'\u25bc';
|
||||||
const price=q.price>10000?q.price.toLocaleString('en-IN',{maximumFractionDigits:0}):q.price.toFixed(2);
|
const price=q.price>10000?q.price.toLocaleString('en-IN',{maximumFractionDigits:0}):q.price.toFixed(2);
|
||||||
return '<div class="card mcard"><div class="mlbl">'+slot.label+'</div>'+
|
return '<div class="card mcard"><div class="mlbl">'+slot.label+'</div>'+
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,9 @@ function normalisePosition(p: AngelPosition): Position | null {
|
||||||
const ltp = parseFloat(p.ltp) || 0;
|
const ltp = parseFloat(p.ltp) || 0;
|
||||||
const unrealised = parseFloat(p.unrealised) || 0;
|
const unrealised = parseFloat(p.unrealised) || 0;
|
||||||
const realised = parseFloat(p.realised) || 0;
|
const realised = parseFloat(p.realised) || 0;
|
||||||
const netAmount = parseFloat(p.netamount) || 0;
|
const netprice = parseFloat(p.netprice) || 0;
|
||||||
// avgPrice = total cost / qty (approximate, fine for display)
|
const cfAvg = netqty > 0 ? (parseFloat(p.cfbuyavgprice)||0) : (parseFloat(p.cfsellavgprice)||0);
|
||||||
const avgPrice = netqty !== 0 ? Math.abs(netAmount / netqty) : 0;
|
const avgPrice = netprice || Math.abs(cfAvg) || 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key: `${p.exchange}:${p.tradingsymbol}`,
|
key: `${p.exchange}:${p.tradingsymbol}`,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ const INDEX_TOKENS = [
|
||||||
{ key: 'NIFTY50', exchange: 'NSE', token: '26000', label: 'NIFTY 50', unit: 'pts' },
|
{ key: 'NIFTY50', exchange: 'NSE', token: '26000', label: 'NIFTY 50', unit: 'pts' },
|
||||||
{ key: 'BANKNIFTY', exchange: 'NSE', token: '26009', label: 'BANK NIFTY', unit: 'pts' },
|
{ key: 'BANKNIFTY', exchange: 'NSE', token: '26009', label: 'BANK NIFTY', unit: 'pts' },
|
||||||
{ key: 'INDIAVIX', exchange: 'NSE', token: '26017', label: 'INDIA VIX', unit: '%' },
|
{ key: 'INDIAVIX', exchange: 'NSE', token: '26017', label: 'INDIA VIX', unit: '%' },
|
||||||
|
{ key: 'CRUDEOIL', exchange: 'MCX', token: '234230', label: 'Crude Oil', unit: '₹/bbl' },
|
||||||
|
{ key: 'USDINR', exchange: 'CDS', token: '1', label: 'INR/USD', unit: '₹' },
|
||||||
];
|
];
|
||||||
|
|
||||||
async function searchToken(exchange: string, query: string): Promise<string | null> {
|
async function searchToken(exchange: string, query: string): Promise<string | null> {
|
||||||
|
|
@ -49,19 +51,14 @@ function loadFromCache(): MarketQuote[] {
|
||||||
async function fetchFromAngel(): Promise<MarketQuote[]> {
|
async function fetchFromAngel(): Promise<MarketQuote[]> {
|
||||||
const headers = await getAuthHeaders();
|
const headers = await getAuthHeaders();
|
||||||
|
|
||||||
const [crudeToken, usdinrToken] = await Promise.all([
|
// All tokens hardcoded - build token map directly
|
||||||
searchToken('MCX', 'CRUDEOIL'),
|
const tokenMap: Record<string, string[]> = {};
|
||||||
searchToken('CDS', 'USDINR'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const tokenMap: Record<string, string[]> = { NSE: [], BSE: [] };
|
|
||||||
const tokenIndex: Record<string, string> = {};
|
const tokenIndex: Record<string, string> = {};
|
||||||
for (const idx of INDEX_TOKENS) {
|
for (const idx of INDEX_TOKENS) {
|
||||||
|
if (!tokenMap[idx.exchange]) tokenMap[idx.exchange] = [];
|
||||||
tokenMap[idx.exchange].push(idx.token);
|
tokenMap[idx.exchange].push(idx.token);
|
||||||
tokenIndex[idx.token] = idx.key;
|
tokenIndex[idx.token] = idx.key;
|
||||||
}
|
}
|
||||||
if (crudeToken) { tokenMap['MCX'] = [crudeToken]; tokenIndex[crudeToken] = 'CRUDEOIL'; }
|
|
||||||
if (usdinrToken) { tokenMap['CDS'] = [usdinrToken]; tokenIndex[usdinrToken] = 'USDINR'; }
|
|
||||||
|
|
||||||
const r = await axios.post(BASE + '/rest/secure/angelbroking/market/v1/quote/',
|
const r = await axios.post(BASE + '/rest/secure/angelbroking/market/v1/quote/',
|
||||||
{ mode: 'FULL', exchangeTokens: tokenMap }, { headers, timeout: 8000 });
|
{ mode: 'FULL', exchangeTokens: tokenMap }, { headers, timeout: 8000 });
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue