Skip to main content

Oanda forex candle API built on top of oandapyV20

Project description

oanda-candles

Oanda forex candle API built on top of oandapyV20

Oanda Access Token

Using this package requires an access token to a user's Oanda brokerage account. This module only uses the token to request candle data, but such tokens can be used to make trades on the account. It is recommended that access tokens from a demo as opposed to a live accounts be used.

Demo account tokens can be generated by a signed in user here:

https://www.oanda.com/demo-account/tpa/personal_token

Quick Example

Supposing that token is set to an Oanda access token, one could print the opening bid price of the latest 100 trading hours for the Aussie like this:

from oanda_candles import CandleRequester, Pair, Gran

aud_usd = Pair("audusd")
requester = CandleRequester(token, aud_usd, Gran.H1)
candles = requester.request(count=100)

for candle in candles:
    print(candle.bid.o)

Summary of Basic Usage

  1. A CandleRequester object is initialized with a token, forex pair, and granularity.
  2. Its request method is called specifying starting time, ending time, and/or count of the candle range desired.
  3. This returns a CandleSequence object containing Candle objects as well as the pair and granularity.
  4. Each Candle has three Ohlc objects, one for Bid, Mid, and Ask prices.
  5. The Ohlc objects have open, high, low, and close Price objects

Understanding Request Ranges

The CandleRequester.request() has start, end, and count optional parameters used to specify how many candles and from when.

| parameter | valid types | valid range | default | |: --- |: --- |:----|:----| | start | TimeInt, datetime, None | epoch to now | None | | end | TimeInt, datetime, None | epoch to now | now | | count | int, None | 1 to 5000 | 500 |

It does not make sense to set all three of these parameters, but you can specify any single one of them, or any two of them, or none of them. The behavior for when they are set or unset is shown in this table:

| start | end | count | behavior | |: --- |: --- |:----|: --- | | -- | -- | -- | Get latest 500 candles | | -- | -- | set | Get latest count candles | | -- | set | -- | Get last 500 candles up until the end time | | -- | set | set | Get last count candles up until the end time | | set | -- | -- | Get the first 500 candles from start time | | set | -- | set | Get the first count candles from start time | | set | set | -- | Get candles from start to end times | | set | set | set | ValueError (there might be a different count in the range) |

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oanda-candles-0.0.1.tar.gz (12.0 kB view hashes)

Uploaded Source

Built Distribution

oanda_candles-0.0.1-py3-none-any.whl (13.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page