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