Skip to content

Instantly share code, notes, and snippets.

@Endogen
Last active August 18, 2017 20:42
Show Gist options
  • Save Endogen/354942856d23fc4b682a7ee342213092 to your computer and use it in GitHub Desktop.
Save Endogen/354942856d23fc4b682a7ee342213092 to your computer and use it in GitHub Desktop.
Choose which Kraken API keys to use depending on current MAC address
from uuid import getnode as mac
# Read Kraken keys
with open("kraken.json") as kraken_keys_file:
kraken_keys = json.load(kraken_keys_file)
# Identify and choose Kraken API keys based on MAC address
# and return the Kraken object to call the API
def get_kraken_api():
if str(mac()) in kraken_keys:
api_key = kraken_keys[str(mac())]["api_key"]
private_key = kraken_keys[str(mac())]["private_key"]
else:
# If no entry found for current MAC address, use random one from config
msg = "No Kraken API keys found for MAC " + str(mac()) + ". Using random from config"
updater.bot.send_message(chat_id=config["user_id"], text=msg)
mac_address, keys_dict = random.choice(list(kraken_keys.items()))
api_key = keys_dict["api_key"]
private_key = keys_dict["private_key"]
# Connect to Kraken
return krakenex.API(key=api_key, secret=private_key)
@Endogen
Copy link
Author

Endogen commented Aug 16, 2017

The question is, how to get the MAC or any other unique identification of the connected client...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment