def TransactionsTransactionsSinceID(access_token, accountID, params=None): # check 'Get a range of Transactions for an Account starting at (but not including) a provided Transaction ID.' r = transactions.TransactionsSinceID(accountID=accountID, params=params) client = API(access_token=access_token) client.request(r) return readable_output(Munch(r.response)), Munch(r.response)
def transactions_since_id(self, _id): params = {"id": _id} r = transactions.TransactionsSinceID(accountID=self.account_id, params=params) request_data = self.send_request(r) return request_data
def test__transactions_sinceid(self, mock_get): """get the transactions since an id.""" tid = "_v3_accounts_transaction_sinceid" resp, data, params = fetchTestData(responses, tid) r = transactions.TransactionsSinceID(accountID, params=params) mock_get.register_uri('GET', "{}/{}".format(api.api_url, r), text=json.dumps(resp)) result = api.request(r) self.assertTrue(resp == r.response)
def get_TransactionsSinceID(self, transactionID): """TransactionsSinceID. Get a range of Transactions for an Account starting at (but not including) a provided Transaction ID. """ r = transactions.TransactionsSinceID(accountID=self.accountID, params={'id': transactionID}) return self.client.request(r)
def get_trans(trans_size=100): last_trans_id = int( RUNNING_ENV.api.request( transactions.TransactionList( RUNNING_ENV.account.mt4)).get('lastTransactionID')) since_id = last_trans_id - trans_size if last_trans_id - trans_size > 0 else 0 params = {"id": since_id} r = transactions.TransactionsSinceID(RUNNING_ENV.account.mt4, params) try: rv = RUNNING_ENV.api.request(r) except V20Error as err: logging.error(r.status_code, err) else: logging.debug(json.dumps(rv, indent=2)) return rv.get('transactions')
def oanda_get_sell_ordhist(self, market, lastid): pre_list = [] results_dict = {} params={"id": lastid} # market param does not work for some reason request = transactions.TransactionsSinceID(self.oanda_account_id, params=params) result = self.oanda.request(request)['transactions'] for elem in result: if 'instrument' in list(elem.keys()): if elem['instrument'] == market: pre_list.append(elem) # Reverse list (need from new to old) listoforders = [] for elem in pre_list: temp_dict = {} temp_dict['OrderUuid'] = elem["id"] listoforders.append(temp_dict) return listoforders
def oanda_results_over_time(self, market, timestamp_from, timestamp_to, lastid=0): pre_list = [] results_dict = {} params={"id": lastid} # market param does not work for some reason request = transactions.TransactionsSinceID(self.oanda_account_id, params=params) result = self.oanda.request(request)['transactions'] for elem in result: if 'instrument' in list(elem.keys()): if elem['instrument'] == market: utc_datetime = elem['time'] try: utc_datetime = datetime.strptime(utc_datetime, "%Y-%m-%dT%H:%M:%S.%fZ") except ValueError: # can be insonsistent utc_datetime = datetime.strptime(utc_datetime[:-4], "%Y-%m-%dT%H:%M:%S.%f") timestamp = (utc_datetime - datetime(1970, 1, 1)).total_seconds() if (timestamp > timestamp_from) and (timestamp < timestamp_to): pre_list.append(elem) # Only the last element is needed for calculations for OANDA last_result = pre_list[-1] total_commission = abs(float(last_result['commission'])) total_funding = abs(float(last_result['financing'])) gain = float(last_result['pl']) total_value = gain + total_commission + total_funding # for consistency print("> Total value in fiat", -total_value, "funding", total_funding) print("> Total gain / loss (outcome):", gain) results_dict['position_diff'] = total_value results_dict['commission'] = total_commission results_dict['funding'] = total_funding results_dict['total_outcome'] = gain result = results_dict return result