Skip to content

Commit

Permalink
[Add] 미체결 거래 체결 정보 수신 관련 커스텀훅 생성
Browse files Browse the repository at this point in the history
- 거래량 부재로 미체결 처리된 주문이 서버 데이터 갱신에 따라 체결처리 되었을 때 해당 정보를 서버로 부터 GET 하는 로직 구현
- 컴포넌트에 적용하여 fetching 테스트 진행 예정

Issues #122
  • Loading branch information
novice1993 committed Sep 18, 2023
1 parent e48e4bf commit 25d4d1b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions client/src/hooks/useGetWaitOrderSuccessInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useQuery, useQueryClient } from "react-query";
import axios from "axios";

const url = "http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com:8080/long-polling/listen";

const useGetWaitOrderSuccessInfo = () => {
const queryClient = useQueryClient();

const { data, isLoading, isError, refetch } = useQuery("waitOrderSuccess", getWaitOrderSuccessInfo, {
onSuccess: (data) => {
queryClient.invalidateQueries("cash");
queryClient.invalidateQueries("holdingStock");
queryClient.invalidateQueries("orderRecord");
refetch();
console.log("예약주문 처리 테스트");
console.log(data);
},
});

return { waitOrderSuccessData: data, waitOrderSuccessLoading: isLoading, waitOrderSuccessError: isError };
};

export default useGetWaitOrderSuccessInfo;

const getWaitOrderSuccessInfo = async () => {
const accessToken = localStorage.getItem("accessToken");
const options = {
headers: {
Authorization: `${accessToken}`,
"Content-Type": "application/json",
},
};

const response = await axios.get(url, options);
const orderInfo = await response.data;
return orderInfo;
};

0 comments on commit 25d4d1b

Please sign in to comment.