Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: Converging Trailing Stop via API
Nick
If you are going to be monitoring the position yourself you just have to change the price on the stop order - you don't have to cancel and submit a new one.
toggle quoted message
Show quoted text
Just send another PlaceOrder with everything the same as the original stop order except the new price. This will adjust the stop price. You might look into IB's algo order types, they might have something that would work and then it would be handled on IB's end. On 3/4/2022 12:05 AM, David Walker wrote:
Does anyone have experience in the mechanics of maintaining a converging trailing stop via the API? |
Converging Trailing Stop via API
Does anyone have experience in the mechanics of maintaining a converging trailing stop via the API??
I mean a stop where the trailing amount is wide at the start (to give a trade space to take hold) but then progressively reduces the trailing amount once the position becomes profitable, in order to protect the profit.? So, for example, a 25% trailing stop allows the trade to established, but then is reduced to, say, 20%, 15% and a minimum (say) 10% once the trade reaches certain profitability levels.? I think some people call it a tangential trailing stop. Theoretically, I would guess the mechanics via the API would be something like this (but looking for comment/correction!):
However, I'm not 100% sure of these mechanics and have these questions in my head:
I would love any comments from anyone with experience, or even just views, on this. |
Re: historical market data pacing violations are back?!
Nick
Isn't it just adding a function HistPacing() before each request?
toggle quoted message
Show quoted text
Inside HistPacing you can use a fixed delay to test things out, then move to keeping a list of the last 60 requests when you're back alive with the simple version. It's like 5 lines of code altogether. On 3/3/2022 7:31 PM, skee__bum via groups.io wrote:
or if I need to completely rewrite my code how it was previously. |
Re: historical market data pacing violations are back?!
> Did your violations ever go away?
I have not been pulling continuously today.? I completely restructured my code years ago when they implemented the throttling on their end.? With their changes today, my new code is totally fubar'd. So I'm left waiting to hear if this is a change they are reversing tomorrow...or if I need to completely rewrite my code how it was previously.? Thank you so much IB!!!! |
historical market data pacing violations are back?!
skee__bum, I'm OK but I'll try to keep an eye on it.? My logs show occasional data fetches that a taking a bit long, maybe one every 10 mins or so.? I'll try to check back in an hour or so.
Did your violations ever go away? Thanks, as always, and Be Well, Lou Dudka |
Re: historical market data pacing violations are back?!
Glad it's working again, Lou. We don't use historical data requests that often (pretty much never) and our code implements self-pacing. So we have not experienced any changes. Just checked our real-time data processor and no issues there. It received 210 million ticks since Sunday afternoon and shows no unusual behavior or errors. 闯ü谤驳别苍 |
Re: historical market data pacing violations are back?!
After getting passed around amongst various IB desks, they said they weren't aware of any changes, but they were seeing the errors on their end.? I provided them with log files and they are going to look into it.
So it doesn't SEEM like it was intentional...but how this gets re-introduced accidentally, I have no idea. IB is sometimes (frequently?) so bad at basic things.... |
historical market data pacing violations are back?!
Years ago, IB expected API users to pace their requests for HMD.? They then moved to a model whereby they paced their responses, and the API users didn't need to pace their calls.
But they seem to be back to requiring us to pace our requests.? Ugggghhhh.... Is everyone else seeing the same? |
Re: next valid id on initial connection
The TWS API is asynchronous by design and there is no guarantee as to the time it takes for a response to arrive after the corresponding request has been made. Under no circumstance should you ever use sleep to synchronize requests and responses. And while you are correct that many sample programs (even some from IBKR) frequently use sleep, it is completely wrong and dangerous to do so. If you do need to block your main thread until a callback for a request comes in (in your case nextOrderId), use one of the "wait/notify" mechanisms your programming language provides. For an example how you can do this in Python take a look at the i where Ewald de Wit provides both asynchronous as well as and synchronous (blocking) versions for each request. In your case, client.connect() blocks the caller (wait not sleep) until all callbacks related to the client connection request have taken place. We use Java and our request methods return that give the caller the option to treat the request as asynchronous (caller keeps on working on other tasks while the request is being processed) or synchronous (blocks the caller until the response arrives) or a combination of both. 闯ü谤驳别苍 |
next valid id on initial connection
this is my first topic in this gruop so ill start with something simple. even though its working I prefer to use the?nextValidID to make?sure the connction is?established but i didnt find any?example on how to?implement it testApp = IBApi()
? ? #connect on separet thred
? ? testApp.connect("127.0.0.1", 7496,1)
? ? t = threading.Thread(target=testApp.run, daemon=True)
? ? t.start()
? ? time.sleep(1)
should I write? ? ? testApp = IBApi()
? ? #connect on separet thred
? ? testApp.connect("127.0.0.1", 7496,1)
? ? t = threading.Thread(target=testApp.run, daemon=True)
? ? t.start()
? ? testApp.nextValidId(1)
i?should?overwrite or expand netxValidId or reqIds? or is that redundant? thank in advance |
Need "dummies" guide for interpreting accountSummary w/ margin trading
I'm pretty new to margin trading, and am still trying to wrap my head around how to exactly interpret accountSummary().?
Unfortunately, the documentation for it is a bit too terse for me:
Here's an example. On my paper trading account, I put in about $200K cash, then bought around $330K worth of stock. Here's what I get via accountSummary(): AccountType? ? ? ? ? ? ? ? ?INDIVIDUAL
Cushion? ? ? ? ? ? ? ? ? ? ? ? ? ?0.51
DayTradesRemaining? ? ? ? ? ? ? ?-1.00
LookAheadNextChange? ? ? ? ? ? ? ?0.00
AccruedCash? ? ? ? ? ? ? ? ? ? ? ?0.00
AvailableFunds? ? ? ? ? ? ? ?93,611.10
BuyingPower? ? ? ? ? ? ? ? ?374,444.40
EquityWithLoanValue? ? ? ? ?202,012.37
ExcessLiquidity? ? ? ? ? ? ?103,289.66
FullAvailableFunds? ? ? ? ? ?93,611.10
FullExcessLiquidity? ? ? ? ?103,289.66
FullInitMarginReq? ? ? ? ? ?108,401.27
FullMaintMarginReq? ? ? ? ? ?98,722.71
GrossPositionValue? ? ? ? ? 331,165.19
InitMarginReq? ? ? ? ? ? ? ?108,401.27
LookAheadAvailableFunds? ? ? 93,611.10
LookAheadExcessLiquidity? ? 103,289.66
LookAheadInitMarginReq? ? ? 108,401.27
LookAheadMaintMarginReq? ? ? 98,722.71
MaintMarginReq? ? ? ? ? ? ? ?98,722.71
NetLiquidation? ? ? ? ? ? ? 202,012.37
SMA? ? ? ? ? ? ? ? ? ? ? ? ? 36,770.38
TotalCashValue? ? ? ? ? ? ?-129,152.82
Can someone give me a "dummies guide" on the following questions: 1. Exactly what conditions shown in accountSummary would cause IB to start dumping my stock to meet margin requirements? My best guess is that if?EquityWithLoanValue?goes below MaintMarginReq, that is when the dumping will begin. So basically, I just want to keep an eye on?EquityWithLoanValue?and make sure it stays well above?MaintMarginReq. Is this correct? |
Re: How to get real time data for INDEX and FUTURES using TWS API reqMktData()?
Example of the minimum fields to set for a march ZB futures contract: ? ? With lContractInfo ? ? ? ? .symbol = "" ? ? ? ? .secType = "FUT" ? ? ? ? .lastTradeDateOrContractMonth = "" ? ? ? ? .Strike = 0 ? ? ? ? .Right = "" ? ? ? ? .multiplier = "" ? ? ? ? .Exchange = "ECBOT" ? ? ? ? .primaryExchange = "" ? ? ? ? .currency = "USD" ? ? ? ? .localSymbol = "ZB ? MAR 22" ? ? ? ? .conId = 0 ? ? End With You could also set the Symbol = "ZB" and the lastTradeDateOrContractMonth = "202203" instead of the localSymbol El mié, 2 mar 2022 a las 6:39, Tareq Naushad (<tareq_ifti@...>) escribió: Hi, |
Re: One cancel all, trailing stop loss OR exit on close
And you should have no problem figuring that out with the complete example rajeshh_98 provided and after rereading the TWS API Reference on and
toggle quoted message
Show quoted text
闯ü谤驳别苍 On Wed, Mar 2, 2022 at 12:23 PM, <omgwtfsalty@...> wrote:
ahh this is helpful but I need to use the tws api.? |