def cancel_order(self, id=None): """ docstring """ if id == None: return False nonce = myutils.nonce() url_path = "api/exchange/orders/" + id #message = str(nonce) + url #signature = hmac.new(self.config["coincheck"]["API_SECRET"], message, hashlib.sha256).hexdigest() signature = self._signature(nonce=nonce, url_path=url_path) headers = { 'ACCESS-KEY': self.config["coincheck"]["ACCESS_KEY"], 'ACCESS-SIGNATURE': signature, 'ACCESS-NONCE': nonce } response = myutils.delete(self.base_url + url_path, headers) ticker = json.loads(response.text) print ticker return response
def cancel_all_order(self, ids): """ Uncertain """ response = {} for id in ids: nonce = myutils.nonce() url_path = "/0/private/CancelOrder" data = {"txid": id} data["nonce"] = nonce signature = self._signature(nonce=nonce, url_path=url_path, data=data) #message = url_path + hashlib.sha256(str(nonce) + urllib.urlencode(data)).digest() #signature = hmac.new(base64.b64decode(self.config["kraken"]["API_SECRET"]), message, hashlib.sha512) headers = { 'API-Key': self.config["kraken"]["ACCESS_KEY"], 'API-Sign': base64.b64encode(signature.digest()) } #response = requests.post(self.base_url + url_path, headers=headers, data=data) response[id] = myutils.post(self.base_url + url_path, headers, data) return response
def get_balance(self): """ docstring return jpy, btc """ nonce = myutils.nonce() url_path = "api/accounts/balance" #message = str(nonce) + url #signature = hmac.new(self.config["coincheck"]["API_SECRET"], message, hashlib.sha256).hexdigest() signature = self._signature(nonce=nonce, url_path=url_path) headers = { 'ACCESS-KEY': self.config["coincheck"]["ACCESS_KEY"], 'ACCESS-SIGNATURE': signature, 'ACCESS-NONCE': nonce } #response = requests.get(self.base_url + url_path , headers=headers) response = myutils.get(self.base_url + url_path, headers) if response.status_code == 200: ticker = json.loads(response.text) jpy = float(ticker["jpy"]) btc = float(ticker["btc"]) print "coincheck_amount jpy :" + str(jpy) print "coincheck_amount btc :" + str(btc) else: jpy = 0 btc = 0 return jpy, btc
def sell(self, rate, amount): """ Uncertain """ nonce = myutils.nonce() url_path = "/0/private/AddOrder" data = { 'pair': 'XXBTZJPY', 'type': 'sell', 'ordertype': 'market', 'volume:': amount } ''' data = { 'pair': 'XXBTZJPY', 'type': 'sell', 'ordertype': 'limit', 'price': rate, 'volume:': amount } ''' data["nonce"] = nonce signature = self._signature(nonce=nonce, url_path=url_path, data=data) #message = url_path + hashlib.sha256(str(nonce) + urllib.urlencode(data)).digest() #signature = hmac.new(base64.b64decode(self.config["kraken"]["API_SECRET"]), message, hashlib.sha512) headers = { 'API-Key': self.config["kraken"]["ACCESS_KEY"], 'ACCESS-SIGNATURE': signature, 'ACCESS-NONCE': nonce } #response = requests.get(self.base_url + url_path, headers=headers, data=data) response = myutils.post(self.base_url + url_path, headers, data) if response.status_code == 200: ## send messege to slack myutils.post_slack(name="さやちゃん", text="Krakenで" + str(amount) + "BTCを" + str(rate) + "で売っといたよ") return True return False
def get_incomplete_orders(self): """ docstring """ nonce = myutils.nonce() url_path = "api/exchange/orders/opens" signature = self._signature(nonce=nonce, url_path=url_path) headers = { 'ACCESS-KEY': self.config["coincheck"]["ACCESS_KEY"], 'ACCESS-SIGNATURE': signature, 'ACCESS-NONCE': nonce } #response = requests.get(self.base_url + url_path , headers=headers) response = myutils.get(self.base_url + url_path, headers) ticker = json.loads(response.text) #print ticker return response
def sell(self, rate, amount): """ Uncertain """ nonce = myutils.nonce() url_path = "api/exchange/orders" ''' data = { "market_sell_amount": amount, "order_type": "market_sell", "pair": "btc_jpy" } ''' data = { "rate": rate, "amount": amount, "order_type": "sell", "pair": "btc_jpy" } signature = self._signature(nonce=nonce, url_path=url_path, data=data) #message = str(nonce) + url + data #signature = hmac.new(self.config["coincheck"]["API_SECRET"], message, hashlib.sha256).hexdigest() headers = { 'ACCESS-KEY': self.config["coincheck"]["ACCESS_KEY"], 'ACCESS-SIGNATURE': signature, 'ACCESS-NONCE': nonce } while True: #response = requests.post(self.base_url + url_path, headers=headers, data=data) response = myutils.post(self.base_url + url_path, headers, data) if response.status_code == 200: ## send messege to slack myutils.post_slack(name="さやちゃん", text="Coincheckで" + str(amount) + "BTCを" + str(rate) + "で売っといたよ") return True
def get_incomplete_orders(self): """ Uncertain """ nonce = myutils.nonce() url_path = "/0/private/OpenOrders" data = {} data["nonce"] = nonce signature = self._signature(nonce=nonce, url_path=url_path, data=data) #message = url_path + hashlib.sha256(str(nonce) + urllib.urlencode(data)).digest() #signature = hmac.new(base64.b64decode(self.config["kraken"]["API_SECRET"]), message, hashlib.sha512) headers = { 'API-Key': self.config["kraken"]["ACCESS_KEY"], 'API-Sign': base64.b64encode(signature.digest()) } #response = requests.post(self.base_url + url_path, headers=headers, data=data) response = myutils.post(self.base_url + url_path, headers, data) return response
def get_barance(self): """ Uncertain """ nonce = myutils.nonce() url_path = "/0/private/Balance" data = {} data["nonce"] = nonce signature = self._signature(nonce=nonce, url_path=url_path, data=data) #message = url_path + hashlib.sha256(str(nonce) + urllib.urlencode(data)).digest() #signature = hmac.new(base64.b64decode(self.config["kraken"]["API_SECRET"]), message, hashlib.sha512) headers = { 'API-Key': self.config["kraken"]["ACCESS_KEY"], 'API-Sign': base64.b64encode(signature.digest()) } #response = requests.post(self.base_url + url_path, headers=headers, data=data) response = myutils.post(self.base_url + url_path, headers, data) if response.status_code == 200: ticker = json.loads(response.text) print ticker