示例#1
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)
示例#2
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)