Beispiel #1
0
 def test__account_list(self, mock_req):
     """get the list of accounts."""
     tid = "_v3_accounts"
     resp, data = fetchTestData(responses, tid)
     r = accounts.AccountList()
     mock_req.register_uri('GET',
                           "{}/{}".format(api.api_url, r),
                           text=json.dumps(resp))
     result = api.request(r)
     self.assertTrue(result == resp)
Beispiel #2
0
def get_accounts():
    client = 'client=oandapyV20.API(access_token=env['client'])'
    client = oandapyV20.API(access_token=client)
    r = accounts.AccountList()
    client.request(r)
    pprint(r.response['accounts'])
    accounts_collection = []
    for each in r.response['accounts']:
        accounts_collection.append(each['id'])
    return accounts_collection
Beispiel #3
0
    def test__requests_exception(self):
        """force a requests exception."""
        from requests.exceptions import RequestException
        import oandapyV20.endpoints.accounts as accounts
        setattr(sys.modules["oandapyV20.oandapyV20"],
                "TRADING_ENVIRONMENTS",
                {"practice": {
                 "stream": "ttps://test.com",
                 "api": "ttps://test.com",
                 }})
        api = API(environment=environment,
                  access_token=access_token,
                  headers={"Content-Type": "application/json"})
        text = "No connection " \
               "adapters were found for 'ttps://test.com/v3/accounts'"
        r = accounts.AccountList()
        with self.assertRaises(RequestException) as oErr:
            api.request(r)

        self.assertEqual("{}".format(oErr.exception), text)
access_token = config['oanda']['api_key']

client = oandapyV20.API(access_token=access_token)

#  Get Basic Account Details
r = accounts.AccountDetails(accountID)

client.request(r)
account_details = r.response
print("\n raw account details: \n", account_details)
# or
account_table_format = pd.Series(r.response['account'])
print(account_table_format)

# Get Account List (for tracking multiple aub accounts)
r = accounts.AccountList()
all_acc_under_mgt = client.request(r)
print("\n All Accounts under management: \n", all_acc_under_mgt)

# Get Account Status Summary (are there open trades?... etc)
r = accounts.AccountSummary(accountID)
client.request(r)
account_status_summary = pd.Series(r.response['account'])
print("\n Summary  of Account Status: \n", account_status_summary)

# Instruments that can be traded with the specified account,
# minimum Trailing Stop Distance,
r = accounts.AccountInstruments(accountID=accountID, params="EUR_USD")
client.request(r)
account_instruments = pd.DataFrame(r.response['instruments'])
print("\n List of tradable Account Instruments: \n", account_instruments)
Beispiel #5
0
 def account_list(self):
     endpoint = accounts.AccountList()
     self.send_request(endpoint)
     return endpoint.response
Beispiel #6
0
 def initAccount(self,
                 broker,
                 token,
                 btpath='./',
                 btfilelist=[],
                 btcurr='USD',
                 btamount=100000,
                 btmargin=0.02,
                 btstart=pd.Timestamp.now(tz='utc'),
                 btend=pd.Timestamp('2000-01-01T00:00', tz='utc')):
     if broker == 'backtest':  # Introduce pairs in config.py
         cfg.brokerList['backtest'] = {
             'path': btpath,
             'filelist': btfilelist,
             'accounts': []
         }
         cfg.brokerList['backtest']['accounts'] = [{
             'ID':
             0,
             'tsv':
             None,
             'psv':
             None,
             'margin':
             btmargin,
             'curr':
             btcurr,
             'initAmount':
             btamount,
             'log':
             pd.DataFrame({
                 'balance': [],
                 'NAV': []
             }, index=[])
         }]
     if broker == 'oanda':
         client = oandapyV20.API(access_token=token)
         r = accounts.AccountList()
         rv = dict(client.request(r))
         cfg.brokerList['oanda'] = {'token': token}
         cfg.brokerList['oanda']['accounts'] = []
         cfg.priceList['oanda'] = {}
         cfg.priceList['oanda']['accounts'] = []
         for acc in rv["accounts"]:
             ra = accounts.AccountDetails(acc["id"])
             rav = dict(client.request(ra))
             cfg.brokerList['oanda']['accounts'].append({
                 'ID':
                 acc["id"],
                 'tsv':
                 None,
                 'psv':
                 None,
                 'margin':
                 float(rav["account"]["marginRate"]),
                 'curr':
                 rav["account"]["currency"],
                 'log':
                 pd.DataFrame(
                     {
                         'bal': [float(rav["account"]["balance"])],
                         'NAV': [float(rav["account"]["NAV"])],
                         'mused': [float(rav["account"]["marginUsed"])]
                     },
                     index=[pd.Timestamp.now(tz='utc')])
             })
             cfg.priceList['oanda']['accounts'].append(None)
Beispiel #7
0
def AccountList(access_token):  # check
    'Get a list of all Accounts authorized for the provided token.'
    r = accounts.AccountList()
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)