ohenrik / bitfinex

A Python client for the Bitfinex API
MIT License
58 stars 32 forks source link

Stop limit orders via websocket v2 not supported #16

Closed gaorufeng closed 6 years ago

gaorufeng commented 6 years ago

new_order("LIMIT", "tEOSUSD", "5", "4") is OK!, I don't know how to support stop limit for new_order().

update:

I edit client.py

copy new_order_op to new_order_op_stop_limit


def new_order_op_stop_limit(self, order_type, pair, amount, price, stop_limit_price,hidden=0, flags=None):

 #add  'price_aux_limit':stop_limit_price

    flags = flags or []
    client_order_id = wss_utils.UtcNow()
    return {
        'cid': client_order_id,
        'type': order_type,
        'symbol': wss_utils.order_pair(pair),
        'amount': amount,
        'price': price,
        'price_aux_limit':stop_limit_price,  
        'hidden': hidden,
        "flags": sum(flags)
    }

copy new_order to new_order_stop_limit()

def new_order_stop_limit(self, order_type, pair, amount, price, stop_limit_price, hidden=0, flags=list()):

    operation = self.new_order_op_stop_limit(order_type, pair, amount, price, stop_limit_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"]   

if price $5.0

exch_order = self.mywss.new_order_stop_limit("STOP LIMIT", "tEOSUSD", "4", "6","6.2")

exch_order = self.mywss.new_order_stop_limit("STOP LIMIT", "tEOSUSD", "-6", "4","3.9")

That's OK. Sorry, my English is not good

ohenrik commented 6 years ago

This is a good point, at the moment we are making it impossible to place complex orders over the websocket api.

ohenrik commented 6 years ago

I have now added support for advanced order types.

We still need to get documentation up and running, but for now look at the updated new_order method: https://github.com/ohenrik/bitfinex/blob/master/bitfinex/websockets/client.py#L292