mirror of
https://github.com/Death916/emailtrade.git
synced 2026-04-10 03:04:40 -07:00
include trade.py in getsignal and add functions to trade
This commit is contained in:
parent
2b4cda19d0
commit
fb37e718b3
2 changed files with 65 additions and 41 deletions
35
getsignal.py
35
getsignal.py
|
|
@ -6,6 +6,7 @@ import glogin
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import psutil
|
import psutil
|
||||||
|
import trade
|
||||||
|
|
||||||
# login to server
|
# login to server
|
||||||
|
|
||||||
|
|
@ -22,7 +23,7 @@ def gconnect():
|
||||||
msg = imap.fetch([uid], [b'BODY[]', b'FLAGS'])
|
msg = imap.fetch([uid], [b'BODY[]', b'FLAGS'])
|
||||||
global message
|
global message
|
||||||
message = pyzmail.PyzMessage.factory(msg[uid][b'BODY[]'])
|
message = pyzmail.PyzMessage.factory(msg[uid][b'BODY[]'])
|
||||||
|
print('connected')
|
||||||
|
|
||||||
last_alert = 0
|
last_alert = 0
|
||||||
|
|
||||||
|
|
@ -38,42 +39,45 @@ def kill(proc_pid):
|
||||||
def start_buy():
|
def start_buy():
|
||||||
|
|
||||||
print('trade is a buy')
|
print('trade is a buy')
|
||||||
proc = subprocess.Popen(['taskmgr'], stdout=subprocess.PIPE, shell=True)
|
trade.open_trade(1)
|
||||||
global last_alert
|
global last_alert
|
||||||
last_alert = "buy"
|
last_alert = "buy"
|
||||||
time.sleep(5)
|
|
||||||
kill(proc.pid)
|
|
||||||
|
|
||||||
|
|
||||||
def start_sell():
|
def start_sell():
|
||||||
|
|
||||||
print('trade is a sell')
|
print('trade is a sell')
|
||||||
proc = subprocess.Popen(['taskmgr'], stdout=subprocess.PIPE, shell=True)
|
trade.close_trade(1)
|
||||||
global last_alert
|
global last_alert
|
||||||
last_alert = "sell"
|
last_alert = "sell"
|
||||||
time.sleep(5)
|
|
||||||
kill(proc.pid)
|
|
||||||
|
|
||||||
|
|
||||||
def get_signal():
|
def get_signal():
|
||||||
try:
|
try:
|
||||||
if 'strategy says sell now' in message.get_subject() or last_alert == 'buy':
|
if 'strategy says sell now' in message.get_subject() or last_alert == 'buy':
|
||||||
print('sell signal found')
|
print('sell signal found')
|
||||||
# print(message.get_subject())
|
coin = message.get_subject()
|
||||||
print('got sell signal')
|
print(coin)
|
||||||
return "sell"
|
return "sell"
|
||||||
|
|
||||||
elif 'strategy says buy now' in message.get_subject():
|
elif last_alert == 'sell' or last_alert == 0:
|
||||||
print('buy signal found')
|
print('buy signal found')
|
||||||
# print(message.get_subject())
|
coin = message.get_subject()
|
||||||
|
"""if 'ETHBTC' in coin: # TODO check for current ticker to use
|
||||||
|
print('true')
|
||||||
|
else:
|
||||||
|
print('false') """
|
||||||
|
print(coin)
|
||||||
|
|
||||||
return "buy"
|
return "buy"
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print('failed')
|
print('failed')
|
||||||
|
|
||||||
|
|
||||||
last_uid = 0
|
last_uid = 0
|
||||||
|
|
||||||
|
def main():
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
global uid
|
global uid
|
||||||
|
|
@ -83,7 +87,7 @@ while True:
|
||||||
print(time.ctime())
|
print(time.ctime())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
global last_uid
|
||||||
if last_uid != uid:
|
if last_uid != uid:
|
||||||
|
|
||||||
if signal == "buy" and last_alert != 'buy':
|
if signal == "buy" and last_alert != 'buy':
|
||||||
|
|
@ -98,6 +102,11 @@ while True:
|
||||||
print('same uid')
|
print('same uid')
|
||||||
except:
|
except:
|
||||||
print(' fail')
|
print(' fail')
|
||||||
|
print(trade.open_orders())
|
||||||
|
|
||||||
time.sleep(600)
|
time.sleep(600)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
27
trade.py
27
trade.py
|
|
@ -1,27 +1,42 @@
|
||||||
#! python3
|
#! python3
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from bittrex.bittrex import Bittrex, API_V2_0
|
from bittrex.bittrex import Bittrex
|
||||||
|
|
||||||
|
|
||||||
amount = 0
|
amount = 0
|
||||||
price = 0
|
price = 0
|
||||||
|
|
||||||
with open('D:/code/emailtrade/keys.json') as k:
|
with open('D:/code/emailtrade/keys.json') as k:
|
||||||
keys = json.load(k)
|
keys = json.load(k)
|
||||||
|
|
||||||
api_key = keys['api_key']
|
api_key = keys['api_key']
|
||||||
priv_key = keys['priv_key']
|
priv_key = keys['priv_key']
|
||||||
|
ticker = 'BTC-ETH'
|
||||||
|
trex = Bittrex(api_key, priv_key)
|
||||||
|
|
||||||
|
|
||||||
trex = Bittrex(api_key, priv_key, api_version=API_V2_0)
|
|
||||||
def marketcheck(ticker):
|
def marketcheck(ticker):
|
||||||
markets = trex.get_ticker(ticker)
|
markets = trex.get_ticker(ticker)
|
||||||
price = markets['result']['Ask']
|
price = markets['result']['Ask']
|
||||||
print(markets['result'])
|
print(markets['result'])
|
||||||
print(price)
|
|
||||||
return price
|
return price
|
||||||
|
|
||||||
marketcheck('BTC-LTC')
|
|
||||||
|
def open_trade(amount):
|
||||||
|
marketcheck(ticker)
|
||||||
|
trex.buy_limit(ticker, amount, rate=None)
|
||||||
|
print('buying', amount, 'of', ticker)
|
||||||
|
|
||||||
|
def close_trade(amount):
|
||||||
|
marketcheck(ticker)
|
||||||
|
trex.sell_limit(ticker, amount, rate =None)
|
||||||
|
print('selling', amount, 'of', ticker)
|
||||||
|
|
||||||
|
def open_orders():
|
||||||
|
trex.get_open_orders()
|
||||||
|
|
||||||
|
|
||||||
#def open_buy():
|
|
||||||
# trex.buy_limit(ticker, amount, price)
|
#open_buy('1')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue