Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
SeungGwan123 committed Nov 28, 2024
1 parent c801cf9 commit 74cb01e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
24 changes: 0 additions & 24 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,6 @@ http {
try_files $uri $uri/ /index.html;
}

location /api/upbit/orderbook {
proxy_pass http://api_servers;

proxy_http_version 1.1;
proxy_set_header Connection '';
proxy_buffering off;

proxy_connect_timeout 10s;
proxy_send_timeout 10s;
proxy_read_timeout 60s;
}

location /api/upbit/price-updates {
proxy_pass http://api_servers;

proxy_http_version 1.1;
proxy_set_header Connection '';
proxy_buffering off;

proxy_connect_timeout 10s;
proxy_send_timeout 10s;
proxy_read_timeout 60s;
}

location /api {
proxy_pass http://api_servers;
proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
Expand Down
24 changes: 24 additions & 0 deletions packages/server/src/upbit/SSE/sse.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ export class SseService implements OnModuleDestroy {
return coinData;
}

async initOrderStream(
coin: string[],
dto: (data: any) => any,
): Promise<MessageEvent> {
let coinLatestInfo = this.coinDataUpdaterService.getCoinOrderbookInfo();

while (!coinLatestInfo.size || !coinLatestInfo.get(coin)) {
await new Promise((resolve) => setTimeout(resolve, 100));
coinLatestInfo = this.coinDataUpdaterService.getCoinLatestInfo();
}

const initData = coinLatestInfo.get(coin);
initData.type = "orderbook"
initData.stream_type = "REALTIME"
initData.code = initData.market;

const dtoData = dto(initData)
delete dtoData.market;

return new MessageEvent('orderbook-update', {
data: JSON.stringify(dtoData),
});
}

getUpdatesStream(
type: 'price' | 'orderbook',
coins: string[],
Expand Down
10 changes: 9 additions & 1 deletion packages/server/src/upbit/upbit.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,20 @@ export class UpbitController {
@Query('coins') coinsQuery?: string[],
): Observable<MessageEvent> {
const coins = this.parseCoins(coinsQuery);

const initData$ = from(
this.sseService.initOrderStream(
coinsQuery,
this.coinListService.convertToOrderbookDto,
),
)

return this.sseService.getUpdatesStream(
const updatesStream = this.sseService.getUpdatesStream(
'orderbook',
coins,
this.coinListService.convertToOrderbookDto,
);
return concat(initData$, updatesStream)
}

@ApiOperation({
Expand Down

0 comments on commit 74cb01e

Please sign in to comment.