auto: 일일 백업 2026-07-22 02:00
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -156,21 +156,37 @@ def collect_market_data(account_label: str, symbol: str, side: str, qty: int) ->
|
||||
'stock_meta': stock_meta,
|
||||
}
|
||||
|
||||
try:
|
||||
open_orders = kc.get_open_orders(account_label)
|
||||
except Exception:
|
||||
open_orders = []
|
||||
|
||||
if side == 'BUY':
|
||||
try:
|
||||
bal = kc.get_balance(account_label)
|
||||
md['balance_d2'] = _to_int(bal.get('d2_entra'))
|
||||
d2 = _to_int(bal.get('d2_entra'))
|
||||
# d2_entra는 미체결 매수 지정가로 묶인 예수금을 아직 포함 → 실제 가용액에서 차감.
|
||||
locked = sum(_to_int(o.get('order_price')) * _to_int(o.get('unfilled_qty'))
|
||||
for o in open_orders
|
||||
if o.get('side') == 'BUY' and _to_int(o.get('order_price')) > 0)
|
||||
md['balance_d2'] = max(0, d2 - locked)
|
||||
except Exception:
|
||||
md['balance_d2'] = 0
|
||||
else:
|
||||
try:
|
||||
positions = kc.get_positions(account_label)
|
||||
md['position_qty'] = next(
|
||||
(_to_int(p.get('trde_able_qty') or p.get('qty') or p.get('hold_qty') or p.get('rmnd_qty'))
|
||||
for p in positions
|
||||
if (p.get('code') == symbol) or (p.get('symbol') == symbol) or (p.get('stk_cd') == symbol)),
|
||||
0,
|
||||
)
|
||||
pos = next((p for p in positions
|
||||
if (p.get('code') == symbol) or (p.get('symbol') == symbol) or (p.get('stk_cd') == symbol)),
|
||||
None)
|
||||
if pos:
|
||||
hold = _to_int(pos.get('qty') or pos.get('hold_qty') or pos.get('rmnd_qty'))
|
||||
trde_able = _to_int(pos.get('trde_able_qty') or hold)
|
||||
pend_sell = sum(_to_int(o.get('unfilled_qty')) for o in open_orders
|
||||
if o.get('side') == 'SELL' and o.get('code') == symbol)
|
||||
# trde_able이 미체결 매도 제외 여부 불확실 → min으로 이중차감 방지 (check 핸들러와 동일).
|
||||
md['position_qty'] = max(0, min(trde_able, hold - pend_sell))
|
||||
else:
|
||||
md['position_qty'] = 0
|
||||
except Exception:
|
||||
md['position_qty'] = 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user