Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Invalid Nonce #599

Open
kezibooo opened this issue Dec 25, 2024 · 0 comments
Open

Invalid Nonce #599

kezibooo opened this issue Dec 25, 2024 · 0 comments

Comments

@kezibooo
Copy link

import json
import threading

import websocket
import hmac
import hashlib
import base64
import time

class BtcturkWsAuth:
 def __init__(self):
 self.exchange_name = "BTC Turk"
 self.uri = "wss://ws-feed-pro.btcturk.com/"
 self.ws = None

 def on_message(self, wrs, message):
 """WebSocket'ten gelen mesajları işler."""
 print(f"Gelen Mesaj: {message}") # Gelen mesajı kontrol etmek için ekrana yazdır

 def on_open(self, ws):
 """Bağlantı açıldığında çalışır."""
 print("Connection opened")
 self.authenticate()

 def authenticate(self):
 """WebSocket oturumu açma."""
 publicKey = ""
 privateKey = ""
 nonce = int(time.time() * 1000)
 baseString = f"{publicKey}{nonce}".encode("utf-8")
 signature = hmac.new(base64.b64decode(privateKey), baseString, hashlib.sha256).digest()
 signature = base64.b64encode(signature).decode("utf-8")

 auth_message = [
 114,
 {"nonce": nonce, "publicKey": publicKey, "signature": signature, "type": 114},
 ]
 self.ws.send(json.dumps(auth_message))


 def start_websocket(self):

 self.ws = websocket.WebSocketApp(
 self.uri, on_message=self.on_message, on_error=self.on_error, on_close=self.on_close
 )
 self.ws.on_open = self.on_open
 self.ws.run_forever()

 def on_error(self, ws, error):
 """Hata durumunda çalışır."""
 print(f"Error: {error}")

 def on_close(self, ws, close_status_code, close_msg):
 """Bağlantı kapandığında yeniden bağlanır."""
 print("Connection closed, attempting to reconnect in 10 seconds...")
 time.sleep(60)
 self.start_websocket()

# Kullanım
if __name__ == "__main__":
 btcturk = BtcturkWsAuth()
 threading.Thread(target=btcturk.start_websocket).start()
# btcturk.ws.close()

burada nasıl bi hata yapıyorum ? Gelen Mesaj: [114,{"type":114,"id":0,"ok":false,"message":"Unauthorized - Invalid Nonce"}]

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant