hootnot / oandapyV20-examples

Examples demonstrating the use of oandapyV20 (oanda-api-v20)
MIT License
147 stars 65 forks source link

Issue with granularity #16

Closed dparrado305 closed 6 years ago

dparrado305 commented 6 years ago

Hello! First of all, thank you very much for posting these Oanda examples, its hard to find many of these out there. As for my question. I keep running the candle-data.py and I get the error

candle-data: error: the following arguments are required: --granularity

What could be causing this? I am sorry if this question seems general, I am still relatively new with python. Also I was wondering what does "clargs" mean and what does it do?

Thank you!

hootnot commented 6 years ago

hi, it's easy. The program needs commandline arguments (clargs), so:

$ python src/candle_data.py
usage: candle-data [-h] [--nice] [--count COUNT] --granularity
                   {M,H8,H1,D,H2,H3,H12,S10,H6,S30,H4,M30,M5,M4,S15,M1,S5,W,M2,M15}
                   [--price {M,B,A,BA,MBA}] [--from FROM] [--to TO]
                   [--instruments [INSTRUMENTS]]
candle-data: error: argument --granularity is required

gives a usage message, because arguments were not provided and the first error it found ia reported

Run:

$ python src/candle_data.py -h

... and it gives full explanation

Now if you run:

python src/candle_data.py  --nice --count 2 --granularity M5 --price MBA --instruments EUR_USD --instruments EUR_GBP

you get:

{
 "instrument": "EUR_USD", 
 "candles": [
  {
   "complete": true, 
   "bid": {
    "h": "1.16083", 
    "c": "1.16077", 
    "l": "1.16061", 
    "o": "1.16072"
   }, 
   "mid": {
    "h": "1.16096", 
    "c": "1.16091", 
    "l": "1.16070", 
    "o": "1.16081"
   }, 
   "volume": 117, 
   "time": "2017-11-03T20:50:00.000000000Z", 
   "ask": {
    "h": "1.16108", 
    "c": "1.16105", 
    "l": "1.16079", 
    "o": "1.16090"
   }
  }, 
  {
   "complete": true, 
   "bid": {
    "h": "1.16089", 
    "c": "1.16045", 
    "l": "1.16036", 
    "o": "1.16081"
   }, 
   "mid": {
    "h": "1.16104", 
    "c": "1.16101", 
    "l": "1.16082", 
    "o": "1.16093"
   }, 
   "volume": 269, 
   "time": "2017-11-03T20:55:00.000000000Z", 
   "ask": {
    "h": "1.16157", 
    "c": "1.16157", 
    "l": "1.16096", 
    "o": "1.16105"
   }
  }
 ], 
 "granularity": "M5"
}
{
 "instrument": "EUR_GBP", 
 "candles": [
  {
   "complete": true, 
   "bid": {
    "h": "0.88793", 
    "c": "0.88766", 
    "l": "0.88759", 
    "o": "0.88771"
   }, 
   "mid": {
    "h": "0.88811", 
    "c": "0.88788", 
    "l": "0.88782", 
    "o": "0.88788"
   }, 
   "volume": 67, 
   "time": "2017-11-03T20:50:00.000000000Z", 
   "ask": {
    "h": "0.88833", 
    "c": "0.88810", 
    "l": "0.88801", 
    "o": "0.88806"
   }
  }, 
  {
   "complete": true, 
   "bid": {
    "h": "0.88768", 
    "c": "0.88736", 
    "l": "0.88736", 
    "o": "0.88768"
   }, 
   "mid": {
    "h": "0.88792", 
    "c": "0.88782", 
    "l": "0.88776", 
    "o": "0.88792"
   }, 
   "volume": 22, 
   "time": "2017-11-03T20:55:00.000000000Z", 
   "ask": {
    "h": "0.88827", 
    "c": "0.88827", 
    "l": "0.88801", 
    "o": "0.88815"
   }
  }
 ], 
 "granularity": "M5"
}

that is how it works. But you need to provide the relevant arguments.

Succes!