Class: Tda::Order
Constant Summary collapse
- STATUS_FILLED =
'FILLED'- STATUS_REPLACED =
'REPLACED'- STATUS_WORKING =
'WORKING'
Class Method Summary collapse
- .check_status(order_id) ⇒ Object
-
.get_account_hash ⇒ Object
not used - the hash is stored.
- .place_order(query) ⇒ Object
- .roll_covered_call_q(pos) ⇒ Object
- .roll_short_credit_call_spread_q(pos) ⇒ Object
Class Method Details
.check_status(order_id) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/tda/order.rb', line 12 def self.check_status order_id profile = Wco::Profile.pi results = self.get("/accounts/#{profile.schwab_account_hash}/orders/#{order_id}", { headers: { accept: 'application/json', Authorization: "Bearer #{profile[:schwab_exec_access_token]}", }, }) puts! results, 'results' return results end |
.get_account_hash ⇒ Object
not used - the hash is stored
25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/tda/order.rb', line 25 def self.get_account_hash profile = Wco::Profile.find_by email: 'piousbox@gmail.com' results = self.get("/accounts/accountNumbers", { headers: { accept: 'application/json', Authorization: "Bearer #{profile[:schwab_exec_access_token]}", }, } ) puts! results, 'results' end |
.place_order(query) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/models/tda/order.rb', line 119 def self.place_order query puts! query, '#place_order' profile = Wco::Profile.pi results = self.post("/accounts/#{profile.schwab_account_hash}/orders", { headers: { 'content-type' => 'application/json', accept: 'application/json', Authorization: "Bearer #{profile[:schwab_exec_access_token]}", }, body: query.to_json, }) order_id = results.headers['location'].split('/').last return order_id end |
.roll_covered_call_q(pos) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/models/tda/order.rb', line 36 def self.roll_covered_call_q pos roll_price = pos.inner.begin_price - pos.autoprev.inner.end_price query = { orderType: "NET_CREDIT", ## pos.roll_price > 0 ? "NET_CREDIT" : "NET_DEBIT", session: "NORMAL", duration: "DAY", price: ( roll_price + 100 ).to_s, ## _TODO this order will never fill (net credit only) orderStrategyType: "SINGLE", orderLegCollection: [ ## close { instruction: "BUY_TO_CLOSE", quantity: pos.q, instrument: { symbol: pos.autoprev.inner.symbol, assetType: "OPTION", }, }, ## open { instruction: "SELL_TO_OPEN", quantity: pos.q, instrument: { symbol: pos.inner.symbol, assetType: "OPTION", }, }, ], } # puts! query, 'query' return query end |
.roll_short_credit_call_spread_q(pos) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/models/tda/order.rb', line 70 def self.roll_short_credit_call_spread_q pos query = { orderType: "NET_CREDIT", ## pos.roll_price > 0 ? "NET_CREDIT" : "NET_DEBIT", session: "NORMAL", duration: "DAY", price: ( pos.roll_price + 100 ).to_s, ## _TODO this order will never fill (net credit only) orderStrategyType: "SINGLE", orderLegCollection: [ ## close { instruction: "BUY_TO_CLOSE", quantity: pos.q, instrument: { symbol: pos.autoprev.inner.symbol, assetType: "OPTION", }, }, { instruction: "SELL_TO_CLOSE", quantity: pos.q, instrument: { symbol: pos.autoprev.outer.symbol, assetType: "OPTION", }, }, ## open { instruction: "BUY_TO_OPEN", quantity: pos.q, instrument: { symbol: pos.outer.symbol, assetType: "OPTION", }, }, { instruction: "SELL_TO_OPEN", quantity: pos.q, instrument: { symbol: pos.inner.symbol, assetType: "OPTION", }, }, ], } # puts! query, 'query' return query end |