mattsta / icli

interactive brokers ibkr api command line interface cli giving you the fastest way to lose all your money
Other
84 stars 19 forks source link

Can you add BUY SELL buttons #7

Closed MethAddicted closed 3 months ago

mattsta commented 3 months ago

yeah, the README needs a complete rewrite to match all the updates over the past couple years, but the commands are there:

live> buy?
2024-03-21 07:15:47.911 | INFO     | mutil.dispatch:printhelp:283 - Command: buy [symbol] [total] [algo] [*preview]
2024-03-21 07:15:47.912 | INFO     | mutil.dispatch:printhelp:292 - buy :: Quick order entry with full order described on command line.
2024-03-21 07:15:47.912 | INFO     | icli.cli:dorepl:3065 - [buy?] Duration: 0.0022

So you can do things like:

# buy $10,000 worth of MSFT shares using the "Limit Adaptive Fast Urgent" order type
> buy MSFT $10_000 AF preview

# buy 100 shares of MSFT
> buy MSFT 100 AF preview

# Buy $1 million worth of AAPL using the MIDPRICE order type
> buy AAPL $1_000_000 MID preview # though, "preview" doesn't work for MID orders due to IBKR

# Sell 100 shares of MSFT using "Limit Adaptive Slow" order type
> buy MSFT -100 AS preview

# Sell $1 million of MSFT
> buy MSFT -$1_000_000 AS preview

# Sell 2 SPY puts at current prices
> buy SPY240321P00525000 -2 AF preview

Those orders will execute immediately (when "preview" is removed) and they auto-calculate the order quantity when using $price syntax or they use the direct share count when using only numbers for amounts. Negative dollar amounts and negative share counts are executed as sell/short transactions even though the command is called buy.

You can also use the evict command to remove a position at current market prices, but it's equivalent to buy X -QUANTITY MID based on how much you are holding for a position (evict MSFT -1 0 for a single position or evict * -1 0 to close every position in your portfolio (sells longs, buys shorts)).

You can also use the limit command for menu-based ordering and manually setting the price you want (the buy command doesn't let you pick a price, it automatically uses walking midpoints of the current bid/ask spread to place your order until filled).

If you want to stop a resting order, you can use cancel * to cancel all orders or cancel to view a menu of orders to select (spacebar) then cancel one or more orders at the same time.

You can view all orders with orders. You can view all your positions with either positions or ls.