mirror of
https://github.com/Death916/emailtrade.git
synced 2026-04-10 03:04:40 -07:00
integrate kraken
This commit is contained in:
parent
319acd457f
commit
df270c2365
5 changed files with 108 additions and 63 deletions
19
README.md
19
README.md
|
|
@ -1,3 +1,22 @@
|
|||
# emailtrade
|
||||
Automatically buy/sell crypto from tradingview alert email
|
||||
Create keys.json file in project root and add bittrex or kraken keys
|
||||
and email and password for gmail
|
||||
|
||||
If you like this software:
|
||||
Get me a beer
|
||||
ETH:
|
||||
0x8De9E8409F427602533c9493a5bAFa5E4F7A8266
|
||||
|
||||
BTC:
|
||||
bc1qhxqk8g72rs8yrvselfauztxr2emdc7sje3dkta
|
||||
|
||||
DOGE:
|
||||
DLdv7fgdz3ADhsMmszGsXGQSmRP2pWJzPE
|
||||
|
||||
LBC:
|
||||
lbc1qgmtmg498m353zyj6n9cwq0ueeakyx8pj2h6sr0
|
||||
|
||||
|
||||
Say thanks
|
||||
twitter.com/sacoftrees916
|
||||
|
|
@ -1,10 +1,22 @@
|
|||
import glogin
|
||||
import trade
|
||||
import trex
|
||||
import history as hist
|
||||
|
||||
import kraken
|
||||
import time
|
||||
|
||||
|
||||
MARKET = input("Pease enter what market you want to use: Kraken or bittrex").lower()
|
||||
if MARKET == "kraken":
|
||||
trade = kraken
|
||||
elif MARKET == "bittrex":
|
||||
trade = trex
|
||||
|
||||
# TODO make above cleaner in get_signal
|
||||
|
||||
|
||||
|
||||
# TODO add try/except for market to make sure its correct
|
||||
|
||||
# login to server
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,60 +4,76 @@ import history as hist
|
|||
import os
|
||||
import krakenex
|
||||
from pykrakenapi import KrakenAPI
|
||||
import pandas as pd
|
||||
|
||||
price = 0
|
||||
|
||||
with open(os.getcwd() + "/keys.json") as k:
|
||||
keys = json.load(k)
|
||||
|
||||
API_KEY = keys["public"]
|
||||
PRIV_KEY = keys["priv"]
|
||||
TICKER = "ETHUSD"
|
||||
API = krakenex.API(API_KEY, PRIV_KEY)
|
||||
# BUY_COIN = input("what coin to buy")
|
||||
# SELL_COIN = input("what to buy it with")
|
||||
TICKER= "ETHUSD"
|
||||
API = krakenex.api(API_KEY, PRIV_KEY)
|
||||
#BUY_CURRENCY = input().capitalize()
|
||||
|
||||
kraken = KrakenAPI(API)
|
||||
buyprice = ""
|
||||
sellprice = ""
|
||||
|
||||
|
||||
def marketcheck():
|
||||
markets = kraken.get_ohlc_data(TICKER)
|
||||
def marketcheck(TICKER):
|
||||
markets = kraken.get_ohlc_data(TICKER)
|
||||
price = markets[0]['close'][0]
|
||||
print(TICKER, "price is ", price)
|
||||
return price
|
||||
|
||||
|
||||
# done
|
||||
buyprice = marketcheck()
|
||||
|
||||
#done
|
||||
|
||||
def open_trade():
|
||||
|
||||
buyprice = marketcheck(TICKER)
|
||||
balancedf = kraken.get_account_balance()
|
||||
balance = balancedf.vol["ZUSD"]
|
||||
buy_amount = (balance / buyprice) - (balance / buyprice) * 0.0025
|
||||
# kraken.add_standard_order(TICKER, "buy", "market", balance)
|
||||
print("buying", buy_amount, "of", TICKER, " for ", balance)
|
||||
# kraken.add_standard_order(TICKER,)
|
||||
print("buying", buy_amount, "of", TICKER)
|
||||
hist.tradehist(
|
||||
"bought " + str(buy_amount) + " of " + TICKER + " at " + str(buyprice)
|
||||
"bought " + str(buy_amount) + " of " + TICKER+ " at " + str(buyprice)
|
||||
)
|
||||
return buy_amount
|
||||
return
|
||||
|
||||
|
||||
def close_trade():
|
||||
|
||||
sell_price = marketcheck()
|
||||
balancedf = kraken.get_account_balance()
|
||||
sell_amount = balancedf.vol['XETH']
|
||||
# print(kraken.add_standard_order(TICKER, "sell", "market", sell_amount))
|
||||
sellprice = marketcheck(TICKER)
|
||||
if TICKER == 'ETHUSD':
|
||||
symbol = 'XETH'
|
||||
if TICKER == 'XBTUSD':
|
||||
symbol ='XXBT'
|
||||
|
||||
|
||||
balance = kraken.get_account_balance()
|
||||
|
||||
sell_amount = balance.vol[symbol]
|
||||
# print(trex.sell_limit(TICKER, sell_amount, rate=sellprice))
|
||||
print("selling", sell_amount, "of", TICKER)
|
||||
hist.tradehist(
|
||||
"sold " + str(sell_amount) + " of " + TICKER + " at " + str(sell_price)
|
||||
"sold " + str(sell_amount) + " of " + TICKER+ " at " + str(sellprice)
|
||||
)
|
||||
hist.tradehist(
|
||||
"profit = "
|
||||
+ "{:.25f}".format((sell_price * sell_amount) - (buyprice * sell_amount))
|
||||
+ "{:.25f}".format((sellprice * sell_amount) - (buyprice * sell_amount))
|
||||
)
|
||||
|
||||
|
||||
def open_orders():
|
||||
kraken.get_open_orders(True)
|
||||
return
|
||||
|
||||
def open_positions():
|
||||
kraken.get_open_positions()
|
||||
return kraken.get_open_positions()
|
||||
|
||||
# TODO uncomment buy/sells
|
||||
|
|
@ -2,7 +2,7 @@ import json
|
|||
from bittrex import Bittrex
|
||||
import history as hist
|
||||
import os
|
||||
import kraken
|
||||
|
||||
|
||||
price = 0
|
||||
|
||||
|
|
@ -10,55 +10,53 @@ with open(os.getcwd() + "/keys.json") as k:
|
|||
keys = json.load(k)
|
||||
|
||||
|
||||
MARKET = input("Pease enter what market you want to use: Kraken or bittrex").lower()
|
||||
# TODO add try/except for market to make sure its correct
|
||||
|
||||
class bittrex_trade():
|
||||
|
||||
api_key = keys["api_key"]
|
||||
priv_key = keys["priv_key"]
|
||||
ticker = "BTC-ETH"
|
||||
trex = Bittrex(api_key, priv_key)
|
||||
|
||||
|
||||
def marketcheck(self, ticker):
|
||||
markets = trex.get_ticker(ticker)
|
||||
price = markets["result"]["Ask"]
|
||||
print(ticker, "price is ", price)
|
||||
return price
|
||||
|
||||
api_key = keys["api_key"]
|
||||
priv_key = keys["priv_key"]
|
||||
ticker = "BTC-ETH"
|
||||
trex = Bittrex(api_key, priv_key)
|
||||
|
||||
|
||||
buyprice = marketcheck(ticker)
|
||||
def marketcheck(ticker):
|
||||
markets = trex.get_ticker(ticker)
|
||||
price = markets["result"]["Ask"]
|
||||
print(ticker, "price is ", price)
|
||||
return price
|
||||
|
||||
|
||||
def open_trade(self):
|
||||
|
||||
balance = trex.get_balance("BTC")["result"]["Available"]
|
||||
buy_amount = (balance / buyprice) - (balance / buyprice) * 0.0025
|
||||
print(trex.buy_limit(ticker, buy_amount, rate=buyprice))
|
||||
print("buying", buy_amount, "of", ticker)
|
||||
hist.tradehist(
|
||||
"bought " + str(buy_amount) + " of " + ticker + " at " + str(buyprice)
|
||||
)
|
||||
return
|
||||
buyprice = marketcheck(ticker)
|
||||
|
||||
|
||||
def close_trade():
|
||||
def open_trade():
|
||||
|
||||
sell_price = marketcheck(ticker)
|
||||
|
||||
sell_amount = trex.get_balance("ETH")["result"]["Available"]
|
||||
print(trex.sell_limit(ticker, sell_amount, rate=sell_price))
|
||||
print("selling", sell_amount, "of", ticker)
|
||||
hist.tradehist(
|
||||
"sold " + str(sell_amount) + " of " + ticker + " at " + str(sell_price)
|
||||
)
|
||||
hist.tradehist(
|
||||
"profit = "
|
||||
+ "{:.25f}".format((sell_price * sell_amount) - (buyprice * sell_amount))
|
||||
)
|
||||
balance = trex.get_balance("BTC")["result"]["Available"]
|
||||
buy_amount = (balance / buyprice) - (balance / buyprice) * 0.0025
|
||||
print(trex.buy_limit(ticker, buy_amount, rate=buyprice))
|
||||
print("buying", buy_amount, "of", ticker)
|
||||
hist.tradehist(
|
||||
"bought " + str(buy_amount) + " of " + ticker + " at " + str(buyprice)
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
def open_orders():
|
||||
trex.get_open_orders()
|
||||
return
|
||||
def close_trade():
|
||||
|
||||
sell_price = marketcheck(ticker)
|
||||
|
||||
sell_amount = trex.get_balance("ETH")["result"]["Available"]
|
||||
print(trex.sell_limit(ticker, sell_amount, rate=sell_price))
|
||||
print("selling", sell_amount, "of", ticker)
|
||||
hist.tradehist(
|
||||
"sold " + str(sell_amount) + " of " + ticker + " at " + str(sell_price)
|
||||
)
|
||||
hist.tradehist(
|
||||
"profit = "
|
||||
+ "{:.25f}".format((sell_price * sell_amount) - (buyprice * sell_amount))
|
||||
)
|
||||
|
||||
|
||||
def open_orders():
|
||||
trex.get_open_orders()
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue