PricingStream

class oandapyV20.endpoints.pricing.PricingStream(accountID, params=None)

Bases: oandapyV20.endpoints.pricing.Pricing

PricingStream.

Get realtime pricing information for a specified list of Instruments.

ENDPOINT = 'v3/accounts/{accountID}/pricing/stream'
EXPECTED_STATUS = 200
METHOD = 'GET'
STREAM = True
__init__(accountID, params=None)

Instantiate a PricingStream APIRequest instance.

Parameters:
  • accountID (string (required)) – the accountID of the account.
  • params (dict (required)) – parameters for the request, check developer.oanda.com for details.

Example

>>> import oandapyV20
>>> from oandapyV20 import API
>>> import oandapyV20.endpoints.pricing as pricing
>>> accountID = "..."
>>> api = API(access_token="...")
>>> params =
        {
          "instruments": "EUR_USD,EUR_JPY"
        }
>>> r = pricing.PricingStream(accountID=accountID, params=params)
>>> rv = api.request(r)
>>> maxrecs = 100
>>> for ticks in r:
>>>     print json.dumps(R, indent=4),","
>>>     if maxrecs == 0:
>>>         r.terminate("maxrecs records received")

Output:

{
  "status": "tradeable",
  "instrument": "EUR_JPY",
  "asks": [
    {
      "price": "114.312",
      "liquidity": 1000000
    },
    {
      "price": "114.313",
      "liquidity": 2000000
    },
    {
      "price": "114.314",
      "liquidity": 5000000
    },
    {
      "price": "114.316",
      "liquidity": 10000000
    }
  ],
  "time": "2016-10-27T08:38:43.094548890Z",
  "closeoutAsk": "114.316",
  "type": "PRICE",
  "closeoutBid": "114.291",
  "bids": [
    {
      "price": "114.295",
      "liquidity": 1000000
    },
    {
      "price": "114.294",
      "liquidity": 2000000
    },
    {
      "price": "114.293",
      "liquidity": 5000000
    },
    {
      "price": "114.291",
      "liquidity": 10000000
    }
  ]
},
{
  "type": "HEARTBEAT",
  "time": "2016-10-27T08:38:44.327443673Z"
},
{
  "status": "tradeable",
  "instrument": "EUR_USD",
  "asks": [
    {
      "price": "1.09188",
      "liquidity": 10000000
    },
    {
      "price": "1.09190",
      "liquidity": 10000000
    }
  ],
  "time": "2016-10-27T08:38:45.664613867Z",
  "closeoutAsk": "1.09192",
  "type": "PRICE",
  "closeoutBid": "1.09173",
  "bids": [
    {
      "price": "1.09177",
      "liquidity": 10000000
    },
    {
      "price": "1.09175",
      "liquidity": 10000000
    }
  ]
},
{
  "status": "tradeable",
  "instrument": "EUR_JPY",
  "asks": [
    {
      "price": "114.315",
      "liquidity": 1000000
    },
    {
      "price": "114.316",
      "liquidity": 2000000
    },
    {
      "price": "114.317",
      "liquidity": 5000000
    },
    {
      "price": "114.319",
      "liquidity": 10000000
    }
  ],
  "time": "2016-10-27T08:38:45.681572782Z",
  "closeoutAsk": "114.319",
  "type": "PRICE",
  "closeoutBid": "114.294",
  "bids": [
    {
      "price": "114.298",
      "liquidity": 1000000
    },
    {
      "price": "114.297",
      "liquidity": 2000000
    },
    {
      "price": "114.296",
      "liquidity": 5000000
    },
    {
      "price": "114.294",
      "liquidity": 10000000
    }
  ]
}
terminate(message='')

terminate the stream.

Calling this method will stop the generator yielding tickrecords. A message can be passed optionally.