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

Include the calculator in the buy order #16

Open
manuelmazzuola opened this issue Feb 24, 2025 · 2 comments
Open

Include the calculator in the buy order #16

manuelmazzuola opened this issue Feb 24, 2025 · 2 comments

Comments

@manuelmazzuola
Copy link

Hi,
would be useful to include a calc in the buy order, for example i would like to buy using the 95% of my total equity, for example

buy MSFT (/ 95% MSFT) MKT

@mattsta
Copy link
Owner

mattsta commented Feb 24, 2025

Thanks for the note!

The next version does have calculator-in-buy-command (for price fields though, not the quantity field). I just haven't packaged all the new changes up into a clean release yet.

Here's an example of setting a limit price 5 under the current live quote with an automatic 3% take profit exit. Currently the percentage doesn't work in the calculator itself yet (percentages only work in the profit/loss bracket math), but it could probably be added.

live> buy /RTYH5 1 LIM @ (- live 5) + 3% preview
2025-02-24 13:10:25.015 | INFO     | icli.lang:run:2562 - [/RTYH5 1 LIM @ (- live 5) + 3% preview] Requesting: OrderIntent(symbol='/RTYH5', algo='LIM', exchange=None, spread=None, qty=DecimalLongShares('1'), bracketProfitAlgo='LMT', bracketLossAlgo='STP', limit='(- live 5)', bracketProfit=DecimalPercent('3'), bracketLoss=None, preview=True, config={}, scaleDesc=None)
2025-02-24 13:10:25.016 | INFO     | icli.lang:resolveCalculation:2607 - Resolving calculation request: (- live 5)
2025-02-24 13:10:25.017 | INFO     | icli.lang:currentBidAsk:2444 - FUT :: RTYH5:    bid 2,200.20 x 2.0    mid 2,200.20    ask 2,200.30 x 1.0    last 2,200.40 x 3.0    last trade 1.72 s    updated 0.58 s
2025-02-24 13:10:25.017 | INFO     | icli.lang:resolveCalculation:2654 - Replaced live placeholder with current midpoint: 2200.3
2025-02-24 13:10:25.017 | INFO     | icli.lang:resolveCalculation:2661 - Calculating: (- 2200.3 5)
2025-02-24 13:10:25.017 | INFO     | icli.lang:run:2910 - [LMT] Live calculation result: 2195.3
2025-02-24 13:10:25.017 | INFO     | icli.cli:placeOrderForContract:1714 - [RTY :: RTYH5] Using exchange: CME
2025-02-24 13:10:25.017 | INFO     | icli.cli:placeOrderForContract:1738 - [RTYH5] Request to order at dynamic qty 1.00 @ price 2,195.30
2025-02-24 13:10:25.017 | INFO     | icli.cli:placeOrderForContract:1974 - [LMT :: BUY] 1.00 @ $2,195.30 x 50 ($109,765.00) ALL_HOURS=False TIF=GTC
2025-02-24 13:10:25.017 | INFO     | icli.cli:whatIfPrepare:2248 - [RTYH5 :: QTY 1 :: PROFIT :: 36204] For preview query, converting: [transmit True] to False; [parentId 36203] to None
2025-02-24 13:10:25.018 | INFO     | icli.cli:whatIfPrepare:2248 - [RTYH5 :: QTY 1 ::  TRADE :: 36203] For preview query, converting: [transmit False] to False; [parentId 0] to None
2025-02-24 13:10:25.154 | INFO     | icli.cli:generatePreviewReport:2306 - [RTYH5 :: QTY 1 :: PROFIT] PREVIEW REQUEST Future(conId=672387509, symbol='RTY', lastTradeDateOrContractMonth='20250321', multiplier='50', exchange='CME', currency='USD', localSymbol='RTYH5', tradingClass='RTY') via ib_async.order.Order(
    orderId=36204,
    action='SELL',
    totalQuantity=1.0,
    orderType='LMT',
    lmtPrice=Decimal('2261.2'),
    tif='GTC',
    parentId=None
)
2025-02-24 13:10:25.155 | INFO     | icli.cli:generatePreviewReport:2306 - [RTYH5 :: QTY 1 :: TRADE] PREVIEW REQUEST Future(conId=672387509, symbol='RTY', lastTradeDateOrContractMonth='20250321', multiplier='50', exchange='CME', currency='USD', localSymbol='RTYH5', tradingClass='RTY') via ib_async.order.Order(
    orderId=36203,
    action='BUY',
    totalQuantity=1,
    orderType='LMT',
    lmtPrice=Decimal('2195.3'),
    tif='GTC',
    parentId=None

@manuelmazzuola
Copy link
Author

manuelmazzuola commented Feb 24, 2025

Great, maybe I’ll try to craft a PR for the quantity field after you pushed the changes.

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

No branches or pull requests

2 participants