Пример #1
0
    def cancel_order_cid(self, order_cid, order_date):
        """Cancel order using the client id and the date of the cid. Both are
        returned from the new_order command from this library.

        Parameters
        ----------
        order_cid : str
            cid string. e.g. "1234154"

        order_date : str
            Iso formated order date. e.g. "2012-01-23"
        """
        data = [
            0,
            wss_utils.get_notification_code('order cancel'),
            None,
            {
                # docs: http://bit.ly/2BVqwW6
                'cid': order_cid,
                'cid_date': order_date
            }
        ]
        payload = json.dumps(data, ensure_ascii=False).encode('utf8')
        self.factories["auth"].protocol_instance.sendMessage(payload,
                                                             isBinary=False)
Пример #2
0
 def new_order(self, order_type, pair, amount, price, hidden=0, flags=list()):
     operation = self.new_order_op(order_type, pair, amount, price, 0, flags)
     data = [
         0,
         wss_utils.get_notification_code('order new'),
         None,
         operation
     ]
     payload = json.dumps(data, ensure_ascii = False).encode('utf8')
     self.factories["auth"].protocol_instance.sendMessage(payload, isBinary=False)
     return operation["cid"]
Пример #3
0
 def cancel_order(self, order_id):
     data = [
         0,
         wss_utils.get_notification_code('order cancel'),
         None,
         {
             # docs: http://bit.ly/2BVqwW6
             'id': order_id
         }
     ]
     payload = json.dumps(data, ensure_ascii = False).encode('utf8')
     self.factories["auth"].protocol_instance.sendMessage(payload, isBinary=False)
Пример #4
0
    def new_order(self,
                  order_type,
                  pair,
                  amount,
                  price,
                  hidden=0,
                  flags=list()):
        """
        Create new order.

        Parameters
        ----------
        order_type : str
            Order type. Must be one of: "LIMIT", "STOP", "MARKET",
            "TRAILING STOP", "FOK", "STOP LIMIT" or equivelent with "MARKET"
            prepended to it.

        pair : str
            The currency pair to be traded. e.g. BTCUSD

        amount :  float
            The amount to be traided.

        price : float
            The price to buy at. Will be ignored for market orders.

        hidden : bool
            Whether or not to use the hidden order type.

        flags : list
            A list of integers for the different flags. Will be added together
            into a unique integer.

        Returns
        -------
        int
            Order client id (cid). The CID is also a mts date stamp of when the
            order was created.
        """
        operation = self.new_order_op(order_type, pair, amount, price, 0,
                                      flags)
        data = [
            0,
            wss_utils.get_notification_code('order new'), None, operation
        ]
        payload = json.dumps(data, ensure_ascii=False).encode('utf8')
        self.factories["auth"].protocol_instance.sendMessage(payload,
                                                             isBinary=False)
        return operation["cid"]
Пример #5
0
    def multi_order(self, operations):
        """Multi order operation.

        Parameters
        ----------
        operations : list
            a list of operations. Read more here:
            https://bitfinex.readme.io/v2/reference#ws-input-order-multi-op
            Hint. you can use the self.new_order_op() for easy order
            operation creation.
        """
        data = [
            0,
            wss_utils.get_notification_code('order multi-op'), None, operations
        ]
        payload = json.dumps(data, ensure_ascii=False).encode('utf8')
        self.factories["auth"].protocol_instance.sendMessage(payload,
                                                             isBinary=False)
        return [order[1].get("cid", None) for order in operations]
Пример #6
0
    def cancel_order(self, order_id):
        """Cancel order

        Parameters
        ----------
        order_id : int, str
            Order id created by Bitfinex
        """
        data = [
            0,
            wss_utils.get_notification_code('order cancel'),
            None,
            {
                # docs: http://bit.ly/2BVqwW6
                'id': order_id
            }
        ]
        payload = json.dumps(data, ensure_ascii=False).encode('utf8')
        self.factories["auth"].protocol_instance.sendMessage(payload,
                                                             isBinary=False)
Пример #7
0
    def update_order(self, **order_settings):
        """Update order using the order id

        Parameters
        ----------
        id : int64
            Order ID
            
        gid : int32
            Group Order ID

        price : decimal string
            Price

        amount : decimal string
            Amount

        delta : decimal string
            Change of amount

        price_aux_limit : decimal string
            Auxiliary limit price

        price_trailing : decimal string
            Trailing price delta

        tif : datetime string
            Time-In-Force: datetime for automatic order cancellation (ie. 2020-01-01 10:45:23)
        """
        data = [
            0,
            wss_utils.get_notification_code('order update'), None,
            order_settings
        ]
        payload = json.dumps(data, ensure_ascii=False).encode('utf8')
        self.factories["auth"].protocol_instance.sendMessage(payload,
                                                             isBinary=False)