mirror of
https://github.com/Death916/emailtrade.git
synced 2026-04-10 03:04:40 -07:00
kraken functions
This commit is contained in:
parent
ef134546f3
commit
21200f0dfb
1 changed files with 25 additions and 17 deletions
|
|
@ -2,49 +2,57 @@ import json
|
||||||
|
|
||||||
import history as hist
|
import history as hist
|
||||||
import os
|
import os
|
||||||
|
import krakenex
|
||||||
|
from pykrakenapi import KrakenAPI
|
||||||
|
|
||||||
|
|
||||||
price = 0
|
price = 0
|
||||||
|
|
||||||
with open(os.getcwd() + "/keys.json") as k:
|
with open(os.getcwd() + "/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"
|
TICKER= "ETHUSD"
|
||||||
kraken = Bittrex(api_key, priv_key)
|
API = krakenex.api()
|
||||||
|
|
||||||
|
|
||||||
|
kraken = KrakenAPI(API)
|
||||||
buyprice = ""
|
buyprice = ""
|
||||||
sellprice = ""
|
sellprice = ""
|
||||||
|
|
||||||
|
|
||||||
def marketcheck(ticker):
|
def marketcheck(TICKER):
|
||||||
markets = trex.get_ticker(ticker)
|
markets = kraken.get_ohlc_data(TICKER)
|
||||||
price = markets["result"]["Ask"]
|
price = markets[0]['close'][0]
|
||||||
print(ticker, "price is ", price)
|
print(TICKER, "price is ", price)
|
||||||
return price
|
return price
|
||||||
|
|
||||||
|
|
||||||
|
#done
|
||||||
|
|
||||||
def open_trade():
|
def open_trade():
|
||||||
|
|
||||||
buyprice = marketcheck(ticker)
|
buyprice = marketcheck(TICKER)
|
||||||
balance = trex.get_balance("BTC")["result"]["Available"]
|
balance = trex.get_balance("USD")["result"]["Available"]
|
||||||
buy_amount = (balance / buyprice) - (balance / buyprice) * 0.0025
|
buy_amount = (balance / buyprice) - (balance / buyprice) * 0.0025
|
||||||
print(trex.buy_limit(ticker, buy_amount, rate=buyprice))
|
print(trex.buy_limit(TICKER, buy_amount, rate=buyprice))
|
||||||
print("buying", buy_amount, "of", ticker)
|
print("buying", buy_amount, "of", TICKER)
|
||||||
hist.tradehist(
|
hist.tradehist(
|
||||||
"bought " + str(buy_amount) + " of " + ticker + " at " + str(buyprice)
|
"bought " + str(buy_amount) + " of " + TICKER+ " at " + str(buyprice)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def close_trade():
|
def close_trade():
|
||||||
|
|
||||||
sellprice = marketcheck(ticker)
|
sellprice = marketcheck(TICKER)
|
||||||
|
|
||||||
sell_amount = trex.get_balance("ETH")["result"]["Available"]
|
sell_amount = trex.get_balance("ETH")["result"]["Available"]
|
||||||
print(trex.sell_limit(ticker, sell_amount, rate=sellprice))
|
print(trex.sell_limit(TICKER, sell_amount, rate=sellprice))
|
||||||
print("selling", sell_amount, "of", ticker)
|
print("selling", sell_amount, "of", TICKER)
|
||||||
hist.tradehist(
|
hist.tradehist(
|
||||||
"sold " + str(sell_amount) + " of " + ticker + " at " + str(sellprice)
|
"sold " + str(sell_amount) + " of " + TICKER+ " at " + str(sellprice)
|
||||||
)
|
)
|
||||||
hist.tradehist(
|
hist.tradehist(
|
||||||
"profit = "
|
"profit = "
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue