Skip to content

Commit

Permalink
Просмотр IPO
Browse files Browse the repository at this point in the history
  • Loading branch information
maksim-zakharov committed Oct 10, 2024
1 parent 71853d9 commit 573bd74
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 30 deletions.
57 changes: 32 additions & 25 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,15 @@ import useListSecs from "./useListSecs";
import {initApi, setSettings, updateDarkColors} from "./api/alor.slice";
import {useAppDispatch, useAppSelector} from "./store";
import {MenuItemType} from "antd/es/menu/interface";
import {FundOutlined, ProfileOutlined, DownOutlined, SearchOutlined} from "@ant-design/icons";
import {
calculateCommission, useGetAllSummariesQuery,
useGetEquityDynamicsQuery,
useGetSummaryQuery,
useGetTradesQuery,
useGetUserInfoQuery
} from './api/alor.api';
import {FundOutlined, ProfileOutlined, SearchOutlined} from "@ant-design/icons";
import {calculateCommission, useGetAllSummariesQuery, useGetTradesQuery, useGetUserInfoQuery} from './api/alor.api';
import {getEnv, oAuth2Client} from "./api/oAuth2";
import QuestionCircleIcon from "./assets/question-circle";
import PortfolioIcon from './assets/portfolio';
import CheckIcon from './assets/check';
import {moneyFormat} from "./common/utils";
import ChevronBottomIcon from "./assets/chevron-bottom";
import useWindowDimensions from "./common/useWindowDimensions";
import useScroll from "./common/useScroll";
import WhatBuy from "./pages/WhatBuy";

export const avg = (numbers: number[]) =>
Expand Down Expand Up @@ -135,7 +128,7 @@ function App() {
commissionType: settings.commissionType,
portfolio: settings.portfolio
}, {
skip: !userInfo || !settings.agreement || !settings.portfolio
skip: !userInfo || !settings.agreement || !settings.portfolio
})

const trades = useMemo(() => {
Expand Down Expand Up @@ -280,15 +273,16 @@ function App() {
key: 'diary',
label: 'Дневник',
icon: <ProfileOutlined/>,
element: <Diary trades={_trades} getIsinBySymbol={getIsinBySymbol} getListSectionBySymbol={getListSectionBySymbol}
element: <Diary trades={_trades} getIsinBySymbol={getIsinBySymbol}
getListSectionBySymbol={getListSectionBySymbol}
isMobile={width < 400 ? 1 : width < 1200 ? Math.round(width / 410) : 0}
dateFrom={dateFrom} dateTo={dateTo}
data={data} isLoading={isLoading}/>
},
isMobile && {
key: 'what_buy',
label: 'Что купить',
icon: <SearchOutlined />,
icon: <SearchOutlined/>,
element: <WhatBuy getIsinBySymbol={getIsinBySymbol}/>
},
{
Expand Down Expand Up @@ -358,36 +352,44 @@ function App() {
skip: !userInfo
});

const accountSummariesMap = useMemo(() => (summaries || []).reduce((acc, curr) => ({...acc, [curr.accountNumber]: curr}),{}), [summaries]);
const accountSummariesMap = useMemo(() => (summaries || []).reduce((acc, curr) => ({
...acc,
[curr.accountNumber]: curr
}), {}), [summaries]);
const agreementSummariesMap = useMemo(() => (summaries || []).reduce((acc, curr) => {
if(!acc[curr.agreementNumber]){
if (!acc[curr.agreementNumber]) {
acc[curr.agreementNumber] = 0;
}
acc[curr.agreementNumber] += curr.portfolioLiquidationValue;
return acc;
},{}), [summaries]);
}, {}), [summaries]);

const totalSum = useMemo(() => (summaries || []).reduce((acc, curr) => {
acc += curr.portfolioLiquidationValue;
return acc;
},0), [summaries]);
}, 0), [summaries]);

const items: MenuProps['items'] = useMemo(() => (userInfo?. agreements || []).map(agreement => ({label: <div className="portfolio-item">
const items: MenuProps['items'] = useMemo(() => (userInfo?.agreements || []).map(agreement => ({
label: <div className="portfolio-item">
<Space><span>Договор {agreement.cid}</span></Space>
<div className="portfolio-summary">
<span className="portfolio-description">Всего на {agreement.portfolios.length} счетах:</span>{moneyFormat(agreementSummariesMap[agreement.agreementNumber], 0, 0)}</div>
</div>, type: 'group', key: agreement.agreementNumber, children: agreement.portfolios.map(portfolio => ({
{!agreement.isEDP && <div className="portfolio-summary">
<span
className="portfolio-description">Всего на {agreement.portfolios.length} счетах:</span>{moneyFormat(agreementSummariesMap[agreement.agreementNumber], 0, 0)}
</div>}
</div>, type: 'group', key: agreement.agreementNumber, children:( agreement.isEDP ? [{accountNumber: `E${agreement.agreementNumber}`, service: 'ЕДП'}] : agreement.portfolios).map(portfolio => ({
label: <div className="portfolio-item">
<Space><span>{portfolio.accountNumber} ({portfolio.service})</span><CheckIcon/></Space>
<div className="portfolio-summary">{moneyFormat(accountSummariesMap[portfolio.accountNumber]?.portfolioLiquidationValue, 0, 0)}</div>
<div
className="portfolio-summary">{moneyFormat(accountSummariesMap[portfolio.accountNumber]?.portfolioLiquidationValue, 0, 0)}</div>
</div>,
key: `${agreement.agreementNumber}-${portfolio.accountNumber}`,
icon: <div className="portfolio-icon"><PortfolioIcon/></div>
})) })), [userInfo]);
}))
})), [userInfo]);

const onSelect = ({key}) => {
const [agreement, portfolio] = key.split('-');
if(agreement && portfolio){
if (agreement && portfolio) {
dispatch(setSettings(({agreement, portfolio})))
}
}
Expand All @@ -400,13 +402,18 @@ function App() {
<span className="portfolio-description">Всего на всех счетах:</span>
</div>
<div className="portfolio-summary">
{moneyFormat(totalSum, 0, 0)}
{moneyFormat(totalSum, 0, 0)}
</div>
</div>
<Divider/>
{menu}
</>
)} menu={{ selectedKeys: [`${settings.agreement}-${settings.portfolio}`], items, onSelect, selectable: true}} trigger={['click']} className="SelectAccountDropdown">
)} menu={{
selectedKeys: [`${settings.agreement}-${settings.portfolio}`],
items,
onSelect,
selectable: true
}} trigger={['click']} className="SelectAccountDropdown">
<a className="header-support-link" onClick={e => e.preventDefault()}>
<Space>
<strong>{settings.portfolio}</strong>
Expand Down
22 changes: 18 additions & 4 deletions src/api/alor.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,18 @@ const getAllSummaries = (api: AlorApi) => async ({
}: (Omit<ExchangePortfolioSummaryParams, 'portfolio'> & {
userInfo: UserInfoResponse
})) => {
return Promise.all(userInfo.agreements.map((agreement) => agreement.portfolios.map(p => api.clientInfo.getSummary({
// @ts-ignore
return Promise.all(userInfo.agreements.map((agreement) => agreement.isEDP ? [api.clientInfo.getSummary({
...params,
// @ts-ignore
exchange: 'UNITED',
portfolio: `E${agreement.agreementNumber}`
}).then(r => ({
...r,
service: 'ЕДП',
accountNumber: `E${agreement.agreementNumber}`,
agreementNumber: agreement.agreementNumber
}))] : agreement.portfolios.map(p => api.clientInfo.getSummary({
...params,
portfolio: p.accountNumber
}).then(r => ({
Expand Down Expand Up @@ -386,21 +397,24 @@ export const alorApi = createApi({
portfolio: string
}) => {
let trades: Trade[] = await api.clientInfo.getTrades({
exchange: Exchange.MOEX,
// @ts-ignore
exchange: portfolio.startsWith('E') ? 'UNITED' : Exchange.MOEX,
portfolio,
});

if (date || dateFrom) {
let lastTrades = await api.clientInfo.getHistoryTrades({
exchange: Exchange.MOEX,
// @ts-ignore
exchange: portfolio.startsWith('E') ? 'UNITED' : Exchange.MOEX,
portfolio,
dateFrom: date || dateFrom,
});
trades.push(...lastTrades);

while (lastTrades.length > 1) {
lastTrades = await api.clientInfo.getHistoryTrades({
exchange: Exchange.MOEX,
// @ts-ignore
exchange: portfolio.startsWith('E') ? 'UNITED' : Exchange.MOEX,
portfolio,
from: trades.slice(-1)[0].id,
});
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Diary/Diary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ const Diary: FC<IProps> = ({
})

const {data: summary, isLoading: isSummaryLoading} = useGetSummaryQuery({
exchange: Exchange.MOEX,
// @ts-ignore
exchange: settings.portfolio.startsWith('E') ? 'UNITED' : Exchange.MOEX,
format: 'Simple',
portfolio: settings.portfolio
}, {
Expand Down

0 comments on commit 573bd74

Please sign in to comment.