Exemplo n.º 1
0
    def create_sell_order(self, sell_price: Decimal,
                          sell_amount: Decimal) -> models.TradeResult:
        """ Create buy order """
        with WexConnection() as conn:
            t = TradeApi(self.key, self.key_handler, conn)

            return t.trade(self.pair, 'sell', sell_price, sell_amount)
Exemplo n.º 2
0
    def funds(self) -> Tuple[Decimal, Decimal]:
        """
        Get account funds according to trading pair:
            base coin, quote (secondary) coin (from current pair)

        Returns:
            Tuple[Decimal, Decimal]: first - is base coin funds, second - quote coin funds
        """
        with WexConnection() as conn:
            t = TradeApi(self.key, self.key_handler, conn)
            r = t.get_info()

            base, quote = self.split_pair()

            return r.funds[base], r.funds[quote]
Exemplo n.º 3
0
    def cancel_buy_orders(self):
        """ Cancel all opened BUY orders """
        buy_orders = self.active_orders('buy')

        if len(buy_orders) > 0:

            self.logger.warning("Cancel all opened BUY orders: {}".format(
                len(buy_orders)))

            with WexConnection() as conn:
                t = TradeApi(self.key, self.key_handler, conn)

                for order in buy_orders:
                    result = t.cancel_order(order.order_id)
                    self.logger.debug("  Canceled order #{}".format(
                        result.order_id))
Exemplo n.º 4
0
    def active_orders(self, orders_type: str = None) -> List[models.Order]:
        """
        Get active orders list.
        If defined type (buy, sell) return orders with this type
        """
        with WexConnection() as conn:
            t = TradeApi(self.key, self.key_handler, conn)

            orders = t.active_orders(self.pair)

            if orders_type is not None:
                result = []
                for order in orders:
                    if order.type == orders_type:
                        result.append(order)

                return result

            return orders
Exemplo n.º 5
0
 def test_key_info(self):
     for key in self.key_handler.keys:
         t = TradeApi(key, self.key_handler, self.connection)
         r = t.get_info()
Exemplo n.º 6
0
 def test_construction(self):
     keys = list(self.key_handler.keys)
     t = TradeApi(keys[0], self.key_handler, self.connection)
Exemplo n.º 7
0
    def cancel_order(self, order_id: int) -> models.CancelOrderResult:
        """ Cancel order """
        with WexConnection() as conn:
            t = TradeApi(self.key, self.key_handler, conn)

            return t.cancel_order(order_id)