def get_client():
""" Creates a client connection to be used with orders
"""
# Get client ID from our non-order pool list in memory
timeout = g.timeout
while g.clientId_in_use:
log.debug('Waiting for clientId to become available...({})'.format(timeout))
time.sleep(0.5)
timeout -= 1
client = g.client_connection
# Enable logging if we're in debug mode
if current_app.debug is True:
client.enableLogging()
# Reconnect if needed
if not client.isConnected():
log.debug('Client {} not connected. Trying to reconnect...'.format(g.client_id))
client.disconnect()
time.sleep(1)
client.connect()
# If we failed to reconnect, be sure to put our client ID back in the pool
if client.isConnected() is False:
raise Exception('Client cannot connect')
return client
评论列表
文章目录