Selling multiple assets with multiple websokets from loop
Hi guys and @sammchardy , hope you are all well.
I'm trying to sell the assets which details are in a list like the one hereafter:
listone = [['APPCBTC',1913650, '0.00020616', '1.00000000'],['VENBTC', 5949889, '0.00048093', '1.00000000'],['VIBEBTC', 1506246, '0.00010918', '5.0'],['GTOBTC', 1506246, '0.00010918', '8.0']]
I then pass trough a for-loop all the itmes in the list and create their own process message for the websocket like below:
`for x in listone:
def process_message_x(msg):
print(msg['p'], msg['s'])
if float(msg['p']) >= float(x[2]):
q = int(float(x[3]))
order = client.create_test_order(symbol=msg['s'], side=Client.SIDE_SELL, type=Client.ORDER_TYPE_MARKET,quantity=q)
print(x[3], 'SOLD UP', x[0])
bm.stop_socket(conn_key)
else:
q = int(float(x[3]))
order = client.create_test_order(symbol=msg['s'], side=Client.SIDE_SELL, type=Client.ORDER_TYPE_MARKET, quantity=q)
print(x[3], 'SOLD Down', x[0])
bm.stop_socket(conn_key)
conn_key = bm.start_trade_socket(x[0], process_message_x)
bm.start() `
Now the problem is that the websockets starts, however they use as the information just the last one also they do not stop once done, this is the print out I get:
0.00071265 VENBTC 8.0 SOLD UP GTOBTC 0.00071295 VENBTC 8.0 SOLD UP GTOBTC 0.00071295 VENBTC 8.0 SOLD UP GTOBTC 0.00012045 APPCBTC 8.0 SOLD UP GTOBTC 0.00012047 APPCBTC 8.0 SOLD UP GTOBTC 0.00008392 VIBEBTC 8.0 SOLD Down GTOBTC
I have tried with multiplex socket, however that creates issues when the order is complete it blow up the code, even if I remove it right after from the trade list in the conn key, and from my list. Also if you have multiple assets from the same symbol bought at different prices, it will just consider one. Do you guys have any suggestion to execute something like this, basically giving a list of asset to sell and do it without encountering errors and closing the socket when finished? Thanks chaps. Cheers
Hi guys, I found a work around it! Cheers
Can you share what you did to fix your problem so everyone can learn from the errors please. Im new to websockets myself and am just starting to play around with the multiplex usage so any fixed problems might lessen my own troubles down the road. Thanks
@SkylerX how did you solve it? :)
hi i would love to hear whats the way around it , im stuck at the same problem thanks