Ejemplo n.º 1
0
    def cancel_all_order_fx(self):
        """
        docstring
        """

        nonce = myutils.nonce2()
        url_path = "/v1/me/cancelallchildorders"

        data = {"product_code": "FX_BTC_JPY"}

        #message  = str(nonce) + url
        #signature = hmac.new(self.config["coincheck"]["API_SECRET"], message, hashlib.sha256).hexdigest()
        signature = self._signature(nonce=nonce,
                                    method="POST",
                                    url_path=url_path,
                                    data=data)
        headers = {
            'ACCESS-KEY': self.config["bitflyer"]["ACCESS_KEY"],
            'ACCESS-SIGN': signature,
            'ACCESS-TIMESTAMP': nonce,
            "Content-Type": "application/json"
        }

        response = myutils.post(url=self.base_url + url_path,
                                headers=headers,
                                data=json.dumps(data))

        return True
    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
Ejemplo n.º 3
0
    def sell(self, rate, amount):
        """
        Uncertain
        """

        nonce = myutils.nonce2()

        data = {
            "method": "trade",
            "currency_pair": "btc_jpy",
            "action": "ask",
            "price": rate,
            "amount": amount,
            'nonce': nonce,
            "method": "trade"
        }

        signature = self._signature(data=data)
        #message  = str(nonce) + url_path + urllib.urlencode(data)
        #signature = hmac.new(self.config["zaif"]["API_SECRET"], message, hashlib.sha512).hexdigest()

        headers = {'key': self.config["zaif"]["ACCESS_KEY"], 'sign': signature}

        while True:
            #response = requests.post(self.base_url + "tapi", headers=headers, data=data)
            response = myutils.post(self.base_url2, headers, data)

            if response.status_code == 200:
                ## send messege to slack
                myutils.post_slack(name="さやちゃん",
                                   text="Zaifで" + str(amount) + "BTCを" +
                                   str(rate) + "で売といたよ")
                return True
Ejemplo n.º 4
0
    def get_balance(self):
        """
        Uncertain
        """

        nonce = myutils.nonce2()
        data = {'nonce': nonce, "method": "get_info"}

        signature = self._signature(data=data)
        #message  = urllib.urlencode(data)
        #signature = hmac.new(self.config["zaif"]["API_SECRET"], message, hashlib.sha512).hexdigest()

        headers = {'key': self.config["zaif"]["ACCESS_KEY"], 'sign': signature}

        #response = requests.post(self.base_url2, headers=headers, data=data)
        response = myutils.post(self.base_url2, headers, data)
        if response.status_code == 200:
            ticker = json.loads(response.text)
            jpy = float(ticker["return"]["funds"]["jpy"])
            btc = float(ticker["return"]["funds"]["btc"])

            print "zaif_amount jpy :" + str(jpy)
            print "zaif_amount btc :" + str(btc)
        else:
            jpy = 0
            btc = 0

        return jpy, btc
Ejemplo n.º 5
0
    def IFD(self, amount, buy, sell):
        """
        docstring
        """
        nonce = myutils.nonce2()
        url = self.base_url
        url_path = "/v1/me/sendparentorder"

        data = {
            "order_method":
            "IFD",
            "minute_to_expire":
            self.config["bitflyer"]["minute_to_expire"],
            "time_in_force":
            "GTC",
            "parameters": [{
                "product_code": "FX_BTC_JPY",
                "condition_type": "LIMIT",
                "side": "BUY",
                "price": buy,
                "size": amount
            }, {
                "product_code": "FX_BTC_JPY",
                "condition_type": "LIMIT",
                "side": "SELL",
                "price": sell,
                "size": amount
            }]
        }

        signature = self._signature(nonce=nonce,
                                    method="POST",
                                    url_path=url_path,
                                    data=data)

        headers = {
            'ACCESS-KEY': self.config["bitflyer"]["ACCESS_KEY"],
            'ACCESS-SIGN': signature,
            'ACCESS-TIMESTAMP': nonce,
            "Content-Type": "application/json"
        }

        #response = requests.post(self.base_url + url_path, headers=headers, data=data)
        response = myutils.post(url=self.base_url + url_path,
                                headers=headers,
                                data=json.dumps(data))

        if response.status_code == 200:
            ## send messege to slack
            myutils.post_slack(name="さやちゃん",
                               text="Bitflyerで" + str(amount) + "BTCを" +
                               str(rate) + "で買っといたよ")
            return True
        return False
    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
Ejemplo n.º 7
0
    def get_incomplete_orders(self):
        """
        Uncertain
        """

        nonce = myutils.nonce2()
        data = {'nonce': nonce, "method": "active_orders"}

        signature = self._signature(data=data)
        #message  = urllib.urlencode(data)
        #signature = hmac.new(self.config["zaif"]["API_SECRET"], message, hashlib.sha512).hexdigest()

        headers = {'key': self.config["zaif"]["ACCESS_KEY"], 'sign': signature}

        #response = requests.post(self.base_url2, headers=headers, data=data)
        response = myutils.post(self.base_url2, headers, data)
        #print response.text
        return response
Ejemplo n.º 8
0
    def cancel_order(self, id):
        """
        Uncertain
        """

        response = {}
        nonce = myutils.nonce2()
        data = {'nonce': nonce, "method": "cancel_order", "order_id": id}

        signature = self._signature(data=data)
        #message  = urllib.urlencode(data)
        #signature = hmac.new(self.config["zaif"]["API_SECRET"], message, hashlib.sha512).hexdigest()

        headers = {'key': self.config["zaif"]["ACCESS_KEY"], 'sign': signature}

        #response = requests.post(self.base_url2, headers=headers, data=data)
        response = myutils.post(self.base_url2, headers, data)

        print response.text
        return response
Ejemplo n.º 9
0
    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
Ejemplo n.º 10
0
    def buy_fx(self, rate, amount):
        """
        docstring
        """
        nonce = myutils.nonce2()
        url = self.base_url
        url_path = "/v1/me/sendchildorder"

        data = {
            "product_code": "FX_BTC_JPY",
            "child_order_type": "LIMIT",
            "side": "BUY",
            "price": rate,
            "size": amount
        }

        signature = self._signature(nonce=nonce,
                                    method="POST",
                                    url_path=url_path,
                                    data=data)

        headers = {
            'ACCESS-KEY': self.config["bitflyer"]["ACCESS_KEY"],
            'ACCESS-SIGN': signature,
            'ACCESS-TIMESTAMP': nonce,
            "Content-Type": "application/json"
        }

        #response = requests.post(self.base_url + url_path, headers=headers, data=data)
        response = myutils.post(url=self.base_url + url_path,
                                headers=headers,
                                data=json.dumps(data))

        if response.status_code == 200:
            ## send messege to slack
            myutils.post_slack(name="さやちゃん",
                               text="Bitflyerで" + str(amount) + "BTCを" +
                               str(rate) + "で買っといたよ")
            return True
        return False
    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