Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v20.instrument.orderBook not implemented #29

Closed
dcolley opened this issue Sep 28, 2018 · 14 comments · May be fixed by #30
Closed

v20.instrument.orderBook not implemented #29

dcolley opened this issue Sep 28, 2018 · 14 comments · May be fixed by #30

Comments

@dcolley
Copy link

dcolley commented Sep 28, 2018

http://developer.oanda.com/rest-live-v20/instrument-ep/ refers an orderBook action, but this is not available in v20

api = v20.Context(
    hostname=config["hostname"],
    port=config["port"],
    token=config["token"],
    datetime_format=config["datetime_format"]
)
params = {
    "time": "2018-09-28T12:00:00:00Z"
}
response = api.instrument.orderBook(instrument, **params)
orderBook = response.get("orderBook", 200)
print(orderBook)

I get this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-47-355910ca7359> in <module>()
      3     "time": "2018-09-28T12:00:00:00Z"
      4 }
----> 5 response = api.instrument.orderBook(instrument, **params)
      6 orderBook = response.get("orderBook", 200)
      7 print(orderBook)

AttributeError: 'EntitySpec' object has no attribute 'orderBook'

Is this a bug?

@hootnot
Copy link

hootnot commented Sep 28, 2018

I don't use this lib,, but sources contain OrderBook, so does it fail with a capital 'O' also ?

@dcolley
Copy link
Author

dcolley commented Sep 28, 2018

I tried that. OrderBook exists, but does not work as the REST API is documented.

@hootnot
Copy link

hootnot commented Sep 28, 2018

You can use make use of oandapyV20 instead, it supports that. You can use v20 and oandapyV20 parallel, so for a quick hack you use only oandapyV20 for the orderbook info.

@dcolley
Copy link
Author

dcolley commented Sep 28, 2018

from command line:

curl \
  --compressed \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <AUTHENTICATION TOKEN>" \
  "https://api-fxtrade.oanda.com/v3/instruments/USD_JPY/orderBook"

returns:

{"orderBook":{
"instrument":"USD_JPY","time":"2018-09-28T12:40:00Z","unixTime":"1538138400","price":"113.437","bucketWidth":"0.050",
"buckets":[
  {"price":"0.000","longCountPercent":"0.0071","shortCountPercent":"0.0000"},
  {"price":"0.100","longCountPercent":"0.0214","shortCountPercent":"0.0214"},
  {"price":"0.150","longCountPercent":"0.0071","shortCountPercent":"0.0285"},
  {"price":"0.200","longCountPercent":"0.0000","shortCountPercent":"0.0071"},
  {"price":"0.300","longCountPercent":"0.0000","shortCountPercent":"0.0142"},
  {"price":"0.400","longCountPercent":"0.0000","shortCountPercent":"0.0071"},
  {"price":"0.500","longCountPercent":"0.0071","shortCountPercent":"0.0071"},
  {"price":"0.600","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"0.700","longCountPercent":"0.0214","shortCountPercent":"0.0071"},
  {"price":"0.800","longCountPercent":"0.0000","shortCountPercent":"0.0071"},
  {"price":"0.850","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"0.900","longCountPercent":"0.0000","shortCountPercent":"0.0142"}, 
  {"price":"0.950","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.000","longCountPercent":"0.1638","shortCountPercent":"0.0783"}, 
  {"price":"1.050","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.100","longCountPercent":"0.0071","shortCountPercent":"0.0142"}, 
  {"price":"1.150","longCountPercent":"0.0071","shortCountPercent":"0.0000"}, 
  {"price":"1.200","longCountPercent":"0.0142","shortCountPercent":"0.0071"}, 
  {"price":"1.300","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.400","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.500","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.600","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.700","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.750","longCountPercent":"0.0142","shortCountPercent":"0.0000"}, 
  {"price":"1.800","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"1.900","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.000","longCountPercent":"0.0000","shortCountPercent":"0.0214"}, 
  {"price":"2.100","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.200","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.300","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.400","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.500","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.600","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.700","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.800","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"2.900","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.000","longCountPercent":"0.0000","shortCountPercent":"0.0142"}, 
  {"price":"3.100","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.200","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.300","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.400","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.500","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.600","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.700","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.800","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"3.900","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"4.000","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"4.100","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"4.200","longCountPercent":"0.0000","shortCountPercent":"0.0071"}, 
  {"price":"4.300","longCountPercent":"0.0000","shortCountPercent":"0.0071"}
}```

@dmpettyp
Copy link

It looks like the enpoint that is used to fetch the orderbooks wasn't set up correctly to have an API call auto-generated for it. I'll get that added and published shortly. The API call will indeed be "api.instrument.orderBook()" as you had predicted.

@dmpettyp
Copy link

actually, since it's python, the API call will be order_book()

@dcolley
Copy link
Author

dcolley commented Sep 28, 2018

@dmpettyp the code is littered with camelCase... hence I was following that convention. I have a PR that solves the problem for me - should I submit it?

@dcolley
Copy link
Author

dcolley commented Sep 28, 2018

PR #30 created

@dmpettyp
Copy link

Hmm, while there is camel case in the code, I believe that it mostly is used to access data from the JSON responses, which is all camel case. I think that most of the python variables and function names use snake case.

Thanks for the PR, however all of the code in the library is auto-generated and we're not set-up to merge code into the library. You should be able to find the order_book() call is in the latest build.

https://github.com/oanda/v20-python/blob/master/src/v20/instrument.py#L932

@dcolley
Copy link
Author

dcolley commented Sep 28, 2018

Sweet! 👍

@dcolley dcolley closed this as completed Sep 28, 2018
@dcolley
Copy link
Author

dcolley commented Sep 28, 2018

PS: you should also do this for position_book()

@dmpettyp
Copy link

scroll!

https://github.com/oanda/v20-python/blob/master/src/v20/instrument.py#L1038

@asasa293
Copy link

Can someone explain to me please, what does shortCountPercent and longCountPercent mean? how can I interpret this information?

@cadwallader
Copy link

cadwallader commented Jan 22, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants