Created
July 19, 2018 15:00
-
-
Save izotx/9a1b0ccbd181cc62b9a9f1d70530b2e3 to your computer and use it in GitHub Desktop.
Kucoin trading bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Import "kucoin.client" could not be resolvedPylance[reportMissingImports]
@bestafor @C-L-U-T-C-H
You have to install kucoin
library via pip install python-kucoin
. You can use pip3 install python-kucoin
if you are on Mac or Linux.
@ericbaranowski Thank You
It’s actually
pip install python-kucoin
OR pip3 install python-kucoin
The code also has to be modified to include the api passphrase
#API KEYS to the exchange
api_key = "xxxxxx"
api_secret = "xxxx"
api_passphrase = "xxxxxx"
#instantiate client
apiclient = Client(api_key, api_secret, api_passphrase)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi, pip doesnt install kucoin.client? i am new at python, could you help about this module?