HOME FORUMS BROKERS SOFTWARE BOOKS CONTACT US
Elite Trader Your Account  •  Become a Member  •  Help  •  Search    
    Forums ›› Technically Speaking ›› Programming ›› IB API Close all Positions  


Post A Reply
    Page 1 of 4:   1  2  3  4  
Mike805
 

Registered: Jul 2004
Posts: 1768

 

08-21-12 07:03 PM

Hello,

I'm sure this has been requested before (and likely posted elsewhere); my question is about getting flat by end of day given a variety of circumstances.

1. Is anyone willing to share some code (VBA possibly) that will close all positions when run (a starting point for this discussion that I can provide - it won't be pretty however as I'm not a very good programmer)?

2. Can we start a discussion regarding the risks associated with such code and how to program around those risks:
- For example: data disconnection and subsequent redundant checks upon reconnect to make sure the account will be flat.
- S/W crash (not in IB's side) where the program can recover gracefully and guarantee the account is flat.

I realize that if IB servers are down, there's nothing one can do... my question is aimed at a more general issue of never getting stuck in anything overnight. Whether the solution is programmable, or, something else entirely (broker request, auto-liquidation etc).

Mike

    Edit/Delete Quote Complain
Bob111
 

Registered: May 2002
Posts: 6422

 

08-21-12 07:28 PM

http://finance.groups.yahoo.com/group/TWSAPI/

i have it some where,but it was for older API version. like 9.4. basically-you request list of your positions,avg.prices, Qty and side. then- get a market data,make sure there is no crazy spreads and stuff like that. and you place an orders. or maybe there is a command now-liquidate all at whatever prices. bots will have a field day over this one.

    Edit/Delete Quote Complain
2rosy
 

Registered: May 2012
Posts: 336

 

08-21-12 08:15 PM

request positions

in callback close the position

    Edit/Delete Quote Complain
tradelink
 

Registered: Feb 2008
Posts: 577

 

08-22-12 05:40 PM

in tradelink you would do something like :

code:
public class MyFlatAtClose : ResponseTemplate { int shutdownat = 155500; bool shutdown = true; override void GotTick(Tick k) { if (shutdown && (k.time>=shutdownat)) { shutdown = false; foreach (var p in pt) sendorder(new MarketOrderFlat(p)); } } PositionTracker pt = new PositionTracker(); override void GotPosition(Position p) { pt.Adjust(p); } override void GotFill(Trade f) { pt.Adjust(t); } }


reconnections occur automatically unless you disable them.

for making sure problems in your own code/modules don't impact the shutdown routine, ensure you have exception handling setup so those errors aren't fatal and recover (or recover at least enough to allow shutdown checks to occur).

for more info google tradelink project or tradelink.org

    Edit/Delete Quote Complain
crmorris
 

Registered: Oct 2008
Posts: 24

 

08-22-12 09:46 PM


Quote from tradelink:

in tradelink you would do something like :

code:
public class MyFlatAtClose : ResponseTemplate { int shutdownat = 155500; bool shutdown = true; override void GotTick(Tick k) { if (shutdown && (k.time>=shutdownat)) { shutdown = false; foreach (var p in pt) sendorder(new MarketOrderFlat(p)); } } PositionTracker pt = new PositionTracker(); override void GotPosition(Position p) { pt.Adjust(p); } override void GotFill(Trade f) { pt.Adjust(t); } }


reconnections occur automatically unless you disable them.

for making sure problems in your own code/modules don't impact the shutdown routine, ensure you have exception handling setup so those errors aren't fatal and recover (or recover at least enough to allow shutdown checks to occur).

for more info google tradelink project or tradelink.org




could you add some sort of email writer to that class? i'd love to know when one of your users is about to run that.

    Edit/Delete Quote Complain
oldtime
 

Registered: Jun 2011
Posts: 7356

 

08-22-12 10:47 PM

are you sure if the server is down a time order won't get executed?

    Edit/Delete Quote Complain
    Page 1 of 4:   1  2  3  4  
Post A Reply


Receive an email whenever a new post is added to this thread by subscribing to it.
 
Rate This Thread:

Forum Jump:
 

 

   Conduct Rules  -  Privacy Policy  -  Day Trader -  Day Trader Forum -  Best Trading Software -  Sitemap Copyright © 2013, Elite Trader. All rights reserved.    
 
WHILE YOU'RE HERE, TAKE A MINUTE TO VISIT SOME OF OUR SPONSORS:
Advantage Futures
Futures Brokerage & Clearing
AMP Global Clearing
Futures and FX Trading
Bright Trading
Professional Equities Trading
CTS
Futures Trading Software
DaytradingBias.com
Professional Trading Analytics
ECHOtrade
Professional Trading Firm
eSignal
Trading Software Provider
FXCM
Forex Trading Services
Global Futures
Futures, Options & FX Trading
Interactive Brokers
Pro Gateway to World Markets
JC Trading Group
Direct Access Trading
MB Trading
Direct Access Trading
MultiCharts
Trading Software Provider
NinjaTrader
Trading Software Provider
OANDA
Currency Trading
optionshouse
Option Trading & Education
Rithmic
Futures Trade Execution Platform
SpeedTrader
Direct Access Trading
SpreadProfessor
Spread Trading Instruction
thinkorswim by TD Ameritrade
Direct Access TradingAdvertisement
TradersStudio
System Building & Backtesting
Trading Technologies
Trading Software Provider
Trend Following
Trading Systems Provider