Skip to content

Commit

Permalink
fix(acc-composer): timeout and throttle
Browse files Browse the repository at this point in the history
  • Loading branch information
zccz14 committed Mar 5, 2024
1 parent 567ac7e commit c5d6c57
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 26 deletions.
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

0 comments on commit c5d6c57

Please sign in to comment.