コード例 #1
0
    def get_trading_commission(self):
        """
        Uncertain 
        """

        nonce = myutils.nonce2()
        url = self.base_url
        url_path = "/v1/me/gettradingcommission"

        params = {"product_code": "BTC_JPY"}

        signature = self._signature(nonce=nonce,
                                    method="GET",
                                    url_path=url_path,
                                    params="?" + urllib.urlencode(params))

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

        #response = requests.get(url + url_path, headers=headers)
        response = myutils.get(url=self.base_url + url_path,
                               headers=headers,
                               params=params)
        commission = json.loads(response.text)
        print "bitfyer commission_rate : " + str(commission["commission_rate"])

        return commission["commission_rate"]
コード例 #2
0
    def get_incomplete_orders_fx(self):
        """
        Uncertain 
        """

        nonce = myutils.nonce2()
        url = self.base_url
        url_path = "/v1/me/getchildorders"
        params = {"child_order_state": "ACTIVE", "product_code": "FX_BTC_JPY"}

        signature = self._signature(nonce=nonce,
                                    method="GET",
                                    url_path=url_path,
                                    params="?" + urllib.urlencode(params))
        #message  = nonce + "get" + url_path
        #signature = hmac.new(self.config["bitflyer"]["API_SECRET"], message, hashlib.sha256).hexdigest()

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

        #response = requests.get(url + url_path, headers=headers)
        response = myutils.get(url=self.base_url + url_path,
                               headers=headers,
                               params=params)
        if response.status_code == 200:
            orders = json.loads(response.text)
            #print orders
        return response
コード例 #3
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
コード例 #4
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
コード例 #5
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
コード例 #6
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
コード例 #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
コード例 #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
コード例 #9
0
    def get_balance(self):
        """
        Uncertain 
        return jpy, btc
        """

        nonce = myutils.nonce2()
        url = self.base_url
        url_path = "/v1/me/getbalance"

        signature = self._signature(nonce=nonce,
                                    method="GET",
                                    url_path=url_path)
        #message  = nonce + "get" + url_path
        #signature = hmac.new(self.config["bitflyer"]["API_SECRET"], message, hashlib.sha256).hexdigest()

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

        #response = requests.get(url + url_path, headers=headers)
        response = myutils.get(url=self.base_url + url_path, headers=headers)
        if response.status_code == 200:
            balance = json.loads(response.text)
            ## Analysis of response to json and confirmation of balance
            for resp in balance:
                if resp["currency_code"] == "JPY":
                    jpy = float(resp["amount"])
                elif resp["currency_code"] == "BTC":
                    btc = float(resp["amount"])

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

        return jpy, btc
コード例 #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