Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add create_bracket_order() #14

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

add create_bracket_order() #14

wants to merge 4 commits into from

Conversation

flare9x
Copy link
Contributor

@flare9x flare9x commented Jun 11, 2023

extend existing create_order_params() to include simple, bracket, oco or oto orders. note embedded Dict() within Dict() within JSON body for the extra price fields.

@flare9x
Copy link
Contributor Author

flare9x commented Jun 11, 2023

bracket order:
image

Copy link
Owner

@dm13450 dm13450 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, couple of minor things

"extended_hours" => extended_hours,
"order_class" => order_class,
"take_profit" => Dict("limit_price" => tp_limit_price),
"stop_loss" => Dict("stop_price" => sl_stop_price, "limit_price" => sl_limit_price))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error is thrown as these aren't passed into the function.
They don't need to be passed into the function, the tp/sl params are used in the bracket function.
Also duplication of code

Copy link
Contributor Author

@flare9x flare9x Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will check - intention was if order_class=nothing it was the normal orders up to this point and if it was specified then would revert to the ifelse statement in the function. order_class="bracket" along with an assertion in utils : @assert order_class in ["simple", "bracket", "oco ", "oto"] "valid order class :: simple, bracket, oco, oto". i did this so that we could do a dict within dict for the tp,sl of these order types. i will verify what happened here. ok i realized where the error was solved see below.

Copy link
Contributor Author

@flare9x flare9x Jul 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create_order_params() repaired and now should be able to extend to "bracket", "oco ", "oto"

Copy link
Contributor Author

@flare9x flare9x Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

create_bracket_order(symbol="AAPL", side = "buy", qty = 1, time_in_force = "day", type = "limit", limit_price = 196.00, tp_limit_price=196.10, sl_stop_price=194.00, sl_limit_price = 193.60)

for brackets tested a few ways of executing the 'parent' order - market, limit and stop limit.

enter with limit order using bracket.

image

and if wish to enter on a stop limit bracket order::

create_bracket_order(symbol="AAPL", side = "buy", qty = 1, time_in_force = "day", type = "stop_limit", limit_price = 196.00, stop_price = 196.10, tp_limit_price=196.50, sl_stop_price=194.00, sl_limit_price = 193.60)

image

  "qty"            => 1
  "extended_hours" => false
  "limit_price"    => 196.0
  "symbol"         => "AAPL"
  "stop_loss"      => Dict("limit_price"=>193.6, "stop_price"=>194.0)
  "take_profit"    => Dict("limit_price"=>196.5)
  "order_class"    => "bracket"
  "stop_price"     => 196.1
  "side"           => "buy"
  "time_in_force"  => "day"
  "type"           => "stop_limit"

src/positions.jl Outdated
@@ -36,7 +36,7 @@ function get_positions(symbol::String)::DataFrame
return resdf
end

function get_positions()::DataFrame
function get_all_positions()::DataFrame
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need two function names to do the same thing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k intent was to cater to ALL positions as well as a singular symbol.

https://alpaca.markets/docs/api-references/trading-api/positions/

image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can see they do different things but we can overload one function to do both things, get_positions() and get_positions("BTCUSD") both work as intended

@codecov-commenter
Copy link

Codecov Report

Merging #14 (888b679) into main (0787330) will decrease coverage by 7.34%.
The diff coverage is 60.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main      #14      +/-   ##
==========================================
- Coverage   44.37%   37.03%   -7.34%     
==========================================
  Files          13       13              
  Lines         311      324      +13     
==========================================
- Hits          138      120      -18     
- Misses        173      204      +31     
Files Changed Coverage Δ
src/positions.jl 0.00% <ø> (ø)
src/orders.jl 12.90% <33.33%> (+2.18%) ⬆️
src/utils.jl 59.74% <100.00%> (-20.86%) ⬇️

... and 5 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@flare9x flare9x requested a review from dm13450 August 9, 2023 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants