Skip to content

Commit e14d52b

Browse files
fix: updated code
1 parent 58ad926 commit e14d52b

File tree

8 files changed

+52
-40
lines changed

8 files changed

+52
-40
lines changed

frontend/src/components/AskBidsTable.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import { toDisplayPrice } from "../utils/utils";
44
import { subscribePrices, type LivePrices } from "../utils/price_store";
55

66
export interface Trade {
7-
buyPrice: number;
8-
sellPrice: number;
7+
bidPrice: number;
8+
askPrice: number;
99
symbol: SYMBOL;
1010
}
1111

12+
1213
const imageUrl = {
14+
1315
SOL: "https://i.postimg.cc/9MhDvsK9/b2f0c70f-4fb2-4472-9fe7-480ad1592421.png",
1416
ETH: "https://i.postimg.cc/gcKhPkY2/3a8c9fe6-2a76-4ace-aa07-415d994de6f0.png",
1517
BTC: "https://i.postimg.cc/TPh0K530/87496d50-2408-43e1-ad4c-78b47b448a6a.png",
@@ -51,8 +53,8 @@ export default function AskBids({ symbol }: { symbol?: SYMBOL }) {
5153
<thead>
5254
<tr className="text-xs text-neutral-400 border-b border-neutral-600/40">
5355
<th className="py-3 text-left font-medium">Symbol</th>
54-
<th className="py-3 text-right font-medium">Ask</th>
5556
<th className="py-3 text-right font-medium">Bid</th>
57+
<th className="py-3 text-right font-medium">Ask</th>
5658
</tr>
5759
</thead>
5860
<tbody className="divide-y divide-neutral-600/20">
@@ -77,10 +79,10 @@ export default function AskBids({ symbol }: { symbol?: SYMBOL }) {
7779
</div>
7880
</th>
7981
<td className="py-4 text-right font-mono text-[#158BF9] font-semibold">
80-
{item.bids}
82+
{item.asks}
8183
</td>
8284
<td className="py-4 text-right font-mono text-[#EB483F] font-semibold">
83-
{item.asks}
85+
{item.bids}
8486
</td>
8587
</tr>
8688
))}

frontend/src/components/BuySell.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import {
1313
} from "../utils/utils";
1414

1515
export default function BuySell({
16-
buyPrice,
17-
sellPrice,
16+
askPrice,
17+
bidPrice,
1818
symbol,
1919
}: {
20-
buyPrice: number;
21-
sellPrice: number;
20+
askPrice: number;
21+
bidPrice: number;
2222
symbol: SYMBOL;
2323
}) {
2424
const [orderType, setOrderType] = useState<"market" | "pending">("market");
@@ -79,8 +79,8 @@ export default function BuySell({
7979
// 1. Convert all inputs to the correct scaled-integer format
8080
const openPriceForCalc =
8181
activeTab === "buy"
82-
? toInternalPrice(buyPrice)
83-
: toInternalPrice(sellPrice);
82+
? toInternalPrice(askPrice)
83+
: toInternalPrice(bidPrice);
8484
const closePriceForCalc = toInternalPrice(Number(tpPrice));
8585
const marginForCalc = margin * 100; // Convert dollar margin to cents
8686

@@ -92,16 +92,16 @@ export default function BuySell({
9292
marginCents: marginForCalc,
9393
leverage: leverage,
9494
});
95-
}, [tpEnabled, tpPrice, activeTab, buyPrice, sellPrice, margin, leverage]);
95+
}, [tpEnabled, tpPrice, activeTab, askPrice, bidPrice, margin, leverage]);
9696

9797
const estimatedSlPnlInCents = useMemo(() => {
9898
if (!slEnabled || !slPrice || Number(slPrice) <= 0) return 0;
9999

100100
// 1. Convert all inputs to the correct scaled-integer format
101101
const openPriceForCalc =
102102
activeTab === "buy"
103-
? toInternalPrice(buyPrice)
104-
: toInternalPrice(sellPrice);
103+
? toInternalPrice(askPrice)
104+
: toInternalPrice(bidPrice);
105105
const closePriceForCalc = toInternalPrice(Number(slPrice));
106106
const marginForCalc = margin * 100; // Convert dollar margin to cents
107107

@@ -113,7 +113,7 @@ export default function BuySell({
113113
marginCents: marginForCalc,
114114
leverage: leverage,
115115
});
116-
}, [slEnabled, slPrice, activeTab, buyPrice, sellPrice, margin, leverage]);
116+
}, [slEnabled, slPrice, activeTab, askPrice, bidPrice, margin, leverage]);
117117

118118
const handleSubmitTrade = async () => {
119119
if (margin <= 0) {
@@ -222,7 +222,9 @@ export default function BuySell({
222222
</div>
223223
</div>
224224
) : (
225-
<div className="text-sm font-semibold text-neutral-50">{symbol}</div>
225+
<div className="text-sm font-semibold text-neutral-50">
226+
{symbol}
227+
</div>
226228
)}
227229
<div className="text-xs ml-auto bg-neutral-800/60 backdrop-blur-sm px-3 py-2 rounded-md border border-neutral-600">
228230
<span className="text-neutral-300">Balance:</span>
@@ -243,7 +245,7 @@ export default function BuySell({
243245
</div>
244246
<div className="mt-2 text-lg font-semibold text-[#EB483F] flex items-center">
245247
<span className="text-sm mr-1">$</span>
246-
{sellPrice}
248+
{bidPrice}
247249
</div>
248250
<div className="absolute w-1 h-full bg-[#EB483F]/40 left-0 top-0"></div>
249251
</div>
@@ -256,7 +258,7 @@ export default function BuySell({
256258
</div>
257259
<div className="mt-2 text-lg font-semibold text-[#158BF9] flex items-center">
258260
<span className="text-sm mr-1">$</span>
259-
{buyPrice}
261+
{askPrice}
260262
</div>
261263
<div className="absolute w-1 h-full bg-[#158BF9]/40 left-0 top-0"></div>
262264
</div>
@@ -559,7 +561,7 @@ export default function BuySell({
559561
</div>
560562
<div className="text-[10px] text-white/40">
561563
Target: ${tpPrice} | Current: $
562-
{activeTab === "buy" ? buyPrice : sellPrice}
564+
{activeTab === "buy" ? askPrice : bidPrice}
563565
</div>
564566
</div>
565567
)}
@@ -650,7 +652,7 @@ export default function BuySell({
650652
</div>
651653
<div className="text-[10px] text-white/40">
652654
Stop: ${slPrice} | Current: $
653-
{activeTab === "buy" ? buyPrice : sellPrice}
655+
{activeTab === "buy" ? askPrice : bidPrice}
654656
</div>
655657
</div>
656658
)}

frontend/src/components/Chart.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function ChartComponent({
3131
}: {
3232
duration: Duration;
3333
symbol: SYMBOL;
34-
onPriceUpdate?: (prices: { buyPrice: number; sellPrice: number }) => void;
34+
onPriceUpdate?: (prices: { bidPrice: number; askPrice: number }) => void;
3535
}) {
3636
const chartContainerRef = useRef<HTMLDivElement>(null);
3737
const chartRef = useRef<IChartApi | null>(null);
@@ -110,13 +110,20 @@ export default function ChartComponent({
110110
const tickWrapper = (trade: Trade) => {
111111
if (trade.symbol !== symbol) return;
112112

113-
const candle = processRealupdate(trade as RealtimeUpdate, duration);
113+
const tick: RealtimeUpdate = {
114+
symbol: trade.symbol,
115+
bidPrice: trade.bidPrice,
116+
askPrice: trade.askPrice,
117+
time: Math.floor(Date.now() / 1000),
118+
};
119+
120+
const candle = processRealupdate(tick, duration);
114121

115122
const prices = {
116-
buyPrice: trade.buyPrice || 0,
117-
sellPrice: trade.sellPrice || 0,
123+
bidPrice: trade.bidPrice || 0,
124+
askPrice: trade.askPrice || 0,
118125
};
119-
if (onPriceUpdate && prices.buyPrice > 0 && prices.sellPrice > 0) {
126+
if (onPriceUpdate && prices.bidPrice > 0 && prices.askPrice > 0) {
120127
onPriceUpdate(prices);
121128
}
122129

frontend/src/pages/Trading.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import { toDisplayPrice } from "../utils/utils";
1212
export default function Trading() {
1313
const [duration, setDuration] = useState<Duration>(Duration.candles_1m);
1414
const [symbol, setSymbol] = useState<SYMBOL>(Channels.BTCUSDT);
15-
const [prices, setPrices] = useState({ buyPrice: 0, sellPrice: 0 });
15+
const [prices, setPrices] = useState({ askPrice: 0, bidPrice: 0 });
1616
const navigate = useNavigate();
17-
17+
1818
useEffect(() => {
1919
async function checkdata() {
2020
try {
@@ -164,8 +164,8 @@ export default function Trading() {
164164
<div className="w-full h-full md:w-1/4">
165165
<BuySell
166166
symbol={symbol}
167-
buyPrice={toDisplayPrice(prices.buyPrice)}
168-
sellPrice={toDisplayPrice(prices.sellPrice)}
167+
askPrice={toDisplayPrice(prices.askPrice)}
168+
bidPrice={toDisplayPrice(prices.bidPrice)}
169169
/>
170170
</div>
171171
</div>

frontend/src/utils/chart_agg_ws_api.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { toDisplayPrice } from "./utils";
55

66
export interface RealtimeUpdate {
77
symbol: SYMBOL;
8-
buyPrice: number;
9-
sellPrice: number;
8+
bidPrice: number;
9+
askPrice: number;
1010
time: number;
1111
}
1212

@@ -37,7 +37,8 @@ export function processRealupdate(
3737
const k = key(trade.symbol, duration);
3838
let lastCandle = lastCandles[k];
3939

40-
const price = toDisplayPrice(trade.sellPrice);
40+
// Using askPrice (previously sellPrice) for candle price source
41+
const price = toDisplayPrice(trade.bidPrice);
4142
const bucketSize = getbucketsize(duration);
4243
const currentbucket = (Math.floor(trade.time / bucketSize) *
4344
bucketSize) as UTCTimestamp;

frontend/src/utils/price_store.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ function ensureInitialized() {
3232
const handler = (raw: unknown) => {
3333
const t = (raw || {}) as {
3434
symbol?: string;
35-
buyPrice?: number;
36-
sellPrice?: number;
35+
bidPrice?: number;
36+
askPrice?: number;
3737
};
3838
const base = String(t.symbol || "BTCUSDT").replace(
3939
"USDT",
@@ -43,8 +43,8 @@ function ensureInitialized() {
4343
const next: LivePrices = {
4444
...latestPrices,
4545
[base]: {
46-
bid: t.buyPrice ?? latestPrices[base].bid,
47-
ask: t.sellPrice ?? latestPrices[base].ask,
46+
bid: t.bidPrice ?? latestPrices[base].bid,
47+
ask: t.askPrice ?? latestPrices[base].ask,
4848
},
4949
};
5050
latestPrices = next;

http_server/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ async function startpriceuddate() {
4343
["BTC", "ETH", "SOL"].forEach(async (asset) => {
4444
await redis.subscribe(asset, (msg: string) => {
4545
const data = JSON.parse(msg);
46-
PRICESTORE[asset] = { ask: data.sellPrice, bid: data.buyPrice };
47-
checkOpenPositions(asset, { ask: data.sellPrice, bid: data.buyPrice });
46+
PRICESTORE[asset] = { ask: data.askPrice, bid: data.bidPrice };
47+
checkOpenPositions(asset, { ask: data.askPrice, bid: data.bidPrice });
4848
});
4949
});
5050
setInterval(() => {

price_poller/src/redisops.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export function pushToRedis(
2323
symbolmap[type],
2424
JSON.stringify({
2525
symbol: symbolmap[type],
26-
buyPrice: ask,
27-
sellPrice: bid,
26+
askPrice: ask,
27+
bidPrice: bid,
2828
decimals: 4,
2929
time: Math.floor(new Date(time).getTime() / 1000),
3030
}),

0 commit comments

Comments
 (0)