TransactionsStream

class oandapyV20.endpoints.transactions.TransactionsStream(accountID, params=None)

Bases: oandapyV20.endpoints.transactions.Transactions

TransactionsStream.

Get a stream of Transactions for an Account starting from when the request is made.

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

Instantiate an TransactionsStream request.

Performing this request will result in a generator yielding transactions.

Parameters:accountID (string (required)) – id of the account to perform the request on.
>>> import oandapyV20
>>> import oandapyV20.endpoints.transactions as trans
>>> client = oandapyV20.API(access_token=...)
>>> r = trans.TransactionsStream(accountID=...)
>>> rv = client.request(r)
>>> maxrecs = 5
>>> try:
>>>     for T in r.response:  # or rv ...
>>>         print json.dumps(R, indent=4), ","
>>>         maxrecs -= 1
>>>         if maxrecs == 0:
>>>             r.terminate("Got them all")
>>> except StreamTerminated as e:
>>>    print("Finished: {msg}".format(msg=e))

Output:

      {
        "type": "HEARTBEAT",
        "lastTransactionID": "2311",
        "time": "2016-10-28T11:56:12.002855862Z"
      },
      {
        "type": "HEARTBEAT",
        "lastTransactionID": "2311",
        "time": "2016-10-28T11:56:17.059535527Z"
      },
      {
        "type": "HEARTBEAT",
        "lastTransactionID": "2311",
        "time": "2016-10-28T11:56:22.142256403Z"
      },
      {
        "type": "HEARTBEAT",
        "lastTransactionID": "2311",
        "time": "2016-10-28T11:56:27.238853774Z"
      },
      {
        "type": "HEARTBEAT",
        "lastTransactionID": "2311",
        "time": "2016-10-28T11:56:32.289316796Z"
      }



Finished: Got them all
terminate(message='')

terminate the stream.

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