Esempio n. 1
0
class CandlePricingAPI(Oanda):
    """
    API to get the current pricing

    """

    def __init__(self, access_token, account_id, csv_path):
        super().__init__(access_token, account_id)
        self.csv_handler = CSVHandler(csv_path)

    def get_candle_price(self):
        url = BASE_API_URL + '/v3/accounts/' + \
            self.account_id + '/candles/latest'
        res = requests.get(url,
                           headers={'Authorization': 'Bearer ' +
                                    self.access_token},
                           params={'candleSpecifications': 'EUR_USD:M1:B'})

        if(res.status_code != 200):
            # need to handle error
            pass

        data = json.loads(res.text)
        row_data = data['latestCandles'][0]['candles'][-1]['bid'].values()
        self.csv_handler.save_to_csv(row_data)
Esempio n. 2
0
class StreamListener:
    def __init__(self, lstm_model, csv_path):
        self.counter = 0
        self.csv_handler = CSVHandler(csv_path)
        self.lstm_model = lstm_model

    def on_data(self, data):
        if(self.counter > MAX_RETRIEVE):
            return False
        else:
            self.handle_data(data)
            return True

    def handle_data(self, data):
        try:
            price = data['bids'][0]['price']
            time = data['time']
            row_data = [time, price]
            self.csv_handler.save_to_csv(row_data)
        except Exception as e:
            raise e