Skip to content

Instantly share code, notes, and snippets.

@caulinez
Last active May 27, 2018 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caulinez/58928e35620a4dcfa5c8dbc335abfdaf to your computer and use it in GitHub Desktop.
Save caulinez/58928e35620a4dcfa5c8dbc335abfdaf to your computer and use it in GitHub Desktop.
Coinut_Connection
import hmac
import hashlib
import json
import uuid
import random
import time
import requests
import logging
def get_logger():
logger = logging.getLogger('logger')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
return logger
logger = get_logger()
class CoinutAPI():
def __init__(self, user = None, api_key = None):
self.user = user
self.api_key = api_key
def request(self, api, content = {}):
url = 'https://api.coinut.com'
headers = {}
content["request"] = api
content["nonce"] = random.randint(1, 1000000000)
content = json.dumps(content)
logger.debug(content.strip())
if self.api_key is not None and self.user is not None:
sig = hmac.new(bytearray(self.api_key, 'utf-8'), msg=content.encode('utf-8'),
digestmod=hashlib.sha256).hexdigest()
headers = {'X-USER': self.user, "X-SIGNATURE": sig}
response = requests.post(url, headers=headers, data=content)
logger.debug(response.text.strip())
print(response.json())
return response.json()
def balance(self):
return self.request("user_balance")
def market_making():
f=open("coinut-API.txt", "r")
if f.mode == 'r':
api_user =f.readline().rstrip('\n')
api_key =f.readline().rstrip('\n')
f.close()
#print(api_key)
#print(api_user)
api = CoinutAPI(api_user, api_key)
bal = api.balance()
market_making()
@caulinez
Copy link
Author

For python 3.X

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