100 lines
3.4 KiB
Kotlin
100 lines
3.4 KiB
Kotlin
|
|
// src/main/kotlin/ui/AutoTradeSection.kt (신규 파일)
|
||
|
|
package ui
|
||
|
|
|
||
|
|
import AutoTradeItem
|
||
|
|
import androidx.compose.foundation.clickable
|
||
|
|
import androidx.compose.foundation.layout.*
|
||
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
||
|
|
import androidx.compose.foundation.lazy.items
|
||
|
|
import androidx.compose.material.*
|
||
|
|
import androidx.compose.material.icons.filled.Refresh
|
||
|
|
import androidx.compose.runtime.*
|
||
|
|
import androidx.compose.ui.Alignment
|
||
|
|
import androidx.compose.ui.Modifier
|
||
|
|
import androidx.compose.ui.graphics.Color
|
||
|
|
import androidx.compose.ui.text.font.FontWeight
|
||
|
|
import androidx.compose.ui.unit.dp
|
||
|
|
import androidx.compose.ui.unit.sp
|
||
|
|
import model.ActiveTradeItem
|
||
|
|
import model.ActiveTradeType
|
||
|
|
import network.KisTradeService
|
||
|
|
|
||
|
|
// src/main/kotlin/ui/AutoTradeSection.kt
|
||
|
|
|
||
|
|
@Composable
|
||
|
|
fun AutoTradeSection(
|
||
|
|
tradeService: KisTradeService,
|
||
|
|
refreshTrigger: Int, // 갱신 트리거 추가
|
||
|
|
onRefresh: () -> Unit,
|
||
|
|
onItemSelect: (ActiveTradeItem) -> Unit
|
||
|
|
) {
|
||
|
|
// 통합 리스트 상태 (ActiveTradeItem은 이전에 정의한 통합 모델)
|
||
|
|
var combinedList by remember { mutableStateOf(emptyList<ActiveTradeItem>()) }
|
||
|
|
|
||
|
|
// refreshTrigger가 바뀔 때마다 실행됨
|
||
|
|
LaunchedEffect(refreshTrigger) {
|
||
|
|
// 1. DB에서 감시 중인 종목 로드
|
||
|
|
val monitoringItems = DatabaseFactory.getActiveAutoTrades().map {
|
||
|
|
ActiveTradeItem(
|
||
|
|
id = it.code,
|
||
|
|
code = it.code,
|
||
|
|
name = it.name,
|
||
|
|
type = ActiveTradeType.MONITORING,
|
||
|
|
price = it.targetPrice,
|
||
|
|
quantity = "-",
|
||
|
|
isDomestic = it.isDomestic
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
// 2. KIS API에서 미체결 주문 로드
|
||
|
|
val unfilledItems = tradeService.fetchUnfilledOrders().getOrDefault(emptyList()).map {
|
||
|
|
ActiveTradeItem(
|
||
|
|
id = it.ord_no,
|
||
|
|
code = it.pdno,
|
||
|
|
name = it.prdt_name,
|
||
|
|
type = ActiveTradeType.UNFILLED,
|
||
|
|
price = it.ord_unpr.toDouble(),
|
||
|
|
quantity = it.rmnd_qty,
|
||
|
|
isDomestic = true
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
combinedList = monitoringItems + unfilledItems
|
||
|
|
}
|
||
|
|
|
||
|
|
Column(modifier = Modifier.fillMaxSize().padding(8.dp)) {
|
||
|
|
Row(
|
||
|
|
modifier = Modifier.fillMaxWidth(),
|
||
|
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||
|
|
verticalAlignment = Alignment.CenterVertically
|
||
|
|
) {
|
||
|
|
Text("진행 중인 거래", style = MaterialTheme.typography.subtitle1, fontWeight = FontWeight.Bold)
|
||
|
|
|
||
|
|
// 강제 갱신 버튼
|
||
|
|
IconButton(
|
||
|
|
onClick = onRefresh,
|
||
|
|
modifier = Modifier.size(24.dp)
|
||
|
|
) {
|
||
|
|
Icon(
|
||
|
|
imageVector = androidx.compose.material.icons.Icons.Default.Refresh,
|
||
|
|
contentDescription = "새로고침",
|
||
|
|
tint = Color(0xFF0E62CF),
|
||
|
|
modifier = Modifier.size(18.dp)
|
||
|
|
)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
LazyColumn {
|
||
|
|
items(combinedList) { item ->
|
||
|
|
ActiveTradeRow(
|
||
|
|
item = item,
|
||
|
|
onCancelClick = { orderNo ->
|
||
|
|
// tradeService.cancelOrder(orderNo, item.code) 호출 로직
|
||
|
|
},
|
||
|
|
onClick = {
|
||
|
|
onItemSelect(item) // 상세 화면 전환용 콜백
|
||
|
|
}
|
||
|
|
)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|