예제 #1
0
파일: base_bot.py 프로젝트: madmis/dimka
    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)
예제 #2
0
    class TestTrade(unittest.TestCase):
        def setUp(self):
            self.key_handler = keyhandler.KeyHandler(TEST_KEY_FILE)
            self.connection = WexConnection()

        def tearDown(self):
            self.connection.close()
            self.connection = None
            self.key_handler.close()

        def test_construction(self):
            keys = list(self.key_handler.keys)
            t = TradeApi(keys[0], self.key_handler, self.connection)

        def test_key_info(self):
            for key in self.key_handler.keys:
                t = TradeApi(key, self.key_handler, self.connection)
                r = t.get_info()
예제 #3
0
    def test_get_ticker(self):
        connection = WexConnection()
        api = PublicApi(connection)
        ticker = api.get_ticker(self.pair)

        self.assertIsInstance(ticker, models.Ticker)

        info = InfoApi(connection)
        api.get_ticker(self.pair, info=info)
예제 #4
0
파일: base_bot.py 프로젝트: madmis/dimka
    def low_high_daily_prices(self) -> Tuple[Decimal, Decimal]:
        """
        Get low and high daily prices

        :return: tuple low, high
        """
        ticker = PublicApi(WexConnection()).get_ticker(self.pair)

        return ticker.low, ticker.high
예제 #5
0
    def test_get_history(self):
        connection = WexConnection()
        api = PublicApi(connection)
        history = api.get_trade_history(self.pair, limit=1)

        self.assertIsInstance(history, list)
        self.assertIsInstance(history[0], models.Trade)

        info = InfoApi(connection)
        api.get_trade_history(self.pair, info=info, limit=1)
예제 #6
0
파일: base_bot.py 프로젝트: madmis/dimka
 def __init__(self, key: str, key_handler: KeyHandler, config: Config,
              args: Namespace):
     self.key = key
     self.key_handler = key_handler
     self.params = config.params
     self.pair = config.params.get("pair")
     self.logger = config.log
     self.args = args
     self.pair_info = InfoApi(WexConnection()).get_pair_info(
         config.params.get("pair"))
예제 #7
0
파일: base_bot.py 프로젝트: madmis/dimka
    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]
예제 #8
0
파일: base_bot.py 프로젝트: madmis/dimka
    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))
예제 #9
0
    def test_get_depth(self):
        connection = WexConnection()
        api = PublicApi(connection)
        self.assertIsInstance(api.get_depth(self.pair, limit=1), tuple)

        asks, bids = api.get_depth(self.pair, limit=1)

        self.assertIsInstance(asks, list)
        self.assertIsInstance(asks[0], list)
        self.assertIsInstance(asks[0][0], Decimal)
        self.assertIsInstance(asks[0][1], Decimal)

        self.assertIsInstance(bids, list)
        self.assertIsInstance(bids[0], list)
        self.assertIsInstance(bids[0][0], Decimal)
        self.assertIsInstance(bids[0][1], Decimal)

        info = InfoApi(connection)
        api.get_depth(self.pair, info=info, limit=1)
예제 #10
0
파일: base_bot.py 프로젝트: madmis/dimka
    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
예제 #11
0
 def setUp(self):
     self.key_handler = keyhandler.KeyHandler(TEST_KEY_FILE)
     self.connection = WexConnection()
예제 #12
0
파일: base_bot.py 프로젝트: madmis/dimka
    def top_sell_price(self) -> Decimal:
        """ Top sell price - top price from sell queue """
        with WexConnection() as conn:
            asks, _ = PublicApi(conn).get_depth(self.pair, limit=1)

            return asks[0][0]
예제 #13
0
파일: base_bot.py 프로젝트: madmis/dimka
    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)
예제 #14
0
파일: base_bot.py 프로젝트: madmis/dimka
    def top_buy_price(self) -> Decimal:
        """ Top buy price - top price from buy queue """
        with WexConnection() as conn:
            _, bids = PublicApi(conn).get_depth(self.pair, limit=1)

            return bids[0][0]