예제 #1
0
    def response_handler(self, response, command, **kwargs):
        if ("error" in response) and (response["error"] is not None):
            raise PoloniexError(response["error"])

        for case in switch(command):
            if case("generateNewAddress"):
                if response["success"] == 0:
                    if "address" in response:
                        raise AddressAlreadyExist("Address [{}] already exist".format(response["address"]))
                    elif "response" in response:
                        raise PoloniexError(response["response"])

        return response
예제 #2
0
    def response_handler(self, response, command, **kwargs):
        if ("error" in response) and (response["error"] is not None):
            raise PoloniexError(response["error"])

        for case in switch(command):
            if case("generateNewAddress"):
                if response["success"] == 0:
                    if "address" in response:
                        raise AddressAlreadyExist(
                            "Address [{}] already exist".format(
                                response["address"]))
                    elif "response" in response:
                        raise PoloniexError(response["response"])

        return response
예제 #3
0
    def get_params(self, command, **kwargs):
        currency_pair = kwargs.get("currency_pair")
        if currency_pair and currency_pair not in constants.CURRENCY_PAIRS + [
                "all"
        ]:
            raise PoloniexError(
                "Currency pair '{}' not available.".format(currency_pair))

        depth = kwargs.get("depth")

        start = kwargs.get("start")
        if start:
            start = start.timestamp()

        end = kwargs.get("end")
        if end:
            end = end.timestamp()

        period = kwargs.get("period")
        if period and period not in constants.CHART_DATA_PERIODS:
            raise PoloniexError("Period '{}' not available.".format(period))

        for case in switch(command):
            if case("returnTicker"):
                method = "get"
                params = {"command": command}
                break

            if case("return24hVolume"):
                method = "get"
                params = {"command": command}
                break

            if case("returnOrderBook"):
                method = "get"
                params = {
                    "command": command,
                    "currencyPair": currency_pair,
                    "depth": depth
                }
                break

            if case("returnChartData"):
                method = "get"
                params = {
                    "command": command,
                    "currencyPair": currency_pair,
                    "period": period,
                    "start": start,
                    "end": end
                }
                break

            if case("returnCurrencies"):
                method = "get"
                params = {"command": command}
                break

            if case("returnTradeHistory"):
                method = "get"
                params = {
                    "command": command,
                    "currencyPair": currency_pair,
                    "start": start,
                    "end": end
                }
                break

            if case():
                raise NotImplementedError(
                    "There is no command '{}'.".format(command))

        return method, params
예제 #4
0
    def get_params(self, command, **kwargs):
        currency_pair = kwargs.get("currency_pair")
        if currency_pair and currency_pair not in constants.CURRENCY_PAIRS + [
                "all"
        ]:
            raise PoloniexError(
                "Currency pair '{}' not available.".format(currency_pair))

        currency = kwargs.get("currency")

        start = kwargs.get("start")
        if start:
            start = start.timestamp()

        end = kwargs.get("end")
        if end:
            end = end.timestamp()

        rate = kwargs.get("rate")
        amount = kwargs.get("amount")
        address = kwargs.get("address")
        order_number = kwargs.get("order_number")

        for case in switch(command):
            if case("returnBalances"):
                method = "post"
                params = {"command": command}
                break

            if case("returnCompleteBalances"):
                method = "post"
                params = {"command": command}
                break

            if case("returnDepositAddresses"):
                method = "post"
                params = {"command": command}
                break

            if case("generateNewAddress"):
                method = "post"
                params = {"command": command, "currency": currency}
                break

            if case("returnDepositsWithdrawals"):
                method = "post"
                params = {"command": command, "start": start, "end": end}
                break

            if case("returnOpenOrders"):
                method = "post"
                params = {"command": command, "currencyPair": currency_pair}
                break

            if case("returnTradeHistory"):
                method = "post"
                params = {
                    "command": command,
                    "currencyPair": currency_pair,
                    "start": start,
                    "end": end
                }
                break

            if case("returnOrderTrades"):
                method = "post"
                params = {"command": command, "orderNumber": order_number}
                break

            if case("buy"):
                method = "post"
                params = {
                    "command": command,
                    "currencyPair": currency_pair,
                    "rate": rate,
                    "amount": amount
                }
                break

            if case("sell"):
                method = "post"
                params = {
                    "command": command,
                    "currencyPair": currency_pair,
                    "rate": rate,
                    "amount": amount
                }
                break

            if case("withdraw"):
                method = "post"
                params = {
                    "currency": currency,
                    "amount": amount,
                    "address": address
                }
                break

            if case("cancelOrder"):
                method = "post"
                params = {
                    "command": "cancelOrder",
                    "orderNumber": order_number
                }
                break

            if case():
                raise NotImplementedError(
                    "There is no command '{}'.".format(command))

        return method, params
예제 #5
0
    def get_params(self, command, **kwargs):
        currency_pair = kwargs.get("currency_pair")
        if currency_pair and currency_pair not in constants.CURRENCY_PAIRS + ["all"]:
            raise PoloniexError("Currency pair '{}' not available.".format(currency_pair))

        depth = kwargs.get("depth")

        start = kwargs.get("start")
        if start:
            start = time.mktime(start.timetuple())

        end = kwargs.get("end")
        if end:
            end = time.mktime(end.timetuple())

        period = kwargs.get("period")
        if period and period not in constants.CHART_DATA_PERIODS:
            raise PoloniexError("Period '{}' not available.".format(period))

        for case in switch(command):
            if case("returnTicker"):
                method = "get"
                params = {"command": command}
                break

            if case("return24hVolume"):
                method = "get"
                params = {"command": command}
                break

            if case("returnOrderBook"):
                method = "get"
                params = {
                    "command": command,
                    "currencyPair": currency_pair,
                    "depth": depth
                }
                break

            if case("returnChartData"):
                method = "get"
                params = {
                    "command": command,
                    "currencyPair": currency_pair,
                    "period": period,
                    "start": start,
                    "end": end
                }
                break

            if case("returnCurrencies"):
                method = "get"
                params = {"command": command}
                break

            if case("returnTradeHistory"):
                method = "get"
                params = {
                    "command": command,
                    "currencyPair": currency_pair,
                    "start": start,
                    "end": end
                }
                break

            if case():
                raise NotImplementedError("There is no command '{}'.".format(command))

        return method, params
예제 #6
0
    def get_params(self, command, **kwargs):
        currency_pair = kwargs.get("currency_pair")
        if currency_pair and currency_pair not in constants.CURRENCY_PAIRS + ["all"]:
            raise PoloniexError("Currency pair '{}' not available.".format(currency_pair))

        currency = kwargs.get("currency")

        start = kwargs.get("start")
        if start:
            start = time.mktime(start.timetuple()),

        end = kwargs.get("end")
        if end:
            end = time.mktime(end.timetuple())

        rate = kwargs.get("rate")
        amount = kwargs.get("amount")
        address = kwargs.get("address")
        order_number = kwargs.get("order_number")

        for case in switch(command):
            if case("returnBalances"):
                method = "post"
                params = {"command": command}
                break

            if case("returnCompleteBalances"):
                method = "post"
                params = {"command": command}
                break

            if case("returnDepositAddresses"):
                method = "post"
                params = {"command": command}
                break

            if case("generateNewAddress"):
                method = "post"
                params = {
                    "command": command,
                    "currency": currency
                }
                break

            if case("returnDepositsWithdrawals"):
                method = "post"
                params = {
                    "command": command,
                    "start": start,
                    "end": end
                }
                break

            if case("returnOpenOrders"):
                method = "post"
                params = {
                    "command": command,
                    "currencyPair": currency_pair
                }
                break

            if case("returnTradeHistory"):
                method = "post"
                params = {
                    "command": command,
                    "currencyPair": currency_pair,
                    "start": start,
                    "end": end
                }
                break

            if case("returnOrderTrades"):
                method = "post"
                params = {
                    "command": command,
                    "orderNumber": order_number
                }
                break

            if case("buy"):
                method = "post"
                params = {
                    "command": command,
                    "currencyPair": currency_pair,
                    "rate": rate,
                    "amount": amount
                }
                break

            if case("sell"):
                method = "post"
                params = {
                    "command": command,
                    "currencyPair": currency_pair,
                    "rate": rate,
                    "amount": amount
                }
                break

            if case("withdraw"):
                method = "post"
                params = {
                    "currency": currency,
                    "amount": amount,
                    "address": address
                }
                break

            if case("cancelOrder"):
                method = "post"
                params = {
                    "command": "cancelOrder",
                    "orderNumber": order_number
                }
                break

            if case():
                raise NotImplementedError("There is no command '{}'.".format(command))

        return method, params