Example #1
0
    def simulated_account_add_or_adjust_coin_amount(self, accountguid: str,
                                                    coin: str, amount: float):
        """Add or Edit simulated account coin amount

        :param accountguid: str: The account guid
        :param coin: str: Coin to change
        :param amount: float: Amount of coins to use

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result :class:`~haasomeapi.dataobjects.accountdata.Wallet`
        """

        response = super()._execute_request(
            "/SimulatedAccountAddOrAdjustCoinAmount", {
                "accountGuid": accountguid,
                "coin": coin,
                "amount": float(str(amount).replace(',', '.'))
            })

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"],
                super()._from_json(response["Result"], Wallet))
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #2
0
    def get_price_markets(self, pricesource: EnumPriceSource):
        """ Returns markets for specified price source

        :param pricesource: :class:`~haasomeapi.enums.EnumPriceSource`: Price Source (Exchange) 

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result List[:class:`~haasomeapi.dataobjects.marketdata.Market`] of markets
        """

        response = super()._execute_request("/GetPriceMarkets", {
            "priceSourceName":
            EnumPriceSource(pricesource).name.capitalize()
        })

        markets = []

        for market in response["Result"]:
            markets.append(super()._from_json(market, Market))

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], markets)
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #3
0
    def get_order_book(self, pricesource: EnumPriceSource, primarycoin: str,
                       secondarycoin: str, contractname: str):
        """ Returns the current order book for specified market

        :param pricesource: :class:`~haasomeapi.enums.EnumPriceSource`: Price Source (Exchange) to get ticker from 
        :param primarycoin: str: Primary currency Ex. If BNB/BTC then set this to BNB
        :param secondarycoin: str: Secondary currency Ex. If BNB/BTC then set this to BTC
        :param contractname: str:  Contract Name (Optional)

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result :class:`~haasomeapi.dataobjects.marketdata.Orderbook`: Orderbook object
        """

        response = super()._execute_request(
            "/GetOrderbook", {
                "priceSourceName":
                EnumPriceSource(pricesource).name.capitalize(),
                "primaryCoin": primarycoin,
                "secondaryCoin": secondarycoin,
                "contractName": contractname
            })
        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"],
                super()._from_json(response["Result"], Orderbook))
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #4
0
    def place_exit_short_order(self,
                               accountguid: str,
                               primarycoin: str,
                               secondarycoin: str,
                               price: float,
                               amount: float,
                               leverage: float,
                               timeout: int = 0,
                               contractname: str = "",
                               userguid: str = "",
                               templateguid: str = ""):
        """ Place a exit short order for Leverage/Margin

        :param accountguid: str: The account guid
        :param primarycoin: str: Primary currency Ex. If BNB/BTC then set this to BNB
        :param secondarycoin: str: Secondary currency Ex. If BNB/BTC then set this to BTC
        :param price: float: Price to place order at
        :param amount: float: Trade Amount
        :param leverage: float: Leverage percentage amount
        :param timeout: int:  (Default value = 0) Order Timeout in minutes
        :param contractname: str: (Default value = "") Contract name to use
        :param userguid: str:  (Default value = "") User guid for order
        :param templateguid: str:  (Default value = "") Order template guid to use

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result str: Template guid
        """

        data = {
            "accountGuid": accountguid,
            "primaryCoin": primarycoin,
            "secondaryCoin": secondarycoin,
            "price": '{0:.08f}'.format(float(str(price).replace(',', '.'))),
            "amount": '{0:.08f}'.format(float(str(amount).replace(',', '.'))),
            "leverage": float(str(leverage).replace(',', '.'))
        }

        if timeout > 0:
            data["timeout"] = str(timeout)

        if contractname:
            data["contractName"] = contractname

        if userguid:
            data["userGuid"] = userguid

        if templateguid:
            data["templateGuid"] = templateguid

        response = super()._execute_request("/PlaceLeverageExitShortOrder",
                                            data)

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], response["Result"])
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #5
0
    def setup_take_profit_order_leverage(self, accountguid: str, orderguid: str, name: str, primarycoin: str, secondarycoin: str,
                                         contractname: str, leverage: float, direction: EnumOrderType,
                                         executingtemplateguid: str, triggerprice: float, executionprice: float,
                                         amount: float, startorderonactivation: bool, startorderprice: float,
                                         starttemplateguid: str, activate: bool):
        """ Modify a take profit order for a leverage/margin market

        :param accountguid: str: The account guid
        :param orderguid: str: The advanced order guid to modify
        :param name: str: Name of the advanced order
        :param primarycoin: str: Primary currency Ex. If BNB/BTC then set this to BNB
        :param secondarycoin: str: Secondary currency Ex. If BNB/BTC then set this to BTC
        :param contractname: str: Name of the contract (Options)
        :param leverage: float:  Leverage percentage
        :param direction: EnumOrderType: Order Direction (Long/Short)
        :param executingtemplateguid: str: Executing Template To Use
        :param triggerprice: float:  Trigger price to execute the stop
        :param executionprice: float: Price for the order to be placed at
        :param amount: float: Trade Amount
        :param startorderonactivation: bool: Start the adavnced order only on activation 
        :param startorderprice: float: What price to start the order
        :param starttemplateguid: str: The template guid to use for the order
        :param activate: bool: Activate the order.

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result :class:`~from haasomeapi.dataobjects.advancedorders.StopTakeProfitOrder`
        """

        response = super()._execute_request("/AddTakeProfitOrder",
                                            {"guid": orderguid,
                                             "name": name,
                                             "accountGuid": accountguid,
                                             "primaryCoin": primarycoin,
                                             "secondaryCoin": secondarycoin,
                                             "contractname": contractname,
                                             "leverage": float(str(leverage).replace(',', '.')),
                                             "orderDirection": EnumOrderType(direction).name.capitalize(),
                                             "executingTemplateGuid": executingtemplateguid,
                                             "triggerPrice": float(str(triggerprice).replace(',', '.')),
                                             "executionPrice": float(str(executionprice).replace(',', '.')),
                                             "amount": float(str(amount).replace(',', '.')),
                                             "startOrderOnActivation": str(startorderonactivation).lower(),
                                             "startOrderPrice": float(str(startorderprice).replace(',', '.')),
                                             "startTemplateGuid": starttemplateguid,
                                             "activate": str(activate).lower()})
        try:
            return HaasomeClientResponse(EnumErrorCode(int(response["ErrorCode"])),
                                         response["ErrorMessage"], super()._from_json(response["Result"], StopTakeProfitOrder))
        except:
            return HaasomeClientResponse(EnumErrorCode(int(response["ErrorCode"])),
                                         response["ErrorMessage"], {})
Example #6
0
    def get_enabled_accounts(self):
        """Retrives a dictionary of enabled accounts

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result dict
        """

        response = super()._execute_request("/GetEnabledAccounts", {})

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], response["Result"])
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #7
0
    def get_enabled_price_sources(self):
        """ Returns all enabled price sources

        
        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result List[str] of all the enabled sources
        """
        response = super()._execute_request("/GetEnabledPriceSources", {})

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], response["Result"])
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #8
0
    def remove_advanced_order(self, guid: str):
        """ Removes (deletes) advanced order

        :param guid: str: advanced order guid

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result bool if success
        """

        response = super()._execute_request("/RemoveAdvancedOrder", {"guid": guid})

        try:
            return HaasomeClientResponse(EnumErrorCode(int(response["ErrorCode"])),
                                         response["ErrorMessage"], bool(response["Result"]))
        except:
            return HaasomeClientResponse(EnumErrorCode(int(response["ErrorCode"])),
                                         response["ErrorMessage"], {})
Example #9
0
    def deactivate_advanced_order(self, guid: str):
        """ Deactivates an advanced order

        :param guid: str: advanced order guid

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result :class:`~haasomeapi.dataobjects.advancedorders.AdvancedOrderBase`
        """

        response = super()._execute_request("/DeactivateAdvancedOrder", {"guid": guid})

        try:
            return HaasomeClientResponse(EnumErrorCode(int(response["ErrorCode"])),
                                         response["ErrorMessage"], super()._from_json(response["Result"], AdvancedOrderBase))
        except:
            return HaasomeClientResponse(EnumErrorCode(int(response["ErrorCode"])),
                                         response["ErrorMessage"], {})
Example #10
0
    def get_order_templates(self):
        """Gets current order templates

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result dict
        """

        response = super()._execute_request("/GetOrderTemplates", {})

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], response["Result"])
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #11
0
    def get_software_details(self):
        """Retrives the current software information

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result :class:`~haasomeapi.dataobjects.accountdata.SoftwareInformation`
        """

        response = super()._execute_request("/GetSoftwareDetails", {})

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"],
                super()._from_json(response["Result"], SoftwareInformation))
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #12
0
    def add_trailing_stop_order(self, accountguid: str, name: str,  primarycoin: str, secondarycoin: str,
                              direction: EnumOrderType, executingtemplateguid: str, trailingstoppercentage: float,
                              amount: float, startorderonactivation: bool, startorderprice: float, starttemplateguid: str,
                              activate: bool):
        """ Create a trailing stop order for a spot market

        :param accountguid: str: The account guid
        :param name: str: Name of the advanced order
        :param primarycoin: str: Primary currency Ex. If BNB/BTC then set this to BNB
        :param secondarycoin: str: Secondary currency Ex. If BNB/BTC then set this to BTC
        :param direction: EnumOrderType: Order Direction (Buy / Sell)  
        :param executingtemplateguid: str: Executing Template To Use
        :param trailingstoppercentage: float: Percentage for trailing top to follow
        :param amount: float: Trade Amount
        :param startorderonactivation: bool: Start the adavnced order only on activation 
        :param startorderprice: float: What price to start the order
        :param starttemplateguid: str: The template guid to use for the order
        :param activate: bool: Activate the order.

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result :class:`~from haasomeapi.dataobjects.advancedorders.StopTakeProfitOrder`
        """

        response = super()._execute_request("/AddTrailingStopOrder",
                                             {"name": name,
                                              "accountGuid": accountguid,
                                              "primaryCoin": primarycoin,
                                              "secondaryCoin": secondarycoin,
                                              "leverage": "0",
                                              "orderDirection": EnumOrderType(direction).name.capitalize(),
                                              "executingTemplateGuid": executingtemplateguid,
                                              "trailingStopPercentage": float(str(trailingstoppercentage).replace(',', '.')),
                                              "amount": float(str(amount).replace(',', '.')),
                                              "startOrderOnActivation": str(startorderonactivation).lower(),
                                              "startOrderPrice": float(str(startorderprice).replace(',', '.')),
                                              "startTemplateGuid": starttemplateguid,
                                              "activate": str(activate).lower()})

        try:
            return HaasomeClientResponse(EnumErrorCode(int(response["ErrorCode"])),
                                         response["ErrorMessage"], super()._from_json(response["Result"], TrailingStop))
        except:
            return HaasomeClientResponse(EnumErrorCode(int(response["ErrorCode"])),
                                         response["ErrorMessage"], {})
Example #13
0
    def get_history(self, pricesource: EnumPriceSource, primarycoin: str,
                    secondarycoin: str, contractname: str, interval: int,
                    depth: int):
        """ Get price history from price servers

        :param pricesource: :class:`~haasomeapi.enums.EnumPriceSource`: Price Source (Exchange) to get ticker from 
        :param primarycoin: str: Primary currency Ex. If BNB/BTC then set this to BNB
        :param secondarycoin: str: Secondary currency Ex. If BNB/BTC then set this to BTC
        :param contractname: str:  Contract Name (Optional)
        :param interval: int: The candle interval value Ex. 1,2,3,5,15,30,etc (In minutes)
        :param depth: int: The depth or how many candles to get

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result List[:class:`~haasomeapi.dataobjects.marketdata.PriceTick`]: List of Price Tick objects
        """

        response = super()._execute_request(
            "/GetHistory", {
                "priceSourceName":
                EnumPriceSource(pricesource).name.capitalize(),
                "primaryCoin": primarycoin,
                "secondaryCoin": secondarycoin,
                "contractName": contractname,
                "interval": str(interval),
                "depth": str(depth)
            })

        priceticks = []

        try:
            for pricetick in response["Result"]:
                priceTickModel = super()._from_json(pricetick, PriceTick)
                priceTickModel.timeStamp = parser.parse(
                    priceTickModel.timeStamp)
                priceticks.append(priceTickModel)

            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], priceticks)
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #14
0
    def cancel_template(self, templateguid: str):
        """ Cancel a pending template order

        :param templateguid: str: Template order guid

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result bool: If template cancelled succesfully
        """

        response = super()._execute_request("/CancelTemplate",
                                            {"templateGuid": templateguid})

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], bool(response["Result"]))
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #15
0
    def get_advanced_orders(self):
        """ Retrieves the current created advanced orders

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result Dict[:class:`~haasomeapi.dataobjects.advancedorders.AdvancedOrderBase`]
        """

        response = super()._execute_request("/GetAdvancedOrders", {})

        advancedorders = {}

        for key, value in response["Result"].items():
            advancedorders[key] = super()._from_json(value, AdvancedOrderBase)

        try:
            return HaasomeClientResponse(EnumErrorCode(int(response["ErrorCode"])),
                                         response["ErrorMessage"], advancedorders)
        except:
            return HaasomeClientResponse(EnumErrorCode(int(response["ErrorCode"])),
                                         response["ErrorMessage"], {})
Example #16
0
    def simulated_account_clear_wallet(self, accountguid: str):
        """Clears the simulated account wallet if the account is a sim account.

        :param accountguid: str: The account guid

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result :class:`~haasomeapi.dataobjects.accountdata.Wallet`
        """

        response = super()._execute_request("/SimulatedAccountClearWallet",
                                            {"accountGuid": accountguid})

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"],
                super()._from_json(response["Result"], Wallet))
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #17
0
    def get_account_details(self, accountguid: str):
        """Retrives account details from supplied guid

        :param accountguid: str: The account guid

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result :class:`~haasomeapi.dataobjects.accountdata.AccountInformation`
        """

        response = super()._execute_request("/GetAccountDetails",
                                            {"accountGuid": accountguid})

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"],
                super()._from_json(response["Result"], AccountInformation))
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #18
0
    def get_template_status(self, templateguid: str):
        """Gets status for template

        :param templateguid: str: Template Guid

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result :class:`~haasomeapi.enums.EnumOrderStatus`
        """

        response = super()._execute_request("/GetTemplateStatus",
                                            {"templateGuid": templateguid})

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"],
                EnumOrderStatus(int(response["Result"])))
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #19
0
    def get_wallet(self, accountguid: str):
        """Get wallet for specific account

        :param accountguid: str: The account guid

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result :class:`~haasomeapi.dataobjects.accountdata.Wallet`
        """

        response = super()._execute_request("/GetWallet",
                                            {"accountGuid": accountguid})

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"],
                super()._from_json(response["Result"], Wallet))
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #20
0
    def get_open_orders(self, accountguid: str):
        """Gets all open orders for a specific account

        :param accountguid: str: The account guid

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result :class:`~haasomeapi.dataobjects.accountdata.OrderContainer`
        """

        response = super()._execute_request("/GetOpenOrders",
                                            {"accountGuid": accountguid})

        order_container = super()._from_json(response["Result"],
                                             OrderContainer)

        exchangeorderlist = {}
        marginorderlist = {}
        leverageorderlist = {}

        for orderstr, order in order_container.exchangeOrderList.items():
            exchangeorderlist[orderstr] = super()._from_json(order, BaseOrder)

        for orderstr, order in order_container.marginOrderList.items():
            marginorderlist[orderstr] = super()._from_json(order, BaseOrder)

        for orderstr, order in order_container.leverageOrderList.items():
            leverageorderlist[orderstr] = super()._from_json(order, BaseOrder)

        order_container.exchangeOrderList = exchangeorderlist
        order_container.marginOrderList = marginorderlist
        order_container.leverageOrderList = leverageorderlist

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], order_container)
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #21
0
    def get_all_price_markets(self):
        """ Returns all  markets

        
        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result List[:class:`~haasomeapi.dataobjects.marketdata.Market`] of markets
        """
        response = super()._execute_request("/GetAllPriceMarkets", {})

        markets = []

        for market in response["Result"]:
            markets.append(super()._from_json(market, Market))

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], markets)
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #22
0
    def get_all_account_details(self):
        """Retrives a dictionary of all account names with guid

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns:  In .result Dict[:class:`~haasomeapi.dataobjects.accountdata.AccountInformation`]
        """

        response = super()._execute_request("/GetAllAccountDetails", {})

        accounts = {}

        for key, value in response["Result"].items():
            accounts[key] = (super()._from_json(value, AccountInformation))

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], accounts)
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #23
0
    def cancel_order(self, accountguid: str, orderguid: str):
        """ Cancel a pending order

        :param accountguid: str: The account guid
        :param orderguid: str: Order guid to cancel

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result bool: If order cancelled succesfully
        """

        response = super()._execute_request("/CancelOrder", {
            "accountGuid": accountguid,
            "order": orderguid
        })

        try:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], bool(response["Result"]))
        except:
            return HaasomeClientResponse(
                EnumErrorCode(int(response["ErrorCode"])),
                response["ErrorMessage"], {})
Example #24
0
    def get_all_open_orders(self):
        """Get all open orders for all accounts

        :returns: :class:`~haasomeapi.dataobjects.util.HaasomeClientResponse`
        :returns: In .result dict
        """

        accounts = self.get_enabled_accounts()

        if accounts.errorCode != EnumErrorCode.SUCCESS:
            return HaasomeClientResponse(accounts.errorCode,
                                         accounts.errorMessage, {})

        results = {}

        for key, value in accounts.result.items():
            openorders = self.get_open_orders(key)
            results[key] = openorders.result

        try:
            return HaasomeClientResponse(EnumErrorCode.SUCCESS, "", results)
        except:
            return HaasomeClientResponse(EnumErrorCode.FAILURE, "", {})