rudimeier / twstools

command line tools around Interactive Brokers TWS API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is possible to use without xml jobfiles

jaznow opened this issue · comments

Hi,
I've been reviewing your work, and it's more or less what I needed, i would like to use your tool to create a batch php that will import 25 years of history of a "symbol", like for example "AAPL".
I can see you have implemented usage via xml jobfile, is ti possible to use it without jobfiles? somewat

twsdo -p=7956 -h=127.0.0.1 --symbol=AAPL --market=SMART --currency=USD --startDate=1995-01-01 --endDate=2014-12-30

?

I have no such simple options (except -A, -E, -O to get account status, etc.). Adding all possible contracts and order fields would be overkill.

But you could use an order template to it fill up. Below an example how I use it in a shell script using sed. I guess php should even have a built-in "sed" or you could use sprintf to replace placeholders "%s" by ordered list of variables.

IFS=$'\n' read -r -d '' order_tmpl <<-'EOF'
<?xml version="1.0"?>
<TWSXML>
  <request type="place_order">
    <query>
      <contract secType="FUT" exchange=":exchange:" localSymbol=":localSymbol:"/>
      <order
        account=":account:"
        action=":action:" totalQuantity=":totalQuantity:"
        orderType=":orderType:" tif=":tif:"
        goodAfterTime=":goodAfterTime:" goodTillDate=":goodTillDate:"
        transmit=":transmit:"
      />
    </query>
  </request>
</TWSXML>
EOF

echo "${order_tmpl}" | sed \
        -e "s/:exchange:/${ex}/g" \
        -e "s/:localSymbol:/${loc_sym}/g" \
        -e "s/:account:/${TWS_ACC_NAME}/g" \
        -e "s/:action:/${act}/g" \
        -e "s/:totalQuantity:/${qty}/g" \
        -e "s/:orderType:/${ot}/g" \
        -e "s/:tif:/${tif}/g" \
        -e "s,:goodAfterTime:,${time_order},g" \
        -e "s,:goodTillDate:,${time_cancel},g" \
        -e "s/:transmit:/${transmit}/g" \
        > order_file

Note you could also pipe the order string without writing to a file (echo $order | twsdo ...). But usually I want to keep all the orders for logging and debugging.

Ah sorry I haven't read carefully that you want to create "history jobs". In shell I do this using dseq from http://www.fresse.org/dateutils/ to get good date sequences. twsgen can generate history jobs.

# the contract or more contracts are in a file
cat /tmp/con_example.xml
<?xml version="1.0"?>
<TWSXML>
  <request type="contract_details">
    <query>
      <reqContract symbol="16E" secType="IND"/>
    </query>
    <response>
      <ContractDetails>
            <summary symbol="16E" secType="IND" exchange="GLOBEX" currency="USD" localSymbol="16E" tradingClass="16E"/>
      </ContractDetails>
    </response>
  </request>
</TWSXML>

# itereate over intervals of 34 business days (which is good for 30min data)
for i in `dseq --compute-from-last -f "%Y%m%d" 2012-01-01 34b 2013-05-15` ;do
    cat /tmp/con_example | twsgen -H -e "$i 00:00:00" -b "30 mins" -w "BID,ASK,TRADES"
done > /tmp/jobfile.xml

Hi, thanks rudimeier I will have to study carefully what you've given me, since sed and dseq commands are totally new for me, and have to see how they operate.

But right now, if I understood right, what you've given me is a shell script, but I don't get what's the content of the file /tmp/con_example.xml ?

Also are u interested in developing a simple command to achieve what I need for me if we find a economic agreement for the job?, I'm really not any good at unix shell script or C++ programming.

Thank you.