Permalink
Browse files

Strat, calculate quote dist from contract's min_tick

  • Loading branch information...
1 parent 95978a3 commit ab3d2cb7fc34f1bfb13e62917f61aac63ff2e0f4 @rudimeier committed May 9, 2012
Showing with 17 additions and 2 deletions.
  1. +16 −2 src/tws_strat.cpp
  2. +1 −0 src/tws_strat.h
View
@@ -59,6 +59,18 @@ Strat::~Strat()
{
}
+/**
+ * Return min tick price for a given contract.
+ */
+double Strat::min_tick(const IB::Contract& c)
+{
+ assert( c.conId != 0 );
+ assert( twsdo.con_details.find( c.conId ) != twsdo.con_details.end() );
+ double min_tick = twsdo.con_details[c.conId]->minTick ;
+ assert(min_tick > 0.0);
+ return min_tick;
+}
+
/**
* Place or modify buy and sell orders for a single contract. Quote should
* valid bid and ask.
@@ -72,8 +84,10 @@ void Strat::adjust_order( const IB::Contract& c, const Quote& quote,
pO.order.totalQuantity = pO.contract.secType == "CASH" ? 25000 : 1;
const char *symbol = pO.contract.symbol.c_str();
- double lmt_buy = quote.val[IB::BID] - 0.1;
- double lmt_sell = quote.val[IB::ASK] + 0.1;
+ double quote_dist = 1 * min_tick(c);
+
+ double lmt_buy = quote.val[IB::BID] - quote_dist;
+ double lmt_sell = quote.val[IB::ASK] + quote_dist;
if( twsdo.p_orders.find(oids.buy_oid) == twsdo.p_orders.end() ) {
/* new buy order */
View
@@ -66,6 +66,7 @@ class Strat
private:
void adjust_order( const IB::Contract&, const Quote&, buy_sell_oid& );
+ double min_tick( const IB::Contract& );
TwsDL &twsdo;
std::map<int, buy_sell_oid> map_data_order;

0 comments on commit ab3d2cb

Please sign in to comment.