Skip to content

Commit

Permalink
feat(gui): enable read/write InterleavingTraderConfig (No-Trade-No-Li…
Browse files Browse the repository at this point in the history
  • Loading branch information
zccz14 authored Oct 3, 2024
1 parent d3e444c commit 4f06066
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions ui/web/src/modules/Order/InterleavingTrader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Ajv from 'ajv';
import { parse } from 'jsonc-parser';
import { useObservableState } from 'observable-hooks';
import { useMemo, useState } from 'react';
import { from, lastValueFrom } from 'rxjs';
import { BehaviorSubject, from, lastValueFrom } from 'rxjs';
import { InlineAccountId, useAccountInfo } from '../AccountInfo';
import { fs } from '../FileSystem/api';
import Form, { showForm } from '../Form';
Expand All @@ -13,7 +13,7 @@ import { registerPage } from '../Pages';
import { InlineProductId } from '../Products/InlineProductId';
import { terminal$, useTick } from '../Terminals';

interface IInterleavingConfigItem {
export interface IInterleavingConfigItem {
account_id: string;
datasource_id: string;
product_id: string;
Expand All @@ -23,7 +23,7 @@ interface IInterleavingConfigItem {
disabled?: boolean;
}

interface IInterleavingConfig {
export interface IInterleavingConfig {
count: number;
items: IInterleavingConfigItem[];
}
Expand Down Expand Up @@ -79,8 +79,10 @@ const initState: IState = {
message: '',
};

export const InterleavingTraderConfig$ = new BehaviorSubject<IInterleavingConfig | undefined>(void 0);

registerPage('InterleavingTrader', () => {
const [config, setConfig] = useState<IInterleavingConfig>();
const config = useObservableState(InterleavingTraderConfig$);
const [state, setState] = useState<IState>(initState);
const terminal = useObservableState(terminal$);

Expand Down Expand Up @@ -112,7 +114,7 @@ registerPage('InterleavingTrader', () => {
if (!validator.validate(schema, config)) {
throw validator.errorsText();
}
setConfig(config);
InterleavingTraderConfig$.next(config);
Toast.success('Success to load');
} catch (e) {
Toast.success(`Failed to load: ${e}`);
Expand All @@ -125,7 +127,7 @@ registerPage('InterleavingTrader', () => {
<Form
formData={config}
onChange={(e) => {
setConfig(e.formData);
InterleavingTraderConfig$.next(e.formData);
}}
schema={schema}
>
Expand Down
2 changes: 1 addition & 1 deletion ui/web/src/modules/Order/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import './InterleavingTrader';
import './ManualTradePanel';
import './OrderListPanel';
export * from './InterleavingTrader';

0 comments on commit 4f06066

Please sign in to comment.