示例#1
0
def currency_update():
    while True:
        currency_response = requests.request("GET",
                                             currency_url).json()['result']
        for item in currency_response:

            coin_pair = item['MarketName']
            day_high = item['High']
            day_low = item['Low']
            volume = item['Volume']
            last_price = item['Last']
            base_volume = item['BaseVolume']
            bid_price = item['Bid']
            ask_price = item['Ask']
            open_buy = item['OpenBuyOrders']
            open_sell = item['OpenSellOrders']
            prev_day = item['PrevDay']

            currency = Currency.select().where(Currency.coin_pair == coin_pair)

            if not currency:
                Currency.create(coin_pair=coin_pair,
                                day_high=day_high,
                                day_low=day_low,
                                volume=volume,
                                last_price=last_price,
                                base_volume=base_volume,
                                bid_price=bid_price,
                                ask_price=ask_price,
                                open_buy=open_buy,
                                open_sell=open_sell,
                                prev_day=prev_day).save()

                currency = Currency.select().where(
                    Currency.coin_pair == coin_pair).get()
                market_update(currency)

            elif currency:
                Currency.update(day_high=day_high,
                                day_low=day_low,
                                volume=volume,
                                last_price=last_price,
                                base_volume=base_volume,
                                bid_price=bid_price,
                                ask_price=ask_price,
                                open_buy=open_buy,
                                open_sell=open_sell,
                                prev_day=prev_day).where(
                                    Currency.coin_pair == coin_pair).execute()

        print("Paused for 900 seconds")
        time.sleep(900)
示例#2
0
 def get(self):
     user = User.select().where(User.id == int(self.current_user)).get()
     names = self.currency_names()
     # get user's portfolio based off of slug in url
     userMarkets = UserCurrency.select().where(
         UserCurrency.user_id == user.id)
     bitcoin = Currency.select().where(
         Currency.coin_pair == "USDT-BTC").get()
     # set bitcoin as variable in order to render the price on the index page.
     if not userMarkets:
         market = Market.select().join(Currency).where(
             Currency.coin_pair == "USDT-BTC").get()
         return self.render_template("dashboard.html", {
             "user": user,
             "market": market,
             "bitcoin": bitcoin,
             'names': names
         })
     return self.render_template(
         "dashboard.html", {
             "user": user,
             "bitcoin": bitcoin,
             "userMarkets": userMarkets,
             'names': names
         })
示例#3
0
 def get(self):
     user = False
     if self.current_user:
         user = int(self.current_user)
     bitcoin = Currency.select().where(Currency.coin_pair == "USDT-BTC").get()
     # set bitcoin as variable in order to render the price on the index page.
     markets = Market.select().join(Currency).where(Currency.id == Market.currency_id).order_by(Currency.volume.desc()).limit(6)
     return self.render_template("index.html", {'markets': markets, "bitcoin": bitcoin, "user": user})
示例#4
0
    def start(self):
        print('----TRADER STARTED----')
        currencies = Currency.select().group_by(Currency.currency)
        for currency in currencies:
            scan_results = self.scan(currency.currency)

            print(scan_results)

            simple_safe_strategy = SimpleSafeStrategy(scan_results)
            self.decide(currency.currency, simple_safe_strategy)
示例#5
0
    def scan(self, currency):
        prices = Currency.select().where(
            Currency.currency == currency).order_by(-Currency.date).limit(30)
        up_count = 0
        down_count = 0

        up_streak = 0
        down_streak = 0

        print('------------------')
        for i in reversed(range(len(prices))):
            prev = prices[i - 1]
            curr = prices[i]

            if prev.price == curr.price:
                continue

            diff = round(prev.price - curr.price, 6)
            diff_pct = round((diff / prev.price) * 100, 6)

            if prev.price > curr.price:
                state = '+++'
                up_count += 1
                up_streak += 1
                down_streak = 0
            else:
                state = '---'
                down_count += 1
                up_streak = 0
                down_streak += 1

            date = datetime.strptime(curr.date.replace(':00Z', ''),
                                     '%Y-%m-%dT%H:%M')
            # print('{} ~ {}: ${} {} {}% \tdiff={}$'.format(
            #     currency, date, curr.price, state, diff_pct, diff))

        start_price = prices[-1].price
        curr_price = prices[0].price
        price_30m_change = curr_price - start_price
        price_30m_change_pct = (price_30m_change / start_price * 100) / 100

        return dict((
            ('up_streak', up_streak),
            ('down_streak', down_streak),
            ('up_count', up_count),
            ('down_count', down_count),
            ('going_up', up_count > down_count),
            ('up_down_diff', up_count - down_count),
            ('price_30m_change', price_30m_change),
            ('price_30m_change_pct', price_30m_change_pct),
            ('price_1h_change', prices[-1].price_1h_change),
            ('price_1h_change_pct', prices[-1].price_1h_change_pct),
            ('price_1d_change', prices[-1].price_1d_change),
            ('price_1d_change_pct', prices[-1].price_1d_change_pct),
        ))