mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-09 08:18:07 +00:00
feat: 添加获取交易所显示名称的功能,并在 MakerApp、OffsetMakerApp 和 TrendApp 中显示交易所名称
This commit is contained in:
@@ -20,6 +20,10 @@ export function resolveExchangeId(value?: string | null): SupportedExchangeId {
|
||||
return "aster";
|
||||
}
|
||||
|
||||
export function getExchangeDisplayName(id: SupportedExchangeId): string {
|
||||
return id === "grvt" ? "GRVT" : "AsterDex";
|
||||
}
|
||||
|
||||
export function createExchangeAdapter(options: ExchangeFactoryOptions): ExchangeAdapter {
|
||||
const id = resolveExchangeId(options.exchange);
|
||||
if (id === "grvt") {
|
||||
|
||||
+10
-5
@@ -1,7 +1,11 @@
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import React, { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Box, Text, useInput } from "ink";
|
||||
import { makerConfig } from "../config";
|
||||
import { createExchangeAdapter, resolveExchangeId } from "../exchanges/create-adapter";
|
||||
import {
|
||||
createExchangeAdapter,
|
||||
getExchangeDisplayName,
|
||||
resolveExchangeId,
|
||||
} from "../exchanges/create-adapter";
|
||||
import { MakerEngine, type MakerEngineSnapshot } from "../core/maker-engine";
|
||||
import { DataTable, type TableColumn } from "./components/DataTable";
|
||||
import { formatNumber } from "../utils/format";
|
||||
@@ -16,6 +20,8 @@ export function MakerApp({ onExit }: MakerAppProps) {
|
||||
const [snapshot, setSnapshot] = useState<MakerEngineSnapshot | null>(null);
|
||||
const [error, setError] = useState<Error | null>(null);
|
||||
const engineRef = useRef<MakerEngine | null>(null);
|
||||
const exchangeId = useMemo(() => resolveExchangeId(), []);
|
||||
const exchangeName = useMemo(() => getExchangeDisplayName(exchangeId), [exchangeId]);
|
||||
|
||||
useInput(
|
||||
(input, key) => {
|
||||
@@ -29,7 +35,6 @@ export function MakerApp({ onExit }: MakerAppProps) {
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
const exchangeId = resolveExchangeId();
|
||||
let adapter;
|
||||
if (exchangeId === "aster") {
|
||||
const apiKey = process.env.ASTER_API_KEY;
|
||||
@@ -66,7 +71,7 @@ export function MakerApp({ onExit }: MakerAppProps) {
|
||||
console.error(err);
|
||||
setError(err instanceof Error ? err : new Error(String(err)));
|
||||
}
|
||||
}, []);
|
||||
}, [exchangeId]);
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
@@ -131,7 +136,7 @@ export function MakerApp({ onExit }: MakerAppProps) {
|
||||
<Box flexDirection="column" marginBottom={1}>
|
||||
<Text color="cyanBright">Maker Strategy Dashboard</Text>
|
||||
<Text>
|
||||
交易对: {snapshot.symbol} | 买一价: {formatNumber(topBid, 2)} | 卖一价: {formatNumber(topAsk, 2)} | 点差: {spreadDisplay}
|
||||
交易所: {exchangeName} | 交易对: {snapshot.symbol} | 买一价: {formatNumber(topBid, 2)} | 卖一价: {formatNumber(topAsk, 2)} | 点差: {spreadDisplay}
|
||||
</Text>
|
||||
<Text color="gray">状态: {snapshot.ready ? "实时运行" : "等待市场数据"} | 按 Esc 返回策略选择</Text>
|
||||
</Box>
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import React, { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Box, Text, useInput } from "ink";
|
||||
import { makerConfig } from "../config";
|
||||
import { createExchangeAdapter, resolveExchangeId } from "../exchanges/create-adapter";
|
||||
import {
|
||||
createExchangeAdapter,
|
||||
getExchangeDisplayName,
|
||||
resolveExchangeId,
|
||||
} from "../exchanges/create-adapter";
|
||||
import { OffsetMakerEngine, type OffsetMakerEngineSnapshot } from "../core/offset-maker-engine";
|
||||
import { DataTable, type TableColumn } from "./components/DataTable";
|
||||
import { formatNumber } from "../utils/format";
|
||||
@@ -16,6 +20,8 @@ export function OffsetMakerApp({ onExit }: OffsetMakerAppProps) {
|
||||
const [snapshot, setSnapshot] = useState<OffsetMakerEngineSnapshot | null>(null);
|
||||
const [error, setError] = useState<Error | null>(null);
|
||||
const engineRef = useRef<OffsetMakerEngine | null>(null);
|
||||
const exchangeId = useMemo(() => resolveExchangeId(), []);
|
||||
const exchangeName = useMemo(() => getExchangeDisplayName(exchangeId), [exchangeId]);
|
||||
|
||||
useInput(
|
||||
(input, key) => {
|
||||
@@ -29,7 +35,6 @@ export function OffsetMakerApp({ onExit }: OffsetMakerAppProps) {
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
const exchangeId = resolveExchangeId();
|
||||
let adapter;
|
||||
if (exchangeId === "aster") {
|
||||
const apiKey = process.env.ASTER_API_KEY;
|
||||
@@ -66,7 +71,7 @@ export function OffsetMakerApp({ onExit }: OffsetMakerAppProps) {
|
||||
console.error(err);
|
||||
setError(err instanceof Error ? err : new Error(String(err)));
|
||||
}
|
||||
}, []);
|
||||
}, [exchangeId]);
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
@@ -138,7 +143,7 @@ export function OffsetMakerApp({ onExit }: OffsetMakerAppProps) {
|
||||
<Box flexDirection="column" marginBottom={1}>
|
||||
<Text color="cyanBright">Offset Maker Strategy Dashboard</Text>
|
||||
<Text>
|
||||
交易对: {snapshot.symbol} | 买一价: {formatNumber(topBid, 2)} | 卖一价: {formatNumber(topAsk, 2)} | 点差: {spreadDisplay}
|
||||
交易所: {exchangeName} | 交易对: {snapshot.symbol} | 买一价: {formatNumber(topBid, 2)} | 卖一价: {formatNumber(topAsk, 2)} | 点差: {spreadDisplay}
|
||||
</Text>
|
||||
<Text>
|
||||
买10档累计: {formatNumber(snapshot.buyDepthSum10, 4)} | 卖10档累计: {formatNumber(snapshot.sellDepthSum10, 4)} | 状态: {imbalanceLabel}
|
||||
|
||||
+10
-5
@@ -1,7 +1,11 @@
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import React, { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Box, Text, useInput } from "ink";
|
||||
import { tradingConfig } from "../config";
|
||||
import { createExchangeAdapter, resolveExchangeId } from "../exchanges/create-adapter";
|
||||
import {
|
||||
createExchangeAdapter,
|
||||
getExchangeDisplayName,
|
||||
resolveExchangeId,
|
||||
} from "../exchanges/create-adapter";
|
||||
import { TrendEngine, type TrendEngineSnapshot } from "../core/trend-engine";
|
||||
import { formatNumber } from "../utils/format";
|
||||
import { DataTable, type TableColumn } from "./components/DataTable";
|
||||
@@ -18,6 +22,8 @@ export function TrendApp({ onExit }: TrendAppProps) {
|
||||
const [snapshot, setSnapshot] = useState<TrendEngineSnapshot | null>(null);
|
||||
const [error, setError] = useState<Error | null>(null);
|
||||
const engineRef = useRef<TrendEngine | null>(null);
|
||||
const exchangeId = useMemo(() => resolveExchangeId(), []);
|
||||
const exchangeName = useMemo(() => getExchangeDisplayName(exchangeId), [exchangeId]);
|
||||
|
||||
useInput(
|
||||
(input, key) => {
|
||||
@@ -31,7 +37,6 @@ export function TrendApp({ onExit }: TrendAppProps) {
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
const exchangeId = resolveExchangeId();
|
||||
let adapter;
|
||||
if (exchangeId === "aster") {
|
||||
const apiKey = process.env.ASTER_API_KEY;
|
||||
@@ -68,7 +73,7 @@ export function TrendApp({ onExit }: TrendAppProps) {
|
||||
console.error(err);
|
||||
setError(err instanceof Error ? err : new Error(String(err)));
|
||||
}
|
||||
}, []);
|
||||
}, [exchangeId]);
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
@@ -115,7 +120,7 @@ export function TrendApp({ onExit }: TrendAppProps) {
|
||||
<Box flexDirection="column" marginBottom={1}>
|
||||
<Text color="cyanBright">Trend Strategy Dashboard</Text>
|
||||
<Text>
|
||||
交易对: {snapshot.symbol} | 最近价格: {formatNumber(lastPrice, 2)} | SMA30: {formatNumber(sma30, 2)} | 趋势: {trend}
|
||||
交易所: {exchangeName} | 交易对: {snapshot.symbol} | 最近价格: {formatNumber(lastPrice, 2)} | SMA30: {formatNumber(sma30, 2)} | 趋势: {trend}
|
||||
</Text>
|
||||
<Text color="gray">状态: {ready ? "实时运行" : READY_MESSAGE} | 按 Esc 返回策略选择</Text>
|
||||
</Box>
|
||||
|
||||
Reference in New Issue
Block a user