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

Expecting property name enclosed in double quotes: line 1 column 2 (char 1) #52

Open
saeedesmaili opened this issue Jun 13, 2018 · 1 comment

Comments

@saeedesmaili
Copy link

saeedesmaili commented Jun 13, 2018

I'm trying to use algo-trading as described in this tutorial:
https://www.oreilly.com/learning/algorithmic-trading-in-less-than-100-lines-of-python-code

class MomentumTrader(opy.Streamer):
    def __init__(self, momentum, *args, **kwargs): 
        opy.Streamer.__init__(self, *args, **kwargs) 
        self.ticks = 0  
        self.position = 0 
        self.df = pd.DataFrame()  
        self.momentum = momentum  
        self.units = 100000 
    def create_order(self, side, units): 
        order = oanda.create_order(config["oanda"]["account_id"], 
            instrument="EUR_USD", units=units, side=side,
            type="market") 
        print("\n", order)  
    def on_success(self, data):  
        self.ticks += 1 
        # print(self.ticks, end=", ")
        # appends the new tick data to the DataFrame object
        self.df = self.df.append(pd.DataFrame(data["tick"],
                                 index=[data["tick"]["time"]]))  
        # transforms the time information to a DatetimeIndex object
        self.df.index = pd.DatetimeIndex(self.df["time"])  
        # resamples the data set to a new, homogeneous interval
        dfr = self.df.resample("5s").last() 
        # calculates the log returns
        dfr["returns"] = np.log(dfr["ask"] / dfr["ask"].shift(1))  
        # derives the positioning according to the momentum strategy
        dfr["position"] = np.sign(dfr["returns"].rolling( 
                                      self.momentum).mean())  
        if dfr["position"].ix[-1] == 1:  
            # go long
            if self.position == 0: 
                self.create_order("buy", self.units) 
            elif self.position == -1:  
                self.create_order("buy", self.units * 2)  
            self.position = 1  
        elif dfr["position"].ix[-1] == -1:  
            # go short
            if self.position == 0:  
                self.create_order("sell", self.units)  
            elif self.position == 1: 
                self.create_order("sell", self.units * 2)
            self.position = -1
        if self.ticks == 250: 
            # close out the position
            if self.position == 1:  
                self.create_order("sell", self.units)  
            elif self.position == -1:  
                self.create_order("buy", self.units) 
            self.disconnect()  
mt = MomentumTrader(momentum=12, environment="practice",
                    access_token=config["oanda"]["access_token"])
mt.rates(account_id=config["oanda"]["account_id"],
         instruments=["DE30_EUR"], 
         ignore_heartbeat=True)

And I'm getting this error:
JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

I guess I need to use the oandapyv20 but there isn't any cheatsheet to guide me how to migrate these simple code snippets to the new api.
So what should be used instead of "mt.rates"?

@hootnot
Copy link
Contributor

hootnot commented Jun 13, 2018

Hi, checkout thisone: https://github.com/benjaminchodroff/oandamomentum/blob/master/oandamomentumv20.ipynb

maybe it helps

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

No branches or pull requests

2 participants