Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def stop_reactor(exit_code=0):
'''
Stop the reactor and exit with exit_code.
If exit_code is None, don't exit, just return to the caller.
exit_code must be between 1 and 255.
'''
if exit_code is not None:
logging.warning("Exiting with code {}".format(exit_code))
else:
# Let's hope the calling code exits pretty soon after this
logging.warning("Stopping reactor")
try:
reactor.stop()
except ReactorNotRunning:
pass
# return to the caller and let it decide what to do
if exit_code == None:
return
# a graceful exit
if exit_code == 0:
sys.exit()
# a hard exit
assert exit_code >= 0
assert exit_code <= 127
os._exit(exit_code)
def stop(*args, **kwargs):
reactor.stop()
def gotChar(ch, resp=resp):
if not ch: return
if ch=='\x03': # C-c
reactor.stop()
if ch=='\r':
frame.write('\r\n')
stresp = ''.join(resp)
del resp
frame.callback = None
d.callback(stresp)
return
elif 32 <= ord(ch) < 127:
resp.append(ch)
if echo:
frame.write(ch)
elif ord(ch) == 8 and resp: # BS
if echo: frame.write('\x08 \x08')
resp.pop()
frame.callback = gotChar
def _failure(res):
reactor.stop()
print res
return -1
d.addCallbacks(_success, _failure)
def stop_thread():
time.sleep(2)
reactor.stop()
def force_disconnect(self, reason):
self.update_connection_status('Disconnected')
self.error_handler(self.id, 'API Disconnect: %s' % reason)
reactor.stop()
print a.set(key="APA", value="banan")
print a.get(key="APA")
print b.get(key="APA")
a.stop()
b.stop()
except:
traceback.print_exc()
ret = 1
finally:
if reactor.running:
threads.blockingCallFromThread(reactor, reactor.stop)
return ret
def run(srv):
host = config['host']
port = int(config['port'])
tls_mode = config['tls']
try:
p = yield protocol.connect(host, port, tls_mode, config['username'],
config['password'])
yield srv.startup(p)
yield srv.onShutdown()
log.msg('Disconnected cleanly.')
except Exception as e:
log.msg('There was an error: {}'.format(e))
if stop_reactor:
try:
reactor.stop()
except Exception:
pass
def onDisconnect(self):
self.log.info("connection closed")
try:
reactor.stop()
except ReactorNotRunning:
pass
cur_price = float(msg['p'])
percent_from_max = utils.percent_change(max_price, cur_price)
percent_from_bought = utils.percent_change(price_bought, cur_price)
# COMMENT THIS LINE OUT IF YOU DON'T WANT TOO MUCH DATA
print_trade_data(price_bought, cur_price, max_price, percent_from_max, percent_from_bought)
if reached_goal == False and percent_from_bought >= sell_order_desired_percentage_profit:
reached_goal = True
utils.print_and_write_to_logfile("REACHED PRICE GOAL")
if percent_from_max < sell_percent_down_to_sell and reached_goal == True:
utils.print_and_write_to_logfile("PERCENT DOWN FROM PEAK: " + str(percent_from_max) + ". TIME TO SELL")
try:
reactor.stop()
except:
print("REACTOR ALREADY STOPPED")
max_price = max(cur_price, max_price)