Closed biomechman closed 3 years ago
Try this one:
import os import argparse import json from oandapyV20 import API from oandapyV20.endpoints.pricing import PricingStream
class Streaming: """Script for streaming of rates Example use: streaming.py --inst EUR_USD --inst EUR_JPY Can be one or more instruments Will keep going until stopped or error occurs """
# Get credentials from .env
access_token = os.getenv("TOKEN")
accountID = os.getenv("ACCOUNT_ID")
# Parser for tickers
parser = argparse.ArgumentParser(prog="streaming")
parser.add_argument("function", type=str, action="store", nargs=1)
parser.add_argument("-i", "--instruments", type=str, action="append")
args = parser.parse_args()
# Generate for the api-calls
api = API(
access_token=access_token, environment=os.getenv("OandaEnv"), request_params={}
)
r = PricingStream(
accountID=accountID, params={"instruments": ",".join(args.instruments)}
)
# Continious streaming of rates
while True:
try:
for R in api.request(r):
R = json.dumps(R)
print(R)
except Exception as e:
print("Error occured: {}\n".format(e))
break
Should work flawless with Python 3.7
Would someone be able to provide a sample code with PriceStream() working on Python for the v20? (found the example)
Website (https://oanda-api-v20.readthedocs.io/en/latest/endpoints/pricing/pricingstream.html) and in this GitHub should probably be updated.
Cheers