示例#1
0
    def setUpClass(cls):
        API_KEY = "XXXXXX"
        API_SECRET = "XXXXXX"

        cls.bitkub = Bitkub()
        cls.bitkub.set_api_key(API_KEY)
        cls.bitkub.set_api_secret(API_SECRET)
示例#2
0
def getBalance(idName):
    API_KEY = configJson[idName]['bk_apiKey']
    API_SECRET = configJson[idName]['bk_apiSecret']
    if API_KEY == '' or API_SECRET == '':
        print('this user have no API KEY or API SECRET to send order')
        return None
    bitkub = Bitkub()
    bitkub.set_api_key(API_KEY)
    bitkub.set_api_secret(API_SECRET)
    balance = bitkub.balances()
    data = {}
    if balance['error'] == 0:
        for sym in balance['result']:
            if balance['result'][sym]['available'] > 0:
                available = balance['result'][sym]['available']
                available_h = max([
                    available, configJson[idName]['available'],
                    configJson[idName]['availableHigh']
                ])
                p_drawdown = (abs(available_h - available) / available_h) * 100
                p_drawdown = round(p_drawdown, 2)
                data[sym] = {
                    'available': available,
                    'reserved': balance['result'][sym]['reserved']
                }
                #update balance data sheet
                if sym == 'THB':
                    gSheet.setValue('Config',
                                    findKey='idName',
                                    findValue=idName,
                                    key='available',
                                    value=available)
                    gSheet.setValue('Config',
                                    findKey='idName',
                                    findValue=idName,
                                    key='availableHigh',
                                    value=available_h)
                    gSheet.setValue('Config',
                                    findKey='idName',
                                    findValue=idName,
                                    key='percentageDrawdown',
                                    value=p_drawdown)
    return data
示例#3
0
def getBalance(idName):
    API_KEY = configJson[idName]['bk_apiKey']
    API_SECRET = configJson[idName]['bk_apiSecret']
    if API_KEY == '' or API_SECRET == '':
        print('this user have no API KEY or API SECRET to send order')
        return None
    bitkub = Bitkub()
    bitkub.set_api_key(API_KEY)
    bitkub.set_api_secret(API_SECRET)
    balance = bitkub.balances()
    data = {}
    if balance['error'] == 0:
        for sym in balance['result']:
            if balance['result'][sym]['available'] > 0:
                data[sym] = {
                    'available': balance['result'][sym]['available'],
                    'reserved': balance['result'][sym]['reserved']
                }
    return data
示例#4
0
def CreateSellOrder(idName, symbol):
    if not symbol.__contains__('THB_'):
        print('symbol name need contains THB_')
        return None
    API_KEY = configJson[idName]['bk_apiKey']
    API_SECRET = configJson[idName]['bk_apiSecret']
    if API_KEY == '' or API_SECRET == '':
        print('this user have no API KEY or API SECRET to send order')
        return None
    bitkub = Bitkub()
    bitkub.set_api_key(API_KEY)
    bitkub.set_api_secret(API_SECRET)
    balance = getBalance(idName)
    sym = symbol.replace('THB_', '')
    if not sym in list(balance):
        print('not found [{}] in balance'.format(sym))
        return None
    amount = balance[sym]['available']
    result = bitkub.place_ask(sym=symbol, amt=amount, typ='market')
    print(result)
示例#5
0
def CreateBuyOrder(idName, symbol, portfoiloList):
    if not symbol.__contains__('THB_'):
        print('symbol name need contains THB_')
        return None
    API_KEY = configJson[idName]['bk_apiKey']
    API_SECRET = configJson[idName]['bk_apiSecret']
    if API_KEY == '' or API_SECRET == '':
        print('this user have no API KEY or API SECRET to send order')
        return None
    bitkub = Bitkub()
    bitkub.set_api_key(API_KEY)
    bitkub.set_api_secret(API_SECRET)
    balance = getBalance(idName)
    percentageBalanceUsing = configJson[idName]['percentageBalanceUsing']
    system = configJson[idName]['system']
    size = int(systemJson[system]['size'])
    portSize = len(list(balance)) - 1

    portSymList = []
    for symbol in portfoiloList:  # Chane Symbol to Sym
        q = symbol.replace('THB_', '')
        portSymList.append(q)
    if portSize >= size:  #checking except symbol
        for sym in list(balance):
            if (not sym in portSymList) and (sym != 'THB'):
                CreateSellOrder(idName, 'THB_' + sym)
                time.sleep(5)
                balance = getBalance(idName)
                portSize = len(list(balance)) - 1

    print('size {}'.format(size))
    print('portSize {}'.format(portSize))
    budget = balance['THB']['available']
    sizedBudget = (budget / (size - portSize)) * (percentageBalanceUsing / 100)
    print(sizedBudget)
    result = bitkub.place_bid(sym=symbol, amt=sizedBudget, typ='market')
    print(result)
示例#6
0
def CreateBuyOrder(idName, symbol, portfoiloList, countLeft):
    if countLeft <= 0:
        print('count left = 0')
        return None
    if not symbol.__contains__('THB_'):
        print('symbol name need contains THB_')
        return None
    API_KEY = configJson[idName]['bk_apiKey']
    API_SECRET = configJson[idName]['bk_apiSecret']
    if API_KEY == '' or API_SECRET == '':
        print('this user have no API KEY or API SECRET to send order')
        return None
    bitkub = Bitkub()
    bitkub.set_api_key(API_KEY)
    bitkub.set_api_secret(API_SECRET)
    balance = getBalance(idName)
    percentageBalanceUsing = configJson[idName]['percentageBalanceUsing']
    system = configJson[idName]['system']
    size = int(configJson[idName]['portSize'])
    portSize = len(list(balance)) - 1  #Real Port
    buySize = int(configJson[idName]['buySize'])

    portSymList = []
    for symbol in portfoiloList:  # Chane Symbol to Sym
        q = symbol.replace('THB_', '')
        portSymList.append(q)

    #print('size {}'.format(size))
    #print('portSize {}'.format(portSize))
    print('countLeft {}'.format(countLeft))
    budget = balance['THB']['available']
    #sizedBudget = ( (budget / (size-portSize)) /countLeft) * (percentageBalanceUsing/100)
    sizedBudget = (budget / countLeft) * (percentageBalanceUsing / 100)
    print('sizedBudget {}'.format(sizedBudget))
    result = bitkub.place_bid(sym=symbol, amt=sizedBudget, typ='market')
    print(result)
示例#7
0
def Reset(*_):
    print('---------------------\nReset\n---------------------')
    global mornitorFilePath
    global transacFilePath
    if not os.path.exists(mornitorFilePath):
        return None
    m_df = pd.read_csv(mornitorFilePath)
    t_df = pd.read_csv(transacFilePath)
    deleteList = []

    m_user_list = m_df['User'].unique().tolist()
    t_user_list = t_df['User'].unique().tolist()
    for user in m_user_list:
        print('Checking User {} in Mornitor'.format(user))
        if not user in list(configJson):
            deleteList.append(user)
    for user in t_user_list:
        print('Checking User {} in Transaction'.format(user))
        if not user in list(configJson):
            deleteList.append(user)

    #Sending Restart
    for user in list(configJson):
        if bool(configJson[user]['reset']):
            text = '[ Reset Portfoilo ]\n' +\
                   'User ID : {} \n'.format(user) +\
                   'Preset ID : {} \n'.format(configJson[user]['preset']) +\
                   'System ID : {} \n'.format(configJson[user]['system']) +\
                   'Portfolio Size : {} \n'.format(configJson[user]['portSize']) +\
                   'Position Size : {} \n'.format(configJson[user]['buySize']) +\
                   'Target Profit : {}%'.format(configJson[user]['percentageProfitTarget'])
            lineNotify.sendNotifyMassage(configJson[user]['lineToken'], text)
            gSheet.setValue('Config',
                            findKey='idName',
                            findValue=user,
                            key='reset',
                            value=0)
            gSheet.setValue('Config',
                            findKey='idName',
                            findValue=user,
                            key='lastReport',
                            value=time.time())
            print(text)

            #Clear all real portfolio
            API_KEY = configJson[user]['bk_apiKey']
            API_SECRET = configJson[user]['bk_apiSecret']
            bitkub = Bitkub()
            bitkub.set_api_key(API_KEY)
            bitkub.set_api_secret(API_SECRET)
            balance = getBalance(user)
            #print(balance)
            for sym in balance:
                if sym == 'THB':
                    continue
                symbol = 'THB_{}'.format(sym)
                print(symbol)
                print('Sell {} {}'.format(balance[sym]['available'], sym))
                CreateSellOrder(user, symbol, count=1)

    for user in deleteList:
        print('delete [ {} ]'.format(user))
        m_df = m_df[m_df['User'] != user]
        t_df = t_df[t_df['User'] != user]

    m_df.to_csv(mornitorFilePath, index=False)
    t_df.to_csv(transacFilePath, index=False)
    print('User Reset')
示例#8
0
# [START gae_python37_app]
from flask import Flask
from bitkub import Bitkub

# If `entrypoint` is not defined in app.yaml, App Engine will look for an app
# called `app` in `main.py`.
app = Flask(__name__)

API_KEY = '04c859241ce7cb77c2c6e8ef9f7481bf'
API_SECRET = '2b6833f376de370834538c00a38b756f'

# initial obj non-secure and secure
bitkub = Bitkub(api_key=API_KEY, api_secret=API_SECRET)
import requests
url = 'https://notify-api.line.me/api/notify'
token = 'HG7VEAzCskajzj8OLJ1dMmAwYvuBWmMXMOhFKjZS0Tn'
headers = {
    'content-type': 'application/x-www-form-urlencoded',
    'Authorization': 'Bearer ' + token
}
import time
start = 1593702012.6649423


@app.route('/')
def hello():
    #j = 1
    #while j < 200:
    zrx = bitkub.ticker(sym='THB_ZRX')
    x = zrx.get('THB_ZRX')
    last = x.get('last')