Hey guys! I could use alittle help here. I have a program script I wrote for auto-trading software and it is supposed to switch between profitable coins! I feel like everything is coded correctly now, but the program does not end when the coin changes. Any help would be appreciated!!! :)
import json
import requests
import re
import unicodedata
import subprocess
import os
import sqlite3
import time
from decimal import *
import threading
variable = []
flag = []
stop = []
class same(object):
def __init__(self):
while 1:
global variable
global stop
variable=str(variable)
print(variable)
print(flag)
print ('Current Profitable Coin Is The Same!')
subprocess.call('./zenbot.sh trade --order_adjust_time=30000 --debug poloniex.'+variable,shell=True)
if stop == True:
print(" Exiting loop.")
break
class diff(object):
def __init__(self):
while 1:
global flag
global variable
global stop
variable=str(variable)
print(variable)
subprocess.call('./zenbot.sh sell --order_adjust_time=30000 --debug poloniex.'+flag,shell=True)
flag=variable
if stop == True:
print(" Exiting loop.")
break
class firstFunction(object):
def __init__(self):
while 1:
##Main App Loop
##DB Refresh
global variable
os.remove('/example.db')
conn = sqlite3.connect('/example.db')
c = conn.cursor()
c.execute('''CREATE TABLE gains (ke4,pct1,dips,dips1)''')
wjdata = requests.get('http://ift.tt/2tUqWZ4').json()
##Load Initial Data
for key in wjdata:
if re.match(r'BTC_+', key):
ke1=key.replace('_', '-')
ke2=ke1.replace('BTC-', '')
ke3='-BTC'
ke9=ke2+ke3
pct=(wjdata[key]['last'])
pct0=Decimal(pct)
pct1=format(pct0, 'f')
dips='undefined'
dips1='undefined'
c.execute("INSERT INTO gains VALUES (?, ?, ?, ?);", (ke9, pct1, dips, dips1))
conn.commit()
time.sleep(60)
wjdata = requests.get('http://ift.tt/2tUqWZ4').json()
##Load the second Data
for key in wjdata:
if re.match(r'BTC_+', key):
ke1=key.replace('_', '-')
ke2=ke1.replace('BTC-', '')
ke3='-BTC'
ke4=ke2+ke3
pct2=(wjdata[key]['last'])
pct3=Decimal(pct2)
dips=format(pct3, 'f')
c.execute('UPDATE gains SET dips = ? WHERE ke4 = ?;', (dips, ke4))
conn.commit()
for row in c.execute('SELECT ke4, (dips-pct1) as diff FROM gains ORDER BY diff DESC LIMIT 1;'):
row=str(tuple(row))
ro1=row.replace("u", '')
ro2=ro1.replace("'", '')
ro3=ro2.replace('(', '')
ro4=ro3.replace(')', '')
ro5=ro4.replace(",", '')
s = ro5
s=re.sub('\d', '', s)
variable=s.replace(".", '')
print(variable)
def main():
stop = False
threading.Thread(target=firstFunction).start()
if flag == variable:
threading.Thread(target=same).start()
else:
stop = True
threading.Thread(target=diff).start()
main()
Aucun commentaire:
Enregistrer un commentaire