Wednesday, August 13, 2014

Bypassing OANDA's 5000 candle limit

OANDA limits the amount of candles you can download using it's HTTP API. If you ever try to download more than 5000 candles, you get the following error message:

{ "code" : 36, "message" : "The value specified is not in the valid range: Resulting candle count is larger than maximum allowed: 5000", "moreInfo" : "http:\/\/developer.oanda.com\/docs\/v1\/troubleshooting\/#errors" }
This limit can be bypassed using the following script:
#!/bin/bash # OANDA 5000 candle limit bypasser # Vicente Oscar Mier Vela # <vomv1988@gmail.com> # Wed Aug 13 19:45:05 CDT 2014 # # Example: # # ./dl2.sh "Aug 3 21:00:00 GMT 2014" "Aug 8 21:00:00 GMT 2014" S5 # # This will output 3 element lists composed of # 1. A line containing the UNIX time of a particular currency price sample # 2. A line containing the closing bid price # 3. A line containing the closing ask price # # Remember that... # "No candles are published for intervals where there are no ticks. This will result # in gaps in between time periods." # http://developer.oanda.com/docs/v1/rates/#get-current-prices START=$1 START=`date -d "$START" +%s` END=$2 END=`date -d "$END" +%s` TIME=$3 case $TIME in S5 ) TIMES=5 ;; S10 ) TIMES=10 ;; S15 ) TIMES=15 ;; S30 ) TIMES=30 ;; M1 ) TIMES=60 ;; M2 ) TIMES=120 ;; M3 ) TIMES=180 ;; M5 ) TIMES=300 ;; M10 ) TIMES=600 ;; M15 ) TIMES=900 ;; M30 ) TIMES=1800 ;; H1 ) TIMES=3600 ;; H2 ) TIMES=7200 ;; H3 ) TIMES=10800 ;; H4 ) TIMES=14400 ;; esac LAPSE=`echo "$END-$START" | bc` CHUNKS=`echo "$LAPSE/(5000*$TIMES)" | bc` AUTH="Authorization: Bearer 12345678900987654321-abc34135acde13f13530" DFORM="X-Accept-Datetime-Format: UNIX" URL="https://api-fxpractice.oanda.com/v1/candles?instrument=EUR_USD&start=0&end=0&granularity=$TIME" DATESTART=$START >samples if test $CHUNKS -gt 0 ; then while test $CHUNKS -gt 0 ; do DATEEND=`echo "$DATESTART+(5000*$TIMES)" | bc` # echo START $DATESTART = `date -d "@$DATESTART"` # echo END $DATEEND = `date -d "@$DATEEND"` URLSAMPLE=`echo $URL | sed "s/start=0&end=0/start=$DATESTART\\&end=$DATEEND/"` curl -s -H "$AUTH" -H "$DFORM" -X GET $URLSAMPLE >> samples DATESTART=`echo "$DATEEND+$TIMES" | bc` CHUNKS=`echo "$CHUNKS-1" | bc` echo CHUNKS $CHUNKS done LASTCHUNKSIZE=`echo "$LAPSE%(5000*$TIMES)" | bc` DATESTART=`echo "$END-$LASTCHUNKSIZE+$TIMES" | bc` DATEEND=$END # echo START $DATESTART = `date -d "@$DATESTART"` # echo END $DATEEND = `date -d "@$DATEEND"` URLSAMPLE=`echo $URL | sed "s/start=0&end=0/start=$DATESTART\\&end=$DATEEND/"` curl -s -H "$AUTH" -H "$DFORM" -X GET $URLSAMPLE >> samples else DATESTART=$START DATEEND=$END # echo START $DATESTART = `date -d "@$DATESTART"` # echo END $DATEEND = `date -d "@$DATEEND"` URLSAMPLE=`echo $URL | sed "s/start=0&end=0/start=$DATESTART\\&end=$DATEEND/"` curl -s -H "$AUTH" -H "$DFORM" -X GET $URLSAMPLE >> samples fi cat samples | grep -e time -e closeBid -e closeAsk | sed 's/000000",/",/;s/"//;s/"//g;s/.*: //;s/,//'
I will pipe this script's output into a C program to produce the trading simulation I mentioned in an earlier post.

1 comment:

  1. Hey Everybody,

    I've created a list of the highest ranking forex brokers:
    1. Most Recommended Forex Broker
    2. eToro - $50 min. deposit.

    Here is a list of top forex instruments:
    1. ForexTrendy - Recommended Odds Software.
    2. EA Builder - Custom Indicators Autotrading.
    3. Fast FX Profit - Secret Forex Strategy.

    I hope you find these lists helpful...

    ReplyDelete