Hi to all. Is there some special thing that i need to do so I can update my IP address on binance site ?.
Basically, i want to automatically set new IP address under part of restricted IP’s and this is what i get for error: {‘code’: -1002, ‘msg’: ‘You are not authorized to execute this request.’}
//---------------//
I see that the request is made and i see that the post is made but it looks that i need some additional rights ? This is the part of the code that am using:
def update_binance_ip_restriction(api_key, api_secret):
try:
current_ip = requests.get('https://api.ipify.org').text
client = Client(api_key, api_secret)
url = 'https://api.binance.com/sapi/v1/account/apiRestrictions/ipRestriction'
params = {
'ipAddress': current_ip,
'action': 'ADD', # Assuming action is required and is either ADD or REMOVE
}
headers = {
'X-MBX-APIKEY': api_key,
}
response = requests.post(url, headers=headers, params=params)
response_data = response.json()
if response.status_code == 200 and response_data.get('code') == 200:
print(f'IP {current_ip} successfully updated')
else:
print(f'IP Error: {response_data}')
except Exception as e:
print(f'IP Update error: {e}')
def periodically_update_ip(api_key, api_secret, interval=60):
while True:
update_binance_ip_restriction(api_key, api_secret)
time.sleep(interval)
# ---------------
import threading
ip_update_thread = threading.Thread(target=periodically_update_ip, args=(api_key, api_secret))
ip_update_thread.daemon = True
ip_update_thread.start()