How to perform batch-trading using Interactive Broker API?
How to perform batch-trading using Interactive Broker API?
Loading saved threads...
user2979010 · External communityPost link
External question — Quantitative Finance Stack Exchange
Author: user2979010
Original post: https://quant.stackexchange.com/questions/26267
License: CC BY-SA 3.0 — https://creativecommons.org/licenses/by-sa/3.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
My definition of batch-trading: Given $N$ BUY orders, $M$ SELL orders and $O$ ($O < N$) as the max number of open positions to be held. Batch-trading should monitor the orders and when $O$ BUY orders are filled it would cancel the $N-O$ BUY Orders.
To perform this, below is the pseudo-code:
for every PositionMessage that comes in:
if number_of_filled_openpositions >= Max:
// cancel is performed only ONCE, I set a "flag" to make sure
// cancel is called only once during this entire process
cancel_unfilled_BUY_orders_one_by_one()
// OpenPositions have a TimeUpdated field,
// Sell order will be generated starting from the last filled orders
// Sell order is generated only after the position is fully filled
Sell_excess_filled_orders()
The problem I am facing now is, depending on the day, I might get
correct
number of cancellations and
correct
number of excess_positions_sold. But on other days, I sometimes run into
max number of messages exceeds limit..
or
remote host forcibly disconnected your connection
or incorrect number of cancellation or excess_filled_sold.
I have tried introducing a
time-delay
within
cancel_unfilled_BUY_orders_one_by_one()
so that each cancel order is sent after a time-delay.
I am finding it hard to debug because I need the market-to-be-open to test exhaustively, which is 00:00 (midnight) for me and on weekends the markets are not open (this is a hobby project).
What else should I consider? what am I missing? Has anyone else tried doing something similar?
Happy to elaborate more if required.
Quote
Report
hui · External communityPost link
External answer — Quantitative Finance Stack Exchange
Author: hui
Original post: https://quant.stackexchange.com/a/32088
License: CC BY-SA 3.0 — https://creativecommons.org/licenses/by-sa/3.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Interactive Brokers posted a webinar on Dec 13 2016 about using IBridgePy to connect to IB's API.
https://www.youtube.com/watch?v=hogXB07OJ_I
. It is pretty easy to solve the problem you mentioned. You may check out the website of IBridgePy at www.IBridgePy.com To learn how to use it, you may refer to its documentation.
Quote
Report
Post Reply
Checking account access…