def ping(self, channel="auth"): """Ping bitfinex. Parameters ---------- channel : str What channel id that should be pinged. Default "auth". To get channel id’s use ´client._conns.keys()´. """ client_cid = utils.create_cid() data = {'event': 'ping', 'cid': client_cid} payload = json.dumps(data, ensure_ascii=False).encode('utf8') self.factories[channel].protocol_instance.sendMessage(payload, isBinary=False) return client_cid
def new_order_op(self, order_type, symbol, amount, price, price_trailing=None, price_aux_limit=None, price_oco_stop=None, hidden=0, flags=None, tif=None, set_cid=True): """Create new order operation Parameters ---------- order_type : str Order type. Must be one of: "LIMIT", "STOP", "MARKET", "TRAILING STOP", "FOK", "STOP LIMIT" or equivelent with "EXCHANGE" prepended to it. All orders starting with EXCHANGE are made on the exchange wallet. Orders without it is made on the margin wallet and will start or change a position. symbol : str The currency symbol to be traded. e.g. BTCUSD amount : decimal str The amount to be traided. price : decimal str The price to buy at. Will be ignored for market orders. price_trailing : decimal string The trailing price price_aux_limit : decimal string Auxiliary Limit price (for STOP LIMIT) price_oco_stop : decimal string OCO stop price 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. tif : datetime string set_cid : bool wheter or not to set a cid. Returns ------- dict A dict containing the order detials. Used in new_order and for creating multiorders. Example ------- Note if you only want to create a new order, use the ´´new_order´´ method bellow. However if you want to submitt multiple order and cancel orders at the same time use this method to create order operations and send them with the ``multi_order`` method:: # You should only need to create and authenticate a client once. # Then simply reuse it later my_client = WssClient(key, secret) my_client.authenticate() my_client.start() order_operation = my_client.new_order_op( order_type="LIMIT", symbol="BTCUSD", amount=0.004, price=1000.0 ) # Usefull to keep track of an order by its client id, for later # operations (like cancel order). clinet_id = order_operation["cid"] my_client.multi_order( operations=[order_operation] ) """ flags = flags or [] order_op = { 'type': order_type, 'symbol': utils.order_symbol(symbol), 'amount': amount, 'price': price, 'hidden': hidden, "flags": sum(flags), } if price_trailing: order_op['price_trailing'] = price_trailing if price_aux_limit: order_op['price_aux_limit'] = price_aux_limit if price_oco_stop: order_op['price_oco_stop'] = price_oco_stop if tif: order_op['tif'] = tif if set_cid: client_order_id = utils.create_cid() order_op['cid'] = client_order_id return order_op