Class: DhanHQ::Skills::Builtin::CoveredCall
Overview
Skill to build a covered call strategy (buy 100 shares, sell 1 OTM call).
Steps: find equity instrument → spot price → option chain →
select OTM call strike → build intent.
Instance Method Summary
collapse
#call, description, #description, #name, param, #param_definitions, params, risk, scope, step, steps, validate_params!
Instance Method Details
#build_intent(ctx) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/DhanHQ/skills/builtin/covered_call.rb', line 68
def build_intent(ctx)
ctx[:intent] = {
trade_type: "COVERED_CALL",
symbol: ctx[:symbol],
quantity: ctx[:quantity],
legs: [
{ action: DhanHQ::Constants::TransactionType::BUY, instrument_type: DhanHQ::Constants::InstrumentType::EQUITY, security_id: ctx[:equity_security_id],
quantity: ctx[:quantity] },
{ action: DhanHQ::Constants::TransactionType::SELL, option_type: "CE", strike: ctx[:call_strike], security_id: ctx[:call_security_id], quantity: ctx[:quantity], premium: ctx[:call_premium] }
],
note: "Covered call prepared: Buy #{ctx[:quantity]} #{ctx[:symbol]}, Sell #{ctx[:quantity]} #{ctx[:call_strike]} CE. Await human confirmation."
}
ctx
end
|
#find_instrument(ctx) ⇒ Object
#get_option_chain(ctx) ⇒ Object
46
47
48
49
|
# File 'lib/DhanHQ/skills/builtin/covered_call.rb', line 46
def get_option_chain(ctx)
ctx[:chain] = ctx[:instrument].option_chain(expiry: ctx[:expiry])
ctx
end
|
#get_spot_price(ctx) ⇒ Object
41
42
43
44
|
# File 'lib/DhanHQ/skills/builtin/covered_call.rb', line 41
def get_spot_price(ctx)
ctx[:spot_price] = ctx[:instrument].ltp
ctx
end
|
#select_otm_call(ctx) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/DhanHQ/skills/builtin/covered_call.rb', line 51
def select_otm_call(ctx)
spot = ctx[:spot_price].to_f
chain = ctx[:chain]
offset_pct = ctx[:strike_offset] / 100.0
target_strike = spot * (1 + offset_pct)
otm_call = nearest_strike(chain, target_strike)
raise ArgumentError, "Could not find suitable OTM call strike near #{target_strike}" unless otm_call
ctx[:call_strike] = otm_call[:strike]
ctx[:call_security_id] = leg_security_id(otm_call, "CE")
ctx[:call_premium] = leg_premium(otm_call, "CE")
ctx[:equity_security_id] = ctx[:instrument].security_id
ctx
end
|