簡體   English   中英

使用 python 用 3 個逗號 API 加載賬戶余額?

[英]Loading account balance with the 3commas API using python?

我正在嘗試使用 python 3commas API 解包器獲取我的帳戶余額。 我在下面列出了我的代碼。 我認為我卡在了 action_id 部分,因為我不確定該放什么。 使用當前代碼,我得到各種異常,如 response_json.get('error'), response_json.get('error_description'))}, None UnboundLocalError: local variable 'response_json' referenced before assignment。

這是代碼:

from py3cw.request import Py3CW

p3cw = Py3CW(
    key='my key', 
    secret='my secret key',
    )

data = p3cw.request(
    entity='accounts',
    action='load_balances',
    action_id='POST /ver1/accounts/{number or name?}/'
    )

print (data);

就像我提到的,我也試過 action_id='number or name?'。 我還嘗試將 action_id 更改為 account_id。

順便說一句,我使用了這個網站: https://github.com/bogdanteodoru/py3cw

我真的希望有人能夠幫助我:)

看起來你的問題是你的 action_id 參數。 您需要獲取您的帳號。 要獲得該號碼,您可以使用 function,如下所示:

def connected_accounts(p3cw):
error, data = p3cw.request(
    entity='accounts',
    action= ''
)
if error == {}:
    return data
else:
    raise(Exception(error['msg']))

function 將數據作為每個帳戶的字典列表返回。 要查找帳戶 ID 號,只需打印數據。

然后您可以使用 action_id = account_id_number 運行您的代碼,我使用了 function,如下所示:

def load_balance(p3cw, account_id):
error, data = p3cw.request(
    entity='accounts',
    action='load_balances',
    action_id=str(account_id),
)
if error == {}:
    return data
else:
    raise(Exception(error['msg']))

您只需要獲取帳戶 ID 以用作 action_id 參數。 這是一個工作示例:

from py3cw.request import Py3CW

p3cw = Py3CW(
    key='KEY', 
    secret='SECRET',
    )

def connected_accounts():
    error, accountData = p3cw.request(
        entity='accounts',
        action= ''
    )
    if error == {}:
        return accountData
    else:
        raise(Exception(error['msg']))

account_id = connected_accounts()[0]['id']

data = p3cw.request(
    entity='accounts',
    action='load_balances',
    action_id=str(account_id)
    )

print(data)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM