feat: add Algo Order API support and update ML feature handling

- Introduced support for Algo Order API, allowing automatic sending of STOP_MARKET and TAKE_PROFIT_MARKET orders.
- Updated README.md to include new features related to Algo Order API and real-time handling of ML features.
- Enhanced ML feature processing to fill missing OI and funding rate values with zeros for consistency in training data.
- Added new training log entries for the lgbm model with updated metrics.
This commit is contained in:
21in7
2026-03-02 02:03:50 +09:00
parent c89374410e
commit 684c8a32b9
4 changed files with 58 additions and 1 deletions

View File

@@ -45,6 +45,8 @@ class BinanceFuturesClient:
return float(b["balance"])
return 0.0
_ALGO_ORDER_TYPES = {"STOP_MARKET", "TAKE_PROFIT_MARKET", "STOP", "TAKE_PROFIT", "TRAILING_STOP_MARKET"}
async def place_order(
self,
side: str,
@@ -55,6 +57,16 @@ class BinanceFuturesClient:
reduce_only: bool = False,
) -> dict:
loop = asyncio.get_event_loop()
if order_type in self._ALGO_ORDER_TYPES:
return await self._place_algo_order(
side=side,
quantity=quantity,
order_type=order_type,
stop_price=stop_price,
reduce_only=reduce_only,
)
params = dict(
symbol=self.config.symbol,
side=side,
@@ -75,6 +87,34 @@ class BinanceFuturesClient:
logger.error(f"주문 실패: {e}")
raise
async def _place_algo_order(
self,
side: str,
quantity: float,
order_type: str,
stop_price: float = None,
reduce_only: bool = False,
) -> dict:
"""STOP_MARKET / TAKE_PROFIT_MARKET 등 Algo Order API(/fapi/v1/algoOrder)로 전송."""
loop = asyncio.get_event_loop()
params = dict(
symbol=self.config.symbol,
side=side,
algoType="CONDITIONAL",
type=order_type,
quantity=quantity,
reduceOnly="true" if reduce_only else "false",
)
if stop_price:
params["triggerPrice"] = stop_price
try:
return await loop.run_in_executor(
None, lambda: self.client.futures_create_algo_order(**params)
)
except BinanceAPIException as e:
logger.error(f"Algo 주문 실패: {e}")
raise
async def get_position(self) -> dict | None:
loop = asyncio.get_event_loop()
positions = await loop.run_in_executor(

View File

@@ -127,4 +127,8 @@ def build_features(
"xrp_eth_rs": float(_calc_rs(ret_1, eth_ret_1)),
})
# 실시간에서는 OI/펀딩비를 수집하지 않으므로 0으로 채워 학습 피처(23개)와 일치시킨다
base.setdefault("oi_change", 0.0)
base.setdefault("funding_rate", 0.0)
return pd.Series(base)