def get_configs(pair, type):
    config_func = change_config.Change_config()
    controls = config_func.get_pair_config(pair)
    configs = {}
    if type == "long":
        transactions = config_func.get_trading_num()

        lev_long = controls['lev_long']
        dicount_rate = controls['long_p']
        curr_price = round(price.get_price(pair), 2)

        configs['discount_rate'] = dicount_rate
        configs['price'] = curr_price
        configs["transaction"] = controls['long_amount']
        configs['leverage_rate'] = controls['lev_long']
        if configs['discount_rate']:
            configs['price'] = configs['price'] * (1 -
                                                   configs['discount_rate'])
    elif type == "short":
        transactions = config_func.get_trading_num()

        lev_long = controls['lev_short']
        dicount_rate = controls['short_p']
        curr_price = round(price.get_price(pair), 2)

        configs['discount_rate'] = dicount_rate
        configs['price'] = curr_price
        configs["transaction"] = controls['short_amount']
        configs['leverage_rate'] = controls['lev_short']
        if configs['discount_rate']:
            configs['price'] = configs['price'] * (1 +
                                                   configs['discount_rate'])
    else:
        print("type invalid")
    return configs
def get_price_formatted(destn_place, deptDate, file_name):
    format = 'json'
    source_place = "ORD"
    seatingclass = 'E'
    arrivalDate = ''
    price.get_price(format, source_place, destn_place, deptDate, seatingclass,
                    arrivalDate, file_name)
Example #3
0
def limit_short_trailing(pair,
                         short_price,
                         quantity,
                         trade_type='short',
                         trigger_per=1,
                         deviation=0.5,
                         stop_loss_per=2):
    configs = change_config.Change_config()
    transaction_func = transaction.Buy_sell()
    # buy
    """
    get order_time 
    while curr_price is higher than price
        sleep 1.5 second 
        get current price 
        if current time > order_time +2h:
            print time expired 
            return 
    else: 
        buy 
    """
    # update trade number allowed
    configs.update_trading_num("short", -1)
    configs.update_short_trade_avl(pair, -1)
    start_time = int(time.time())
    curr_price = price.get_price(pair)
    print("current price:", curr_price)
    while curr_price < short_price:
        print("current price: " + str(curr_price) + "| long price:" +
              str(short_price))
        time.sleep(1.5)
        if int(time.time()) > start_time + 7200:
            print("time expired")
            configs.update_trading_num("short", 1)
            configs.update_short_trade_avl(pair, 1)
            return
        curr_price = price.get_price(pair)
    else:
        buy = transaction_func.mkt_buy_sell_future(pair=pair,
                                                   quantity=quantity,
                                                   positionSide="SHORT",
                                                   side='SELL')
    # trailing
    trailing_func = trailing.Trailing(q=quantity,
                                      trade_type=trade_type,
                                      trigger_per=trigger_per,
                                      deviation=deviation,
                                      stop_loss_per=stop_loss_per,
                                      pair=pair)
    trailing_func.trailing_stop_short()

    configs.update_trading_num("short", 1)
    configs.update_short_trade_avl(pair, 1)

    print("successful")
Example #4
0
def limit_long_trailing(pair,
                        long_price,
                        quantity,
                        trade_type='long',
                        trigger_per=1,
                        deviation=0.5,
                        stop_loss_per=2):
    configs = change_config.Change_config()
    transaction_func = transaction.Buy_sell()
    # buy
    """
    get order_time 
    while curr_price is higher than price
        sleep 1.5 second 
        get current price 
        if current time > order_time +2h:
            print time expired 
            return 
    else: 
        buy 
    """
    # trailing
    configs.update_trading_num("long", -1)
    configs.update_long_trade_avl(pair, -1)
    start_time = int(time.time())
    curr_price = price.get_price(pair)
    while curr_price > long_price:
        print("current price: " + str(curr_price) + "| long price:" +
              str(long_price))
        time.sleep(1.5)
        if int(time.time()) > start_time + 7200:
            print("time expired")
            configs.update_trading_num("long", 1)
            configs.update_long_trade_avl(pair, 1)
            return
        curr_price = price.get_price(pair)
    else:
        buy = transaction_func.mkt_buy_sell_future(pair=pair,
                                                   quantity=quantity,
                                                   positionSide="LONG",
                                                   side='BUY')
        print("bought at " + str(curr_price))
    trailing_func = trailing.Trailing(
        q=quantity,
        trade_type=trade_type,
        trigger_per=trigger_per,
        deviation=deviation,
        stop_loss_per=stop_loss_per,
        pair=pair,
    )
    trailing_func.trailing_stop_long()
    configs.update_trading_num("long", 1)
    configs.update_long_trade_avl(pair, 1)
    print("successful")
Example #5
0
def btc_fee(dane):
    size = 140
    s = 10**8
    if dane != 'err':
        priceb = price.get_price('btc')
        if priceb != 'err':
            p = 'Fee comparison\nPrice (Coinbase) : ' + str(priceb) + ' USD\n'
            fcost = str(round(
                float(dane['fastestFee']) * size * priceb / s, 4)) + ' USD'
            hcost = str(
                round(float(dane['halfHourFee']) * size * priceb / s,
                      4)) + ' USD'
            ocost = str(round(float(dane['hourFee']) * size * priceb / s,
                              4)) + ' USD'

            w = p + 'BTC recommended fee.\nTx size 140 VBytes:\n\n'
            fastestbtc = f"< 30 minutes : {str(dane['fastestFee']):>8} sat/VB : ~{fcost:>8}\n"
            halfhbtc = f"  30 minutes : {str(dane['halfHourFee']):>8} sat/VB : ~{hcost:>8}\n"
            onehbtc = f"     1 hour  : {str(dane['hourFee']):>8} sat/VB : ~{ocost:>8}\n\n"
            k = "https://mempool.space/"
            entry = w + fastestbtc + halfhbtc + onehbtc + k
        else:
            entry = 'err'
            logging.warning(f'Brak ceny BTC')
    else:
        entry = 'err'
    return entry
Example #6
0
def eth_fee(dane):
    size = 21000
    s = 10**9
    if dane != 'err':
        pricee = price.get_price('eth')
        if pricee != 'err':
            p = 'Price (Coinbase) : ' + str(pricee) + ' USD\n'
            fcost = str(
                round((float(dane['fast']) / 10) * size * pricee / s,
                      4)) + ' USD'
            ffcost = str(
                round((float(dane['fastest']) / 10) * size * pricee / s,
                      4)) + ' USD'
            scost = str(
                round((float(dane['safeLow']) / 10) * size * pricee / s,
                      4)) + ' USD'

            w = p + 'ETH recommended gas price.\nTx size 21000 gas:\n\n'
            fastesteth = f"< 30 seconds : {str(float(dane['fastest']) / 10):>8} gwei : ~{ffcost:>8}\n"
            fasteth = f"< 2 minutes  : {str(float(dane['fast']) / 10):>8} gwei : ~{fcost:>8}\n"
            safeloweth = f"< 30 minutes : {str(float(dane['safeLow']) / 10):>8} gwei : ~{scost:>8}\n\n"
            k = "https://ethgasstation.info/\n"
            entry = w + fastesteth + fasteth + safeloweth + k
        else:
            entry = 'err'
            logging.warning(f'Brak ceny ETH')
    else:
        entry = 'err'
    return entry
Example #7
0
def main():
    try:
        price = float(get_price('btc'))
    except:
        price = 'err'

    try:
        rate = float(queryNBP(build_url(selector='usd'))[1]['rates'][0]['mid'])
    except:
        rate = 'err'

    if price != 'err' and rate != 'err':

        flat = float(2538.29)
        # flat = 0
        loan = float(121838.15)

        my_plk = load_pickle(fname)
        print(my_plk)
        btc_plk = float(my_plk[0]['btc_current'])
        mc_plk = int(my_plk[0]['mc'])
        loan_plk = float(my_plk[0]['loan_current'])

        flat_dollars = float(flat / rate)
        exchange_fee = 0.005 * flat_dollars
        flat_dollars += exchange_fee
        flat_btc = flat_dollars / price

        new_btc = round(float(btc_plk - flat_btc), 10)
        new_mc = mc_plk + 1
        new_loan = loan_plk - flat
        new_btc_pln = new_btc * price * rate

        new_data = {
            'mc': new_mc,
            'btc_current': new_btc,
            'loan_current': new_loan,
            'btc_pl': new_btc_pln
        }
        save2pickle(new_data)

        w = wypok_bot_lib
        entry = f"Kredyt na BTC fun.\n" \
                f"W dniu 29 maja 2020 za poradą @rysiekryszard wzięto 100 000 PLN kredytu na zakup BTC.\n" \
                f"10 każdego miesiąca, z zakupionych BTC, będzie spłacana rata kredytu.\n" \
                f"Oznacza, to sprzedaż BTC o wartości równej racie + 0.5% prowizji giełdowej.\n" \
                f"Tym samym pomniejszenie ilości BTC.\n\n" \
                f"Całkowity koszt kredytu: {loan:.2f} PLN\n" \
                f"Bieżąca wartość BTC: {new_btc_pln:.4f} PLN\n" \
                f"Bieżąca ilość BTC: {new_btc}\n" \
                f"Rata numer: {mc_plk}\n" \
                f"Cena BTC Coinbase: {price} $\n" \
                f"Kurs USD NBP: {rate}\n" \
                f"Wartość raty: {flat} PLN, {flat_dollars:.4f} $, {flat_btc:8f} BTC"
        w.add_entry(entry, f'{target_path}/rysiek_investment.png', 1)

    else:
        logging.error(f'Stopped')
url_pool = []
url_pool_price = []

for i in trange(1, 51):
    print('第' + str(i) + '轮....')
    str_url = "http://sh.ziroom.com/z/z1-p" + str(i) + "/"
    # 获取网页源代码
    res = gethtml(str_url)
    sleep(1)
    # 使用lxml的方式解析
    soup = BeautifulSoup(res, "lxml")
    # 找到所有此页面的具体租房的链接板块
    ziroom_url = soup.find_all(attrs={"class": "info-box"})

    now_all_price = []
    if price.get_price(str_url) == False:
        print('价格图片识别出错...跳过该轮...')
        continue
    else:
        now_all_price = price.get_price(str_url)
        print(now_all_price)
        if now_all_price == False:
            print('出错...跳过该轮...')
            continue
        else:
            # 获取网页租房名称以及链接
            for j in ziroom_url:
                ziroom_one_url = 'http:' + j.find('a').get("href")
                url_pool.append(str(ziroom_one_url))

            for j in now_all_price:
Example #9
0
def Click():
    
    game = e.get()
    print(game)
    # gets game string
    
    aux = " Steam"
    # join game name + steam
    query = game + aux
    #print(query)

    app_data_main = gather_app_data(query)
    # steam works with appdata numbers, each game has an unique appdata
    
    url = gather_url(query)
    print(url)
    # this way we search google for the steam url, to see if the game exists, and also to gather the appdata number

    price = {}
    price = get_price(url, app_data_main)
    # this function returns a dictionary with every price possible, for each Steam Store in the world
    
    # print(price)

    j = 0

    while(1):
        
        # we get the main values as a test
        if j == 0:
            flag = 'Brazilian Real'
        if j == 1:
            flag = 'U.S. Dollar'
        if j == 2:
            flag = 'Canadian Dollar'
        if j == 3:
            flag = 'Australian Dollar'
        if j == 4:
            break; 
            
        i = 0
        while(1):
            # search the currency field for our country's currency
            if (price['Currency'].get(i) == flag):
                break;
            i = i + 1

        print(price['Currency'].get(i))
        print(price['Price atm'].get(i))
        print(price['Lowest Price Ever'].get(i))
        
        # for each variable, we get an information about that country
        if j == 0:
            
            currency_brl = price['Currency'].get(i)
            price_atm_brl = price['Price atm'].get(i)
            lowest_price_brl = price['Lowest Price Ever'].get(i)
            
        if j == 1:
            
            currency_usd = price['Currency'].get(i)
            price_atm_usd = price['Price atm'].get(i)
            lowest_price_usd = price['Lowest Price Ever'].get(i)
            
        if j == 2:
            
            currency_cnd = price['Currency'].get(i)
            price_atm_cnd = price['Price atm'].get(i)
            lowest_price_cnd = price['Lowest Price Ever'].get(i)
            
        if j == 3:
            
            currency_aud = price['Currency'].get(i)
            price_atm_aud = price['Price atm'].get(i)
            lowest_price_aud = price['Lowest Price Ever'].get(i)
            
            
        j = j + 1
    
    # now we put It all on a new window for the user to see
    
    top = Toplevel()
    top.title('Results') 
       
    Label_BR = Label(top, text="Price in Brasil: ")
    Label_BR.grid(row=1, column=1)
    Label_Price_BR = Label(top, text=price_atm_brl)
    Label_Price_BR.grid(row=1, column=2)

   
    Label_US = Label(top, text="Price in USA: ")
    Label_US.grid(row=2, column=1)
    Label_Price_usd = Label(top, text=price_atm_usd)
    Label_Price_usd.grid(row=2, column=2)
   
    Label_CND = Label(top, text="Price in Canada")
    Label_CND.grid(row=3, column=1)
    Label_Price_cnd = Label(top, text=price_atm_cnd)
    Label_Price_cnd.grid(row=3, column=2)
    
       
    Label_AUD = Label(top, text="Price in Australia")
    Label_AUD.grid(row=4, column=1)
    Label_Price_aud = Label(top, text=price_atm_aud)
    Label_Price_aud.grid(row=4, column=2)