Example #1
0
    def withdraw_crypto(self,
                        currency: str,
                        amount: str,
                        address: str,
                        payment_id: str = None,
                        include_fee: bool = None,
                        auto_commit: bool = None) -> str:
        """Withdraw cryptocurrency.

        Requires authentication.

        https://api.exchange.cryptomkt.com/#withdraw-crypto

        :param currency: currency code of the crypto to withdraw.
        :param amount: the amount to be sent to the specified address.
        :param address: the address identifier.
        :param paymentId: Optional.
        :param includeFee: Optional. If True then the total spent amount includes fees. Default False.
        :param autoCommit: Optional. If False then you should commit or rollback transaction in an hour. Used in two phase commit schema. Default True.

        :returns: The transaction id, asigned by the exchange.

        .. code-block:: python
        "d2ce578f-647d-4fa0-b1aa-4a27e5ee597b"
        """
        params = args.DictBuilder().currency(currency).address(address).amount(
            amount).payment_id(payment_id).include_fee(
                include_fee).auto_commit(auto_commit).build()
        return self._post(endpoint='account/crypto/withdraw',
                          params=params)['id']
Example #2
0
    def get_active_order(self,
                         client_order_id: str,
                         wait: int = None) -> Dict[str, Any]:
        """Get an order by its client order id.

        Requires authentication.

        https://api.exchange.cryptomkt.com/#get-active-order-by-clientorderid

        :param client_order_id: The clientOrderId of the order.
        :param wait: Optional. Time in milliseconds. Max value is 60000. Default is None. While using long polling request: if order is filled, cancelled or expired, order info will be returned instantly. For other order statuses, actual order info will be returned after specified wait time.

        :returns: An order of the account.

        .. code-block:: python
        {
            "id": 840450210,
            "clientOrderId": "c1837634ef81472a9cd13c81e7b91401",
            "symbol": "ETHBTC",
            "side": "buy",
            "status": "partiallyFilled",
            "type": "limit",
            "timeInForce": "GTC",
            "quantity": "0.020",
            "price": "0.046001",
            "cumQuantity": "0.005",
            "postOnly": false,
            "createdAt": "2017-05-12T17:17:57.437Z",
            "updatedAt": "2017-05-12T17:18:08.610Z"
        }
        """
        params = args.DictBuilder().wait(wait).build()
        return self._get(endpoint=f'order/{client_order_id}')
Example #3
0
    def create_order(self,
                     symbol: str,
                     side: str,
                     quantity: str,
                     client_order_id: str = None,
                     order_type: str = None,
                     price: str = None,
                     stop_price: str = None,
                     time_in_force: str = None,
                     expire_time: str = None,
                     strict_validate: bool = None,
                     post_only: bool = None) -> Dict[str, Any]:
        """Creates a new order.

        Requires authentication.

        https://api.exchange.cryptomkt.com/#create-new-order

        :param symbol: Trading symbol.
        :param side: 'buy' or 'sell'.
        :param quantity: Order quantity.
        :param client_order_id: Optional. If given must be unique within the trading day, including all active orders. If not given, is generated by the server.
        :param order_type: Optional. 'limit', 'market', 'stopLimit' or 'stopMarket'. Default is 'limit'.
        :param time_in_force: Optional. 'GTC', 'IOC', 'FOK', 'Day', 'GTD'. Default to 'GTC'.
        :param price: Required for 'limit' and 'stopLimit'. limit price of the order.
        :param stop_price: Required for 'stopLimit' and 'stopMarket' orders. stop price of the order.
        :param expire_time: Required for orders with timeInForce = 'GDT'.
        :param strict_validate: Optional. If False, the server rounds half down for tickerSize and quantityIncrement. Example of ETHBTC: tickSize = '0.000001', then price '0.046016' is valid, '0.0460165' is invalid. 
        :param post_only: Optional. If True, your post_only order causes a match with a pre-existing order as a taker, then the order will be cancelled.

        :returns: An order of the account.

        .. code-block:: python
        {
            "id": 0,
            "clientOrderId": "d8574207d9e3b16a4a5511753eeef175",
            "symbol": "ETHBTC",
            "side": "sell",
            "status": "new",
            "type": "limit",
            "timeInForce": "GTC",
            "quantity": "0.063",
            "price": "0.046016",
            "cumQuantity": "0.000",
            "postOnly": false,
            "createdAt": "2017-05-15T17:01:05.092Z",
            "updatedAt": "2017-05-15T17:01:05.092Z"
        }
        """
        builder = args.DictBuilder().symbol(symbol).side(side).quantity(
            quantity).order_type(order_type).price(price).stop_price(
                stop_price)
        params = builder.time_in_force(time_in_force).expire_time(
            expire_time).strict_validate(strict_validate).post_only(
                post_only).build()

        if client_order_id is not None:
            return self._put(f'order/{client_order_id}', params)
        # else
        return self._post(endpoint='order', params=params)
Example #4
0
    def get_active_orders(self, symbol: str = None) -> List[Dict[str, Any]]:
        """Get the account active orders.

        Requires authentication.

        https://api.exchange.cryptomkt.com/#get-active-orders

        :param symbol: Optional. A symbol for filtering active orders.

        :returns: The account active orders.

        .. code-block:: python
        [
            {
                "id": 840450210,
                "clientOrderId": "c1837634ef81472a9cd13c81e7b91401",
                "symbol": "ETHBTC",
                "side": "buy",
                "status": "partiallyFilled",
                "type": "limit",
                "timeInForce": "GTC",
                "quantity": "0.020",
                "price": "0.046001",
                "cumQuantity": "0.005",
                "postOnly": false,
                "createdAt": "2017-05-12T17:17:57.437Z",
                "updatedAt": "2017-05-12T17:18:08.610Z"
            }
        ]
        """
        params = args.DictBuilder().symbol(symbol).build()
        return self._get(endpoint='order', params=params)
Example #5
0
    def subscribe_to_ticker(self,
                            symbol: str,
                            callback: callable,
                            result_callback: callable = None):
        """Subscribe to a ticker of a symbol.

        https://api.exchange.cryptomkt.com/#subscribe-to-ticker

        :param symbol: A symbol to subscribe.
        :param callback: A callable to call with each update of the result data. It takes one argument, the feed of tickers.
        :param result_callback: A callable to call with the subscription result. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: callback(err, result).

        :returns: Tickers of the symbol as feed for the callback.

        .. code-block:: python
        {
            "ask":"0.00017762",
            "bid":"0.00017755",
            "last":"0.00017738",
            "open":"0.0001677",
            "low":"0.00016512",
            "high":"0.00017932",
            "volume":"3164087.05",
            "volumeQuote":"540.9955071082",
            "timestamp":"2020-11-23T18:31:31.465Z",
            "symbol":"EOSBTC"
        }
        """
        params = args.DictBuilder().symbol(symbol).build()
        self.send_subscription(method='subscribeTicker',
                               callback=callback,
                               params=params,
                               result_callback=result_callback)
Example #6
0
    def get_orders_by_client_order_id(self,
                                      client_order_id: str) -> Dict[str, Any]:
        """Get order of the account with client_order_id.

        Requires authentication.

        https://api.exchange.cryptomkt.com/#orders-history

        :param client_order_id: the clientOrderId of the orders.

        :returns: An order list.

        .. code-block:: python
        [
            {
                "id": 828680667,
                "clientOrderId": "f4307c6e507e49019907c917b6d7a084",
                "symbol": "ETHBTC",
                "side": "sell",
                "status": "partiallyFilled",
                "type": "limit",
                "timeInForce": "GTC",
                "quantity": "13.942",
                "price": "0.011384",
                "avgPrice": "0.045000",
                "cumQuantity": "5.240",
                "createdAt": "2017-01-16T14:18:50.321Z",
                "updatedAt": "2017-01-19T15:23:56.876Z"
            }
        ]
        """
        params = args.DictBuilder().client_order_id(client_order_id).build()
        return self._get(endpoint='history/order', params=params)
Example #7
0
    def get_symbol(self, symbol: str, callback: callable):
        """Get a symbol by its id.

        A symbol is the combination of the base currency (first one) and quote currency (second one).

        https://api.exchange.cryptomkt.com/#get-symbols

        :param symbol: A symbol id.
        :param callback: A callable to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: callback(err, result).

        :returns: A symbol traded on the exchange as result argument for the callback.

        .. code-block:: python
        {
            "id":"EOSETH",
            "baseCurrency":"EOS",
            "quoteCurrency":"ETH",
            "quantityIncrement":"0.01",
            "tickSize":"0.0000001",
            "takeLiquidityRate":"0.002",
            "provideLiquidityRate":"0.001",
            "feeCurrency":"ETH"
        }
        """
        params = args.DictBuilder().symbol(symbol).build()
        self.send_by_id(method='getSymbol', callback=callback, params=params)
Example #8
0
    def get_currency(self, currency: str, callback: callable):
        """Get the data of a currency.

        https://api.exchange.cryptomkt.com/#get-currencies

        :param currency: A currency id.
        :param callback: A callable to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: callback(err, result).

        :returns: A currency as result argument for the callback.

        .. code-block:: python
        {
            'id': 'EOS', 
            'fullName': 'EOS', 
            'crypto': True, 
            'payinEnabled': True, 
            'payinPaymentId': True, 
            'payinConfirmations': 25, 
            'payoutEnabled': True, 
            'payoutIsPaymentId': True, 
            'transferEnabled': True, 
            'delisted': False, 
            'payoutFee': '0.0926'
        }
        """
        params = args.DictBuilder().currency(currency).build()
        self.send_by_id(method='getCurrency', callback=callback, params=params)
    def create_order(
        self,
        client_order_id: str, 
        symbol: str, 
        side: str, 
        quantity: float,
        order_type: str = None,
        price: float = None,
        stop_price: float = None,
        time_in_force: str = None,
        expire_time: str = None,
        strict_validate: bool = False,
        post_only: bool = False,
        callback: callable = None
    ):
        """Creates a new order

        Requires authentication.

        https://api.exchange.cryptomkt.com/#place-new-order

        :param client_order_id: If given must be unique within the trading day, including all active orders. If not given, is generated by the server.
        :param symbol: Trading symbol.
        :param side: 'buy' or 'sell'.
        :param quantity: Order quantity.
        :param order_type: Optional. 'limit', 'market', 'stopLimit' or 'stopMarket'. Default is 'limit'.
        :param price: Required for 'limit' and 'stopLimit'. limit price of the order.
        :param stop_price: Required for 'stopLimit' and 'stopMarket' orders. stop price of the order.
        :param time_in_force: Optional. 'GTC', 'IOC', 'FOK', 'Day', 'GTD'.
        :param expire_time: Required for orders with timeInForce = 'GDT'.
        :param strict_validate: Optional. If False, the server rounds half down for tickerSize and quantityIncrement. Example of ETHBTC: tickSize = '0.000001', then price '0.046016' is valid, '0.0460165' is invalid. 
        :param post_only: Optional. If True, your post_only order causes a match with a pre-existing order as a taker, then the order will be cancelled.
        :param callback: Optional. A callable to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: callback(err, result).

        :returns: The newly created order as result argument for the callback.

        .. code-block:: python
        {
            "id":"341065302776",
            "clientOrderId":"1000000000028",
            "symbol":"EOSETH",
            "side":"sell",
            "status":"new",
            "type":"limit",
            "timeInForce":"GTC",
            "quantity":"0.01",
            "price":"1000.0000000",
            "cumQuantity":"0.00",
            "createdAt":"2020-11-23T19:45:31.988Z",
            "updatedAt":"2020-11-23T19:45:31.988Z",
            "postOnly":False,
            "reportType":"new"
        }
        """
        builder = args.DictBuilder().client_order_id(client_order_id).symbol(symbol).side(side).quantity(quantity).order_type(order_type)
        builder.price(price).stop_price(stop_price).time_in_force(time_in_force).expire_time(expire_time)
        params = builder.strict_validate(strict_validate).post_only(post_only).build()
        self.send_by_id(method='newOrder', callback=callback, params=params)
Example #10
0
    def get_orders_history(self,
                           symbol: str = None,
                           since: str = None,
                           till: str = None,
                           limit: int = None,
                           offset: int = None) -> List[Dict[str, Any]]:
        """Get the account order history.

        Requires authentication.

        https://api.exchange.cryptomkt.com/#orders-history

        :param symbol: Optional. Filter orders by symbol.
        :param since: Optional. Initial value of the queried interval. 
        :param till: Optional. Last value of the queried interval.
        :param limit: Optional. Orders per query. Defaul is 100. Max is 1000.
        :param offset: Optional. Default is 0. Max is 100000. 

        :returns: Orders in the interval.

        .. code-block:: python
        [
            {
                "id": 828680665,
                "clientOrderId": "f4307c6e507e49019907c917b6d7a084",
                "symbol": "ETHBTC",
                "side": "sell",
                "status": "partiallyFilled",
                "type": "limit",
                "timeInForce": "GTC",
                "quantity": "13.942",
                "price": "0.011384",
                "avgPrice": "0.055487",
                "cumQuantity": "5.240",
                "createdAt": "2017-01-16T14:18:47.321Z",
                "updatedAt": "2017-01-19T15:23:54.876Z"
            },
            {
                "id": 828680667,
                "clientOrderId": "f4307c6e507e49019907c917b6d7a084",
                "symbol": "ETHBTC",
                "side": "sell",
                "status": "partiallyFilled",
                "type": "limit",
                "timeInForce": "GTC",
                "quantity": "13.942",
                "price": "0.011384",
                "avgPrice": "0.045000",
                "cumQuantity": "5.240",
                "createdAt": "2017-01-16T14:18:50.321Z",
                "updatedAt": "2017-01-19T15:23:56.876Z"
            }
        ]
        """
        params = args.DictBuilder().symbol(symbol).since(since).till(
            till).limit(limit).offset(offset).build()
        return self._get(endpoint='history/order', params=params)
Example #11
0
    def get_trades_history(self,
                           symbol: str = None,
                           sort: str = None,
                           by: str = None,
                           since: str = None,
                           till: str = None,
                           limit: int = None,
                           offset: int = None,
                           margin: str = None) -> List[Dict[str, Any]]:
        """Get the account's trading history.

        Requires authentication.

        https://api.exchange.cryptomkt.com/#trades-history

        :param symbol: Optional. Filter trades by symbol.
        :param sort: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'.
        :param by: Optional. Defines the sorting type.'timestamp' or 'id'. Default is 'timestamp'.
        :param since: Optional. Initial value of the queried interval. As id or as Datetime.
        :param till: Optional. Last value of the queried interval. As id or as Datetime.
        :param limit: Optional. Trades per query. Defaul is 100. Max is 1000.
        :param offset: Optional. Default is 0. Max is 100000. 
        :param margin: Optional. Filtering of margin orders. 'include', 'only' or 'ignore'. Default is 'include'

        :returns: Trades in the interval.

        .. code-block:: python
        [
            {
                "id": 9535486,
                "orderId": 816088377,
                "clientOrderId": "f8dbaab336d44d5ba3ff578098a68454",
                "symbol": "ETHBTC",
                "side": "sell",
                "quantity": "0.061",
                "price": "0.045487",
                "fee": "0.000002775",
                "timestamp": "2017-05-17T12:32:57.848Z"
            },
            {
                "id": 9535437,
                "orderId": 816088021,
                "clientOrderId": "27b9bfc068b44194b1f453c7af511ed6",
                "symbol": "ETHBTC",
                "side": "buy",
                "quantity": "0.038",
                "price": "0.046000",
                "fee": "-0.000000174",
                "timestamp": "2017-05-17T12:30:57.848Z"
            }
        ]
        """
        params = args.DictBuilder().symbol(symbol).sort(sort).by(by).since(
            since).till(till).limit(limit).offset(offset).margin(
                margin).build()
        return self._get(endpoint='history/trades', params=params)
Example #12
0
    def get_candles_of_symbol(
        self,
        symbol: str,
        period: str = None,
        sort: str = None,
        since: str = None,
        till: str = None,
        limit: int = None,
        offset: int = None
    ) -> Dict[str, List[Dict[str, List[Dict[str, Any]]]]]:
        """Get candles for a specified symbol.

        Candels are used for OHLC representation.

        https://api.exchange.cryptomkt.com/#candles

        :param symbol: The symbol id.
        :param period: Optional. A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month). Default is 'M30'.
        :param sort: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'.
        :param since: Optional. Initial value of the queried interval.
        :param till: Optional. Last value of the queried interval.
        :param limit: Optional. Candles per query. Defaul is 100. Max is 1000.
        :param offset: Optional. Default is 0. Max is 100000. 

        :returns: The candles for each queried symbol.

        .. code-block:: python
        [
            {
                "timestamp":"2017-05-05T15:00:00.000Z",
                "open":"10",
                "close":"10",
                "min":"10",
                "max":"10",
                "volume":"0.1",
                "volumeQuote":"1"
            },
            {
                "timestamp":"2017-05-05T16:00:00.000Z",
                "open":"80",
                "close":"50",
                "min":"50",
                "max":"80",
                "volume":"1.679",
                "volumeQuote":"113.95"
            }
        ]
        """
        params = args.DictBuilder().period(period).sort(sort).since(
            since).till(till).limit(limit).offset(offset).build()
        return self._public_get(endpoint=f"public/candles/{symbol}",
                                params=params)
Example #13
0
    def cancel_all_orders(self, symbol: str = None) -> List[Dict[str, Any]]:
        """Cancel all active orders, or all active orders for a specified symbol.

        Requires authentication.

        https://api.exchange.cryptomkt.com/#cancel-orders

        :param symbol: Optional. If given, cancels all orders of the symbol. If not given, cancels all orders of all symbols.

        :returns: A list with all the canceled orders.
        """
        params = args.DictBuilder().symbol(symbol).build()
        return self._delete(endpoint='order', params=params)
Example #14
0
    def unsubscribe_to_trades(self, symbol: str, callback: callable = None):
        """Unsubscribe to a trades of a symbol.

        https://api.exchange.cryptomkt.com/#subscribe-to-trades

        :param symbol: The symbol of the trades.
        :param callback: Optional. A callable to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: callback(err, result).

        :returns: The operation result as result argument for the callback. True if success.
        """
        params = args.DictBuilder().symbol(symbol).build()
        self.send_unsubscription(method='unsubscribeTrades',
                                 callback=callback,
                                 params=params)
    def replace_order(self,
    client_order_id: str,
    request_client_id: str,
    quantity: str,
    price: str,
    strict_validate: bool = None,
    callback: callable = None,):
        """Rewrites an order, canceling it or replacing it.

        The Cancel/Replace request is used to change the parameters of an existing order and to change the quantity or price attribute of an open order.
        
        Do not use this request to cancel the quantity remaining in an outstanding order. Use the cancel_order for this purpose.
        
        It is stipulated that a newly entered order cancels a prior order that has been entered, but not yet executed.

        Requires authentication.

        https://api.exchange.cryptomkt.com/#cancel-replace-order

        :param client_order_id: The client id of the order to modify.
        :param request_client_id: The new id for the modified order.
        :param quantity: The new quantity of the order.
        :param price: The new price of the order.
        :param strict_validate: Optional. If False, the server rounds half down for tickerSize and quantityIncrement. Example of ETHBTC: tickSize = '0.000001', then price '0.046016' is valid, '0.0460165' is invalid. 
        :param callback: Optional. A callable to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: callback(err, result).

        :returns: The modified order as result argument for the callback.

        .. code-block:: python
        {
            "id":"341065334406",
            "clientOrderId":"1000000000026",
            "symbol":"EOSETH",
            "side":"sell",
            "status":"new",
            "type":"limit",
            "timeInForce":"GTC",
            "quantity":"0.02",
            "price":"100.0000000",
            "cumQuantity":"0.00",
            "createdAt":"2020-11-23T19:45:31.988Z",
            "updatedAt":"2020-11-23T19:45:35.006Z",
            "postOnly":False,
            "reportType":"replaced",
            "originalRequestClientOrderId":"1000000000028"
        }
        """
        builder = args.DictBuilder().client_order_id(client_order_id).request_client_id(request_client_id).quantity(quantity)
        params = builder.price(price).strict_validate(strict_validate).build()
        self.send_by_id(method='cancelReplaceOrder', callback=callback, params=params)
Example #16
0
    def get_currencies(self,
                       currencies: List[str] = None) -> List[Dict[str, Any]]:
        """Get a list of all currencies or specified currencies.

        https://api.exchange.cryptomkt.com/#currencies

        :param currencies: Optional. A list of currencies ids.

        :returns: A list of available currencies.

        .. code-block:: python
        [
            {
                "id": "BTC",
                "fullName": "Bitcoin",
                "crypto": true,
                "payinEnabled": true,
                "payinPaymentId": false,
                "payinConfirmations": 2,
                "payoutEnabled": true,
                "payoutIsPaymentId": false,
                "transferEnabled": true,
                "delisted": false,
                "payoutFee": "0.00958",
                "payoutMinimalAmount": "0.00958",
                "precisionPayout": 10,
                "precisionTransfer": 10
            },
            {
                "id": "ETH",
                "fullName": "Ethereum",
                "crypto": true,
                "payinEnabled": true,
                "payinPaymentId": false,
                "payinConfirmations": 2,
                "payoutEnabled": true,
                "payoutIsPaymentId": false,
                "transferEnabled": true,
                "delisted": false,
                "payoutFee": "0.001",
                "payoutMinimalAmount": "0.00958",
                "precisionPayout": 20,
                "precisionTransfer": 15
            }
        ]
        """
        params = args.DictBuilder().currencies(currencies).build()
        return self._public_get(endpoint='public/currency', params=params)
Example #17
0
    def get_transactions_history(
            self,
            currency: str,
            sort: str = None,
            by: str = None,
            since: str = None,
            till: str = None,
            limit: int = None,
            offset: int = None,
            show_senders: bool = None) -> List[Dict[str, Any]]:
        """Get the transactions of the account by currency.

        Requires authentication.

        https://api.exchange.cryptomkt.com/#get-transactions-history

        :param currency: Currency code to get the transaction history.
        :param sort: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'.
        :param by: Optional. Defines the sorting type.'timestamp' or 'id'. Default is 'timestamp'.
        :param since: Optional. Initial value of the queried interval. As id or as Datetime.
        :param till: Optional. Last value of the queried interval. As id or as Datetime.
        :param limit: Optional. Transactions per query. Defaul is 100. Max is 1000.
        :param offset: Optional. Default is 0. Max is 100000. 
        :param show_senders: Optional. If True, show the sender address for payins.

        :returns: A list with the transactions in the interval.

        .. code-block:: python
        [
            {
                "id": "6a2fb54d-7466-490c-b3a6-95d8c882f7f7",
                "index": 20400458,
                "currency": "ETH",
                "amount": "38.616700000000000000000000",
                "fee": "0.000880000000000000000000",
                "address": "0xfaEF4bE10dDF50B68c220c9ab19381e20B8EEB2B",        
                "hash": "eece4c17994798939cea9f6a72ee12faa55a7ce44860cfb95c7ed71c89522fe8",
                "status": "pending",
                "type": "payout",
                "createdAt": "2017-05-18T18:05:36.957Z",
                "updatedAt": "2017-05-18T19:21:05.370Z"
            }
        ]
        """
        params = args.DictBuilder().currency(currency).sort(sort).by(by).since(
            since).till(till).limit(limit).offset(offset).show_senders(
                show_senders).build()
        return self._get(endpoint='account/transactions', params=params)
Example #18
0
    def subscribe_to_candles(self,
                             symbol: str,
                             period: str,
                             callback: callable,
                             limit: int = None,
                             result_callback: callable = None):
        """Subscribe to the candles of a symbol, at the given period.

        Candels are used for OHLC representation.

        https://api.exchange.cryptomkt.com/#subscribe-to-candles

        :param symbols: A list of symbol ids.
        :param period: A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month).
        :param callback: A callable to call with each update of the result data. It takes one argument. The candle feed.
        :param limit: Optional. Maximum number of candles in the feed
        :param result_callback: Optional. A callable to call with the subscription result. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: callback(err, result).
        
        :returns: The candle feed of the given symbol and period as feed for the callback.

        .. code-block:: python
        [
            {
                "timestamp":"2020-11-23T19:19:00.000Z",
                "open":"0.032383",
                "close":"0.032382",
                "min":"0.032376",
                "max":"0.032395",
                "volume":"25.5738",
                "volumeQuote":"0.8282975861"
            },
            {
                "timestamp":"2020-11-23T19:20:00.000Z",
                "open":"0.032387",
                "close":"0.032383",
                "min":"0.032374",
                "max":"0.032387",
                "volume":"8.5926",
                "volumeQuote":"0.2782366624"
            }
        ]
        """
        params = args.DictBuilder().symbol(symbol).period(period).limit(
            limit).build()
        self.send_subscription(method='subscribeCandles',
                               callback=callback,
                               params=params,
                               result_callback=result_callback)
Example #19
0
    def market_depth(self, symbol: str, volume: int) -> Dict[str, Any]:
        """Get An order book with market depth data of a symbol.

        An Order Book is an electronic list of buy and sell orders for a specific symbol, structured by price level.

        https://api.exchange.cryptomkt.com/#order-book

        :param symbol: A symbol id.
        :param volume: Optional. Desired volume for market depth search

        :returns: The order book for the symbol with market depth data.

        .. code-block:: python
        {
            "ask": [
                {
                "price": "9779.68",
                "size": "2.497"
                }
            ],
            "bid": [
                {
                "price": "9779.67",
                "size": "0.03719"
                },
                {
                "price": "9779.29",
                "size": "0.171"
                },
                {
                "price": "9779.27",
                "size": "0.171"
                },
                {
                "price": "9779.21",
                "size": "0.171"
                }
            ],
            "timestamp": "2020-02-11T11:30:38.597950917Z",
            "askAveragePrice": "9779.68",
            "bidAveragePrice": "9779.29"
        }
        """
        params = args.DictBuilder().volume(volume).build()
        return self._public_get(endpoint=f'public/orderbook/{symbol}',
                                params=params)
Example #20
0
    def get_trades_of_symbol(self,
                             symbol: str,
                             sort: str = None,
                             by: str = None,
                             since: str = None,
                             till: str = None,
                             limit: int = None,
                             offset: int = None) -> List[Dict[str, Any]]:
        """Get trades of a symbol.

        'since' param and 'till' param must have the same format, both index or both timestamp.

        https://api.exchange.cryptomkt.com/#trades

        :param symbols: Optional. A list of symbol ids.
        :param sort: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'.
        :param since: Optional. Initial value of the queried interval. As id or as Datetime.
        :param till: Optional. Last value of the queried interval. As id or as Datetime.
        :param limit: Optional. Trades per query. Defaul is 100. Max is 1000.
        :param offset: Optional. Default is 0. Max is 100000. 

        :returns: A list of trades of the queried symbol.

        .. code-block:: python
        [
            {
                "id": 9533117,
                "price": "0.046001",
                "quantity": "0.220",
                "side": "sell",
                "timestamp": "2017-04-14T12:18:40.426Z"
            },
            {
                "id": 9533116,
                "price": "0.046002",
                "quantity": "0.022",
                "side": "buy",
                "timestamp": "2017-04-14T11:56:37.027Z"
            }
        ]
        """
        params = args.DictBuilder().sort(sort).by(by).since(since).till(
            till).limit(limit).offset(offset).build()
        return self._public_get(endpoint=f"public/trades/{symbol}",
                                params=params)
Example #21
0
    def unsubscribe_to_order_book(self,
                                  symbol: str,
                                  callback: callable = None):
        """Unsubscribe to an order book of a symbol.

        An Order Book is an electronic list of buy and sell orders for a specific symbol, structured by price level.

        https://api.exchange.cryptomkt.com/#subscribe-to-order-book

        :param symbol: The symbol of the orderbook.
        :param callback: Optional. A callable to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: callback(err, result).

        :returns: The operation result as result argument for the callback. True if success.
        """
        params = args.DictBuilder().symbol(symbol).build()
        self.send_unsubscription(method='unsubscribeOrderbook',
                                 callback=callback,
                                 params=params)
Example #22
0
    def unsubscribe_to_candles(self,
                               symbol: str,
                               period: str,
                               callback: callable = None):
        """Unsubscribe to the candles of a symbol at a given period.

        https://api.exchange.cryptomkt.com/#subscribe-to-candles

        :param symbol: The symbol of the candles.
        :param period: 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month).
        :param callback: Optional. A callable to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: callback(err, result).

        :returns: The operation result as result argument for the callback. True if success
        """
        params = args.DictBuilder().symbol(symbol).period(period).build()
        self.send_unsubscription(method='unsubscribeCandles',
                                 callback=callback,
                                 params=params)
Example #23
0
    def get_estimate_withdraw_fee(self, currency: str, amount: str) -> str:
        """Get an estimate of the withdrawal fee.

        Requires authetication.

        https://api.exchange.cryptomkt.com/#estimate-withdraw-fee

        :param currency: Currency code for withdraw.
        :param amount: Expected withdraw amount.
        
        :returns: The expected fee

        .. code-block:: python
        "0.0008"
        """
        params = args.DictBuilder().amount(amount).currency(currency).build()
        return self._get(endpoint='account/crypto/estimate-withdraw',
                         params=params)['fee']
Example #24
0
    def get_trades(self,
                   symbol: str,
                   callback: callable,
                   sort: str = None,
                   by: str = None,
                   since: str = None,
                   till: str = None,
                   limit: int = None,
                   offset: int = None):
        """Get trades of the specified symbol.

        https://api.exchange.cryptomkt.com/#get-trades

        :param symbol: The symbol to get the trades.
        :param callback: A callable to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: callback(err, result).
        :param sort: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'.
        :param since: Optional. Initial value of the queried interval. As id or as Datetime.
        :param till: Optional. Last value of the queried interval. As id or as Datetime.
        :param limit: Optional. Trades per query. Defaul is 100. Max is 1000.
        :param offset: Optional. Default is 0. Max is 100000. 

        :returns: Trades information of the symbol as result argument for the callback.

        .. code-block:: python
        [
            {
                "id":1011897072,
                "price":"0.032338",
                "quantity":"0.0054",
                "side":"sell",
                "timestamp":"2020-11-23T19:13:35.386Z"
            },
            {
                "id":1011897068,
                "price":"0.032340",
                "quantity":"1.0600",
                "side":"buy",
                "timestamp":"2020-11-23T19:13:34.773Z"
            }
        ]
        """
        params = args.DictBuilder().symbol(symbol).sort(sort).by(by).since(
            since).till(till).limit(limit).offset(offset).build()
        self.send_by_id(method='getTrades', callback=callback, params=params)
Example #25
0
    def transfer_money_from_bank_balance_to_trading_balance(
            self, currency: str, amount: str) -> str:
        """Transfer money from bank account to trading account.
        
        Requires authentication.

        https://api.exchange.cryptomkt.com/#transfer-money-between-trading-account-and-bank-account

        :param currency: Currency code for transfering.
        :param amount: Amount to be transfered between balances.
        
        :returns: The transaction identifier of the transfer.

        .. code-block:: python
        "d2ce578f-647d-4fa0-b1aa-4a27e5ee597b"
        """
        params = args.DictBuilder().currency(currency).amount(
            amount).transfer_type(args.TRANSFER_TYPE.BANK_TO_EXCHANGE).build()
        return self._post(endpoint='account/transfer', params=params)['id']
Example #26
0
    def load_transactions(self,
                          callback: callable,
                          currency: str = None,
                          sort: str = None,
                          since: str = None,
                          till: str = None,
                          limit: int = None,
                          offset: int = None,
                          show_senders: bool = None):
        """Get a list of transactions of the account. Accepts only filtering by Index.

        https://api.exchange.cryptomkt.com/#load-transactions

        :param callback: A callable to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: callback(err, result).
        :param currency: Currency code to get the transaction history.
        :param sort: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'ASC'.
        :param since: Optional. Initial value of the queried interval. As id.
        :param till: Optional. Last value of the queried interval. As id.
        :param limit: Optional. Transactions per query. Defaul is 100. Max is 1000.
        :param offset: Optional. Default is 0. Max is 100000. 
        :param show_senders: Optional. If True, show the sender address for payins.

        :returns: A list with the transactions in the interval.

        .. code-block:: python
        [
            {
            "id": "76b70d1c-3dd7-423e-976e-902e516aae0e",
            "index": 7173627250,
            "type": "bankToExchange",
            "status": "success",
            "currency": "BTG",
            "amount": "0.00001000",
            "createdAt": "2021-01-31T08:19:33.892Z",
            "updatedAt": "2021-01-31T08:19:33.967Z"
            }
        ]
        """
        params = args.DictBuilder().currency(currency).sort(sort).since(
            since).till(till).limit(limit).offset(offset).show_senders(
                show_senders).build()
        self.send_by_id("loadTransactions", callback, params)
Example #27
0
    def find_transactions(self,
                          callback: callable,
                          currency: str = None,
                          sort: str = None,
                          since: str = None,
                          till: str = None,
                          limit: int = None,
                          offset: int = None,
                          show_senders: bool = None):
        """Get a list of transactions of the account. Accepts only filtering by Datetime
        
        https://api.exchange.cryptomkt.com/#find-transactions

        :param callback: A callable to call with the result data. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: callback(err, result).
        :param currency: Currency code to get the transaction history.
        :param sort: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'.
        :param since: Optional. Initial value of the queried interval. As Datetime.
        :param till: Optional. Last value of the queried interval. As Datetime.
        :param limit: Optional. Transactions per query. Defaul is 100. Max is 1000.
        :param offset: Optional. Default is 0. Max is 100000. 
        :param show_senders: Optional. If True, show the sender address for payins.

        :returns: A list with the transactions in the interval.

        .. code-block:: python
        [
            {
                "id": "d91b8caa-ebaa-4254-b50c-8ac717016734",
                "index": 7173628127,
                "type": "exchangeToBank",
                "status": "success",
                "currency": "BTG",
                "amount": "0.00001000",
                "createdAt": "2021-01-31T08:19:48.140Z",
                "updatedAt": "2021-01-31T08:19:48.211Z"
            }
        ]
        """
        params = args.DictBuilder().currency(currency).sort(sort).since(
            since).till(till).limit(limit).offset(offset).show_senders(
                show_senders).build()
        self.send_by_id("findTransactions", callback, params)
Example #28
0
    def get_order_book(self, symbol: str, limit: int = None) -> Dict[str, Any]:
        """Get An order book of a symbols.

        An Order Book is an electronic list of buy and sell orders for a specific symbol, structured by price level.

        https://api.exchange.cryptomkt.com/#order-book

        :param symbol: A symbol id.
        :param limit: Optional. Limit of order book levels. Set to 0 to view full list of order book levels.
        
        :returns: The order book for the symbol.

        .. code-block:: python
        {
            "symbol":"ETHBTC",
            "timestamp":"2020-11-17T22:08:19.426Z",
            "batchingTime":"2020-11-17T22:08:19.440Z",
            "ask":[
                {
                    "price":"0.027288",
                    "size":"0.9000"
                },
                {
                    "price":"0.027292",
                    "size":"0.3265"
                }
            ],
            "bid":[
                {
                    "price":"0.027281",
                    "size":"4.9000"
                },
                {
                    "price":"0.027280",
                    "size":"11.1017"
                }
            ]
        }
        """
        params = args.DictBuilder().limit(limit).build()
        return self._public_get(endpoint=f'public/orderbook/{symbol}',
                                params=params)
Example #29
0
    def subscribe_to_order_book(self,
                                symbol: str,
                                callback: callable,
                                result_callback: callable = None):
        """Subscribe to the order book of a symbol.

        An Order Book is an electronic list of buy and sell orders for a specific symbol, structured by price level.

        https://api.exchange.cryptomkt.com/#subscribe-to-order-book

        :param symbol: The symbol of the orderbook.
        :param callback: A callable to call with each update of the result data. It takes one argument, the feed of order book.
        :param result_callback: Optional. A callable to call with the subscription result. It takes two arguments, err and result. err is None for successful calls, result is None for calls with error: callback(err, result)

        :returns: Order books of the symbol as feed for the callback.
        """
        params = args.DictBuilder().symbol(symbol).build()
        self.send_subscription(method='subscribeOrderbook',
                               callback=callback,
                               params=params,
                               result_callback=result_callback)
Example #30
0
    def transfer_convert_between_currencies(self, from_currency: str,
                                            to_currency: str,
                                            amount: str) -> List[str]:
        """Converts between currencies.

        Requires authentication.

        https://api.exchange.cryptomkt.com/#transfer-convert-between-currencies

        :param from_currency: currency code of origin.
        :param to_currency: currency code of destiny.
        :param amount: the amount to be sent. 

        :returns: A list of transaction identifiers.

        .. code-block:: python
        ["d2ce578f-647d-4fa0-b1aa-4a27e5ee597b", "d2ce57hf-6g7d-4ka0-b8aa-4a27e5ee5i7b"]
        """
        params = args.DictBuilder().from_currency(from_currency).to_currency(
            to_currency).amount(amount).build()
        return self._post(endpoint='account/crypto/transfer-convert',
                          params=params)['result']