Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #importing libraries
- from kucoin.client import Client
- import json
- import math
- import time
- import datetime
- #API KEYS to the exchange
- api_key = "xxxxxx"
- api_secret = "xxxx"
- #instantiate client
- apiclient = Client(api_key, api_secret)
- #set buyin and selling price
- pricebuy = 0.00000029
- pricesell = 0.00000030
- #tickers to trade
- ticker1 = 'CV'
- ticker2 = 'BTC'
- #Each exchange can have different fees
- fee_perc = 0.1
- #Saving logs
- def saveLog(logmessage):
- with open('/Users/jc_admin/Documents/GitHub/Bittrex/log', 'a') as file:
- file.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M") + " ")
- file.write(logmessage +"\n")
- file.close()
- return
- #main function
- def mainf():
- saveLog("Running\n")
- balance_json1 = apiclient.get_coin_balance(ticker1)
- balance_json2 = apiclient.get_coin_balance(ticker2)
- coin_available1 = truncate(balance_json1["balance"],2)
- coin_available2 = balance_json2["balance"]
- print(coin_available1)
- print(coin_available2)
- #checks if we have minimum amount of coins to sell (100 is arbitrary, change it to your number)
- if coin_available1 > 100:
- #selling
- message = "Setting sell order for: " + str(ticker1)
- print(message)
- saveLog(message)
- #executing sell order
- apiclient.create_sell_order("CV-BTC", pricesell, coin_available1)
- #Checks if we have enough to buy
- if coin_available2 > 0:
- #buing
- message = "Setting buy order for: " + str(ticker1)
- print(message)
- saveLog(message)
- buy = calcBuy(coin_available2,pricebuy)
- if buy > 100:
- #executing buy order
- apiclient.create_buy_order("CV-BTC",pricebuy, buy)
- return
- #calcuates how
- def calcBuy(available,price):
- gross = available/price
- fee = fee_perc/100.0
- net = gross * (1 - fee)
- print(net)
- rounded = math.floor(net)
- print(rounded)
- return rounded
- #for continuos execution
- def update():
- while True:
- mainf()
- time.sleep(30 * 60)
- #APIs might have different number formats/precision
- def truncate(f, n):
- return math.floor(f * 10 ** n) / 10 ** n
- mainf() #one time execution
- #update() #uncomment to have continuos execution
Add Comment
Please, Sign In to add comment