이익 실현 및 손실 제한
Take Profit Stop Loss(TPSL) 모듈은 특정 가격 조건이 충족될 때 자동으로 실행되는 conditional order를 가능하게 한다. 이를 통해 trader는 지속적인 모니터링 없이도 손실을 방지하는(stop loss) 또는 이익을 확정하는(take profit) 자동화된 trading strategy를 설정할 수 있다.
How TPSL works
- Create a condition: 지정된 trigger price보다 가격이 위로 올라가거나 아래로 내려갈 때 order가 trigger되어야 하는지 정의한다.
- Create a pending order: 조건이 충족될 때 배치될 order 세부 정보(limit order 또는 market order)를 지정한다.
- Add conditional order: condition과 pending order를 결합하고, 이를 margin manager에 추가한다.
- Execution: 누구나 permissionless
execute_conditional_orders함수를 호출해 condition이 충족된 order를 실행할 수 있다. 이는 일반적으로 시장을 모니터링하는 keeper 또는 bot이 처리한다.
conditional order는 효율적인 실행을 위해 정렬된 vector에 저장된다:
trigger_below: 가격이 trigger price 아래로 떨어질 때 trigger되는 order(높은 값에서 낮은 값 순으로 정렬)trigger_above: 가격이 trigger price 위로 올라갈 때 trigger되는 order(낮은 값에서 높은 값 순으로 정렬)
API
Helper functions
conditional order에 대한 condition과 pending order를 생성하려면 이 함수를 사용한다.
Create a condition
order가 언제 trigger되어야 하는지 지정하는 새 condition을 생성한다.
packages/deepbook_margin/sources/tpsl.move. You probably need to run `pnpm prebuild` and restart the site.Create a pending limit order
condition이 충족될 때 배치될 pending limit order를 생성한다. order type은 no_restriction 또는 immediate_or_cancel이어야 한다.
packages/deepbook_margin/sources/tpsl.move. You probably need to run `pnpm prebuild` and restart the site.Create a pending market order
condition이 충족될 때 배치될 pending market order를 생성한다.
packages/deepbook_margin/sources/tpsl.move. You probably need to run `pnpm prebuild` and restart the site.Manage conditional orders
이 함수들은 conditional order를 관리하기 위해 MarginManager에 노출되어 있다.
Add conditional order
conditional order를 margin manager에 추가한다. order는 condition이 충족될 때 배치된다. trigger condition이 현재 가격에 비해 유효한지 검증한다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.Cancel conditional order
ID로 특정 conditional order를 취소한다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.Cancel all conditional orders
margin manager에 대한 모든 conditional order를 취소한다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.Execute conditional orders
trigger된 conditional order를 실행한다. 이는 누구나 호출할 수 있는 permissionless 함수이다(일반적으로 keeper 또는 bot).
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.Read endpoints
packages/deepbook_margin/sources/tpsl.move. You probably need to run `pnpm prebuild` and restart the site.Events
ConditionalOrderAdded
conditional order가 margin manager에 추가될 때 발생한다.
packages/deepbook_margin/sources/tpsl.move. You probably need to run `pnpm prebuild` and restart the site.ConditionalOrderCancelled
conditional order가 취소될 때 발생한다.
packages/deepbook_margin/sources/tpsl.move. You probably need to run `pnpm prebuild` and restart the site.ConditionalOrderExecuted
conditional order가 실행될 때 발생한다.
packages/deepbook_margin/sources/tpsl.move. You probably need to run `pnpm prebuild` and restart the site.ConditionalOrderInsufficientFunds
fund가 충분하지 않아 conditional order를 실행할 수 없을 때 발생한다.
packages/deepbook_margin/sources/tpsl.move. You probably need to run `pnpm prebuild` and restart the site.