Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(acc-composer): timeout and throttle #480

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 40 additions & 25 deletions apps/account-composer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@ import { IAccountInfo, formatTime } from '@yuants/data-model';
import { Terminal } from '@yuants/protocol';
import Ajv from 'ajv';
import addFormats from 'ajv-formats';
import { combineLatest, defer, filter, groupBy, map, mergeMap, retry, shareReplay, tap, toArray } from 'rxjs';
import {
combineLatest,
defer,
filter,
groupBy,
map,
mergeMap,
retry,
shareReplay,
tap,
throttleTime,
timeout,
toArray,
} from 'rxjs';
import { IAccountCompositionRelation, acrSchema } from './model';

const TERMINAL_ID = process.env.TERMINAL_ID || `AccountComposer`;
Expand Down Expand Up @@ -30,34 +43,36 @@ defer(() => terminal.queryDataRecords<IAccountCompositionRelation>({ type: 'acco
group.pipe(
toArray(),
tap((x) => {
const accountInfo$ = combineLatest(
x.map((y) =>
terminal.useAccountInfo(y.source_account_id).pipe(
//
map(
(x): IAccountInfo => ({
...x,
money: {
//
...x.money,
equity: x.money.equity * y.multiple,
balance: x.money.balance * y.multiple,
profit: x.money.profit * y.multiple,
used: x.money.used * y.multiple,
free: x.money.free * y.multiple,
},
positions: x.positions.map((p) => ({
...p,
volume: p.volume * y.multiple,
free_volume: p.free_volume * y.multiple,
floating_profit: p.floating_profit * y.multiple,
})),
}),
const accountInfo$ = defer(() =>
combineLatest(
x.map((y) =>
terminal.useAccountInfo(y.source_account_id).pipe(
map(
(x): IAccountInfo => ({
...x,
money: {
...x.money,
equity: x.money.equity * y.multiple,
balance: x.money.balance * y.multiple,
profit: x.money.profit * y.multiple,
used: x.money.used * y.multiple,
free: x.money.free * y.multiple,
},
positions: x.positions.map((p) => ({
...p,
volume: p.volume * y.multiple,
free_volume: p.free_volume * y.multiple,
floating_profit: p.floating_profit * y.multiple,
})),
}),
),
timeout(30_000),
),
),
),
).pipe(
//
retry(),
throttleTime(1000),
map((accountInfos): IAccountInfo => {
return {
account_id: group.key,
Expand Down
10 changes: 10 additions & 0 deletions common/changes/@yuants/app-account-composer/2024-03-05-17-26.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@yuants/app-account-composer",
"comment": "timeout and throttle",
"type": "patch"
}
],
"packageName": "@yuants/app-account-composer"
}
3 changes: 2 additions & 1 deletion ui/web/src/modules/AccountInfo/AccountInfoPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ registerPage('AccountInfoPanel', () => {
)?.[0];

return (
<Space vertical align="start" style={{ padding: '1em' }}>
<Space vertical align="start" style={{ padding: '1em', width: '100%' }}>
<h3 style={{ color: 'var(--semi-color-text-0)', fontWeight: 500 }}>{accountInfo.account_id}</h3>
<Typography.Text>
最后更新时间: {formatTime(updatedAt)} (Ping {renderedAt - updatedAt}ms)
Expand All @@ -182,6 +182,7 @@ registerPage('AccountInfoPanel', () => {
align="center"
size="small"
row
style={{ width: '100%' }}
data={[
{
key: '净值',
Expand Down
Loading