Je veux vérifier l'équilibre des marges de bitflyer lightning avec python, mais API_KEY et API_SECRET ne veulent jamais s'en tenir au code source.
Préparez le fichier config.txt séparément et décrivez API_KEY et API_SECRET. Utilisez configparser. https://docs.python.org/ja/3/library/configparser.html
config.txt
[bf]
api_key = <API ici_La touche Entrée>
api_secret = <API ici_Entrez SELECT>
Acquisition de marge.py
import configparser
import hmac
import datetime
import hashlib
import requests
config = configparser.ConfigParser()
config.read('./config.txt')
API_KEY = config['bf']['api_key']
API_SECRET = config['bf']['api_secret']
print(getcollateral())
#Confirmation de marge
def getcollateral():
    api_key = API_KEY
    api_secret = API_SECRET
    base_url = "https://api.bitflyer.jp"
    path_url = "/v1/me/getcollateral"
    method = "GET"
    timestamp = str(datetime.datetime.today())
    message = timestamp + method + path_url
    signature = hmac.new(bytearray(api_secret.encode('utf-8')), message.encode('utf-8') , digestmod = hashlib.sha256 ).hexdigest()
    headers = {
        'ACCESS-KEY' : api_key,
        'ACCESS-TIMESTAMP' : timestamp,
        'ACCESS-SIGN' : signature,
        'Content-Type' : 'application/json'
    }
    response = requests.get( base_url + path_url , headers = headers)
    return response.json()
{'collateral': 5070.0, 'open_position_pnl': 0.0, 'require_collateral': 0.0, 'keep_rate': 0.0}
Pour savoir comment utiliser l'API, j'ai fait référence au message de la personne suivante. Merci beaucoup. https://qiita.com/sodiumplus3/items/b69dbd3e51fc2a0f7e01
Recommended Posts