예제 #1
0
    def transfer_quote(self, amount=None, btc_amount=None, currency=None):
        """Get a quote for a transfer for various Bitso Outlets.

        Args:
          btc_amount (str):
            Mutually exclusive with amount. Either this, or amount should
            be present in the request. The total amount in Bitcoins, as
            provided by the user. NOTE: The amount is in BTC format
            (900mbtc = .9 BTC).
          amount (str):
            Mutually exclusive with btc_amount. Either this, or btc_amount
            should be present in the request. The total amount in Fiat currency.
            Use this if you prefer specifying amounts in fiat instead of BTC.
          currency (str):
            An ISO 4217 fiat currency symbol (ie, "MXN"). If btc_amount is
            provided instead of amount, this is the currency to which the BTC
            price will be converted into. Otherwise, if amount is specified
            instead of btc_amount, this is the currency of the specified amount.
        
        Returns:
          A bitso.TransactionQuote instance.         
        """

        if currency is None:
            raise ApiClientError(
                {u'message': u"Currency symbol not specified"})
        if amount is None and btc_amount is None:
            raise ApiClientError({
                u'message':
                u"Neither 'amount' nor 'btc_amount' are specified"
            })
        if amount is not None and btc_amount is not None:
            raise ApiClientError({
                u'message':
                u"'amount' and 'btc_amount' are mutually exclusive. Pick one"
            })

        url = '%s/transfer_quote' % self.base_url
        parameters = {}
        if amount:
            parameters['amount'] = str(amount).encode('utf-8')
        elif btc_amount:
            parameters['btc_amount'] = str(btc_amount).encode('utf-8')

        parameters['currency'] = currency
        parameters['full'] = True
        resp = self._request_url(url, 'POST', params=parameters, private=True)
        return TransactionQuote._NewFromJsonDict(resp['payload'])
예제 #2
0
    def place_order(self, **kwargs):
        """Places a buy limit order.

        Args:
          book (str):
            Specifies which book to use. 
          side (str):
            the order side (buy or sell) 
          order_type (str):
            Order type (limit or market)
          major (str):
            The amount of major currency for this order. An order could be specified in terms of major or minor, never both.
          minor (str):
            The amount of minor currency for this order. An order could be specified in terms of major or minor, never both.
          price (str):
            Price per unit of major. For use only with limit orders.


        Returns:
          A bitso.Order instance.        
        """

        if kwargs.get('book') is None:
            raise ApiClientError({u'message': u'book not specified.'})
        if kwargs.get('side') is None:
            raise ApiClientError({u'message': u'side not specified.'})
        if kwargs.get('order_type') is None:
            raise ApiClientError({u'message': u'order type not specified.'})

        url = '%s/orders/' % self.base_url
        parameters = {}
        parameters['book'] = kwargs.get('book')
        parameters['type'] = kwargs.get('order_type')
        parameters['side'] = kwargs.get('side')
        if 'major' in kwargs:
            parameters['major'] = str(kwargs['major']).encode('utf-8')
        if 'minor' in kwargs:
            parameters['minor'] = str(kwargs['minor']).encode('utf-8')
        if 'price' in kwargs:
            parameters['price'] = str(kwargs['price']).encode('utf-8')

        resp = self._request_url(url, 'POST', params=parameters, private=True)
        return resp['payload']
예제 #3
0
    def transfer_status(self, transfer_id):
        """Request status for a transfer order 

        Args:
          transfer_id (str):
            Bitso Transfer Order ID (As returned by transfer_create
            method.

        """
        if transfer_id is None:
            raise ApiClientError({u'message': u"'transfer_id' not specified"})
        url = '%s/transfer/%s' % (self.base_url, transfer_id)
        parameters = {}
        resp = self._request_url(url, 'GET', params=parameters, private=True)
        return TransactionOrder._NewFromJsonDict(resp['payload'])
예제 #4
0
    def user_trades(self,
                    tids=[],
                    book=None,
                    marker=None,
                    limit=25,
                    sort='desc'):
        """Get a list of the user's transactions

        Args:
           book (str):
            Specifies which order book to get user trades from. 
          marker (str, optional):
            Returns objects that are older or newer (depending on 'sort') than the object which
            has the marker value as ID
          limit (int, optional):
            Limit the number of results to parameter value, max=100, default=25
          sort (str, optional):
            Sorting by datetime: 'asc', 'desc'
            Defuault is 'desc'
         
        Returns:
          A list bitso.UserTrade instances.        
        """

        url = '%s/user_trades/' % self.base_url
        if isinstance(tids, int):
            tids = str(tids)
        if isinstance(tids, basestring):
            tids = [tids]
        tids = map(str, tids)
        if tids:
            url += '%s/' % ('-'.join(tids))
        parameters = {}
        if book:
            parameters['book'] = book
        if marker:
            parameters['marker'] = marker
        if limit:
            parameters['limit'] = limit
        if sort:
            if not isinstance(sort, basestring) or sort.lower() not in [
                    'asc', 'desc'
            ]:
                raise ApiClientError(
                    {u'message': u"sort is not 'asc' or 'desc' "})
            parameters['sort'] = sort
        resp = self._request_url(url, 'GET', params=parameters, private=True)
        return [UserTrade._NewFromJsonDict(x) for x in resp['payload']]
예제 #5
0
    def transfer_create(self,
                        amount=None,
                        btc_amount=None,
                        currency=None,
                        rate = None,
                        payment_outlet=None,
                        **kwargs):
        """Request a currency transfer using quoted Bitso transer outlet

        Args:
          btc_amount (str):
            Mutually exclusive with amount. Either this, or amount should
            be present in the request. The total amount in Bitcoins, as
            provided by the user. NOTE: The amount is in BTC format
            (900mbtc = .9 BTC).
          amount (str):
            Mutually exclusive with btc_amount. Either this, or btc_amount
            should be present in the request. The total amount in Fiat currency.
            Use this if you prefer specifying amounts in fiat instead of BTC.
          currency (str):
            An ISO 4217 fiat currency symbol (ie, "MXN"). If btc_amount is
            provided instead of amount, this is the currency to which the BTC
            price will be converted into. Otherwise, if amount is specified
            instead of btc_amount, this is the currency of the specified amount.
          rate (str):
            This is the rate (e.g. BTC/MXN), as acquired from the
            transfer_quote method. You must request a quote in this way before
            creating a transfer.
          payment_outlet (str):
            The outlet_id as provided by quote method. 
          required fields parameters: (str):
            Each of the other 'required_fields', as stipulated in the TransferQuote
            for the chosen payment_outlet.

        
        Returns:
          A bitso.TransactionQuote instance.         
        """
        
        
        if currency is None:
            raise ApiClientError({u'message': u"'currency' not specified"})
        if amount is None and btc_amount is None:
            raise ApiClientError({u'message': u"Neither 'amount' nor 'btc_amount' are specified"})
        if amount is not None and btc_amount is not None:
            raise ApiClientError({u'message': u"'amount' and 'btc_amount' are mutually exclusive. Pick one"})
        if rate is None:
            raise ApiClientError({u'message': u"'rate' not specified"})
        if payment_outlet is None:
            raise ApiClientError({u'message': u"'payment_outlet' not specified"})


        url = '%s/transfer_create' % self.base_url
        parameters = {}
        if amount:
            parameters['amount'] = str(amount).encode('utf-8')
        elif btc_amount:
            parameters['btc_amount'] = str(btc_amount).encode('utf-8')

        parameters['currency'] = currency
        parameters['rate'] = str(rate).encode('utf-8')
        parameters['payment_outlet'] = payment_outlet
        for k, v in kwargs.items():
            parameters[k] = str(v).encode('utf-8')
        resp = self._request_url(url, 'POST', params=parameters, private=True)
        return TransactionOrder._NewFromJsonDict(resp['payload'])