-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 주식 매수/매도 관련 서버 통신 로직 작성 후 적용하였으나 오류 발생하는 상황 (500 Error) - BE 담당자와 소통하여 문제 해결할 예정 Issues #17
- Loading branch information
1 parent
c8c8779
commit bbbd055
Showing
3 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useSelector } from "react-redux"; | ||
import { StateProps } from "../models/stateProps"; | ||
import { useMutation } from "react-query"; | ||
import axios from "axios"; | ||
|
||
const useTradeStock = () => { | ||
const orderType = useSelector((state: StateProps) => state.stockOrderType); | ||
const companyId = useSelector((state: StateProps) => state.companyId); | ||
const orderPrice = useSelector((state: StateProps) => state.stockOrderPrice); | ||
const orderVolume = useSelector((state: StateProps) => state.stockOrderVolume); | ||
|
||
const orderRequest = useMutation(() => postOrderRequest(orderType, companyId, orderPrice, orderVolume)); | ||
return orderRequest; | ||
}; | ||
|
||
export default useTradeStock; | ||
|
||
const postOrderRequest = async (orderType: boolean, companyId: number, price: number, volume: number) => { | ||
const authToken = localStorage.getItem("authToken"); | ||
console.log(authToken); | ||
const options = { | ||
headers: { | ||
Authorization: `${authToken}`, | ||
"Content-Type": "application/json", | ||
}, | ||
}; | ||
|
||
// 매수 | ||
if (!orderType) { | ||
const response = await axios.post(`http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com:8080/stock/buy?companyId=${companyId}&price=${price}&stockCount=${volume}`, {}, options); | ||
const orderResult = await response.data; | ||
|
||
console.log(orderResult); // 테스트 코드 | ||
return orderResult; | ||
} | ||
|
||
// 매도 | ||
if (orderType) { | ||
const response = await axios.post(`http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com:8080/stock/sell?companyId=${companyId}&price=${price}&stockCount=${volume}`, {}, options); | ||
const orderResult = await response.data; | ||
|
||
console.log(orderResult); // 테스트 코드 | ||
return orderResult; | ||
} | ||
}; |