Created
August 17, 2024 02:28
-
-
Save brulint/66349e1196f7953a3356e9c9a61dc444 to your computer and use it in GitHub Desktop.
Trade with Bitstamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import hmac, hashlib | |
import requests | |
def sign(): | |
user = '' # username @ Bitstamp | |
key = '' # API key | |
secret = '' # API secret | |
now = time.strftime("%s") | |
message = now + user + key | |
signature = hmac.new(secret.encode(),message.encode(),hashlib.sha256).hexdigest().upper() | |
return {'key':key,'signature':signature,'nonce':now} | |
uri = "https://www.bitstamp.net/api/v2/" | |
# public requests | |
requests.get(uri + 'ticker/btceur').json() | |
requests.get(uri + 'ohlc/btceur', {'limit': 1000, 'step': 3600}).json() | |
# private requests | |
requests.post(uri + 'balance/btceur/', sign()).json() | |
requests.post(uri + 'buy/instant/btceur/', {**sign(), 'amount': 10}).json() # amount in EUR | |
requests.post(uri + 'cancel_order/', {**sign(), 'id': order_id}).json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment