Skip to content

Commit

Permalink
♻️ refactor: 주가 정보 관련 interface 생성 및 적용 #6
Browse files Browse the repository at this point in the history
  • Loading branch information
sieunie committed Nov 6, 2024
1 parent 335686b commit 6aafebe
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 6 deletions.
74 changes: 71 additions & 3 deletions BE/src/stock/index/stock.index.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class StockIndexService {
},
});

const result = await response.json();
const result: StockIndexChartInterface = await response.json();

return new StockIndexListElementDto(
code,
Expand Down Expand Up @@ -73,7 +73,7 @@ export class StockIndexService {
},
});

const result = await response.json();
const result: StockIndexValueInterface = await response.json();
return new StockIndexValueElementDto(
code,
result.output.bstp_nmix_prpr,
Expand All @@ -97,7 +97,7 @@ export class StockIndexService {
appsecret: process.env.APP_SECRET,
}),
});
const result = await response.json();
const result: AccessTokenInterface = await response.json();
this.accessToken = result.access_token;
this.expireDateTime = new Date(
result.access_token_token_expired,
Expand All @@ -108,3 +108,71 @@ export class StockIndexService {
return this.accessToken;
}
}

// interfaces

interface AccessTokenInterface {
access_token: string;
access_token_token_expired: string;
token_type: string;
expires_in: number;
}

interface StockIndexChartInterface {
output: StockIndexChartElementInterface[];
}

interface StockIndexChartElementInterface {
bsop_hour: string;
bstp_nmix_prpr: string;
bstp_nmix_prdy_vrss: string;
prdy_vrss_sign: string;
bstp_nmix_prdy_ctrt: string;
acml_tr_pbmn: string;
acml_vol: string;
cntg_vol: string;
}

interface StockIndexValueInterface {
output: {
bstp_nmix_prpr: string;
bstp_nmix_prdy_vrss: string;
prdy_vrss_sign: string;
bstp_nmix_prdy_ctrt: string;
acml_vol: string;
prdy_vol: string;
acml_tr_pbmn: string;
prdy_tr_pbmn: string;
bstp_nmix_oprc: string;
prdy_nmix_vrss_nmix_oprc: string;
oprc_vrss_prpr_sign: string;
bstp_nmix_oprc_prdy_ctrt: string;
bstp_nmix_hgpr: string;
prdy_nmix_vrss_nmix_hgpr: string;
hgpr_vrss_prpr_sign: string;
bstp_nmix_hgpr_prdy_ctrt: string;
bstp_nmix_lwpr: string;
prdy_clpr_vrss_lwpr: string;
lwpr_vrss_prpr_sign: string;
prdy_clpr_vrss_lwpr_rate: string;
ascn_issu_cnt: string;
uplm_issu_cnt: string;
stnr_issu_cnt: string;
down_issu_cnt: string;
lslm_issu_cnt: string;
dryy_bstp_nmix_hgpr: string;
dryy_hgpr_vrss_prpr_rate: string;
dryy_bstp_nmix_hgpr_date: string;
dryy_bstp_nmix_lwpr: string;
dryy_lwpr_vrss_prpr_rate: string;
dryy_bstp_nmix_lwpr_date: string;
total_askp_rsqn: string;
total_bidp_rsqn: string;
seln_rsqn_rate: string;
shnu_rsqn_rate: string;
ntby_rsqn: string;
};
rt_cd: string;
msg_cd: string;
msg1: string;
}
15 changes: 12 additions & 3 deletions BE/src/websocket/socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ export class SocketService implements OnModuleInit {
};

this.socket.onmessage = (event) => {
const data = event.data.toString().split('|');
const data =
typeof event.data === 'string'
? event.data
: JSON.stringify(event.data);
if (data.length < 2) return;

this.tradeHandler[data[1]](data[3]);
(this.tradeHandler[data[1]] as (data) => void)(data[3]);
};
}

Expand Down Expand Up @@ -58,7 +61,7 @@ export class SocketService implements OnModuleInit {
secretkey: process.env.APP_SECRET,
}),
});
const result = await response.json();
const result: SocketConnectTokenInterface = await response.json();
return result.approval_key;
}

Expand All @@ -81,3 +84,9 @@ export class SocketService implements OnModuleInit {
);
}
}

// interfaces

interface SocketConnectTokenInterface {
approval_key: string;
}

0 comments on commit 6aafebe

Please sign in to comment.