Skip to content

Commit

Permalink
[Feat] 주식주문 거래 발생 시 관련 데이터 업데이트 기능 추가
Browse files Browse the repository at this point in the history
- 매도/매수 발생 시 보유 현금 및 최대 매도가능 주식 수 갱신되도록 기능 구현

Issues #17
  • Loading branch information
novice1993 committed Sep 13, 2023
1 parent 015e94d commit 95a63df
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions client/src/components/StockOrderSection/StockOrder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ const StockOrder = ({ corpName }: { corpName: string }) => {

// 주문 실패 케이스 1) 개장시간 2) 가격/거래량 설정
// 🔴 3시 30분 이후 작업 위해 closingTime 조건 해제
// const orderFailureCase01 = nonBusinessDay;
const orderFailureCase01 = nonBusinessDay || closingTime;
const orderFailureCase01 = nonBusinessDay;
// const orderFailureCase01 = nonBusinessDay || closingTime;
const orderFailureCase02 = orderPrice === 0 || orderVolume === 0;

return (
Expand Down
2 changes: 1 addition & 1 deletion client/src/hooks/useGetStockOrderRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const url = "http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com:8080

const useGetStockOrderRecord = () => {
const isLogin = useSelector((state: StateProps) => state.login);
const { data, isLoading, isError } = useQuery("record", getOrderRecord, {
const { data, isLoading, isError } = useQuery("orderRecord", getOrderRecord, {
enabled: isLogin === 1,
});

Expand Down
11 changes: 9 additions & 2 deletions client/src/hooks/useTradeStock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSelector } from "react-redux";
import { StateProps } from "../models/stateProps";
import { useMutation } from "react-query";
import { useMutation, useQueryClient } from "react-query";
import axios from "axios";

const useTradeStock = () => {
Expand All @@ -9,7 +9,14 @@ const useTradeStock = () => {
const orderPrice = useSelector((state: StateProps) => state.stockOrderPrice);
const orderVolume = useSelector((state: StateProps) => state.stockOrderVolume);

const orderRequest = useMutation(() => postOrderRequest(orderType, companyId, orderPrice, orderVolume));
const queryClient = useQueryClient();
const orderRequest = useMutation(() => postOrderRequest(orderType, companyId, orderPrice, orderVolume), {
onSuccess: () => {
queryClient.invalidateQueries("cash");
queryClient.invalidateQueries("holdingStock");
queryClient.invalidateQueries("orderRecord");
},
});
return orderRequest;
};

Expand Down

0 comments on commit 95a63df

Please sign in to comment.