def test(self): last_tid = self.d * 1e6 - 1 last_price = 0.5 p = find_clear_minute_prices(self.trades, last_tid, last_price) self.assertEqual(len(p), 1) self.assertEqual(p[0]["price"], 1) self.assertEqual(p[0]["time"], datetime.datetime(2012,1,1,2,3,0,0,utc))
def test(self): last_tid = self.d * 1e6 - 1 last_price = 0.5 p = find_clear_minute_prices(self.trades, last_tid, last_price) self.assertEqual(len(p), 1) self.assertEqual(p[0]["price"], 1) self.assertEqual(p[0]["time"], datetime.datetime(2012, 1, 1, 2, 3, 0, 0, utc))
def handle(self, *args, **options): if already_running(): #self.stdout.write("Already running") return time_started = util.get_utc_time_now() has_expired = False now = util.get_utc_time_now() one_hour = datetime.timedelta(0, 3600, 0) try: last_bitcoin_price = Bitcoin_Price.objects.order_by('-time')[0] last_tid = last_bitcoin_price.rollover_id_b except IndexError: last_tid = int(util.datetime_to_unix_time(now - one_hour) * 1e6) trades = self.get_gox_trades( last_tid - 1) # needs to include the last rollover trade if len(trades) > 0: try: last_tid = int(trades[0]["tid"]) except: return last_price = trades[0]["price"] while (len(trades) > 0 and not has_expired): prices = find_clear_minute_prices(trades, last_tid, last_price) for price in prices: bitcoin_price = Bitcoin_Price(**price) bitcoin_price.save() last_tid = int(trades[-1]["tid"]) last_price = trades[-1]["price"] time.sleep(1) # Don't hammer the gox server too hard time_taken = util.get_utc_time_now() - time_started has_expired = time_taken.total_seconds() > 30 # Check if there are more trades after the last trade in the # previous set of trades if (len(trades) == 500): trades = self.get_gox_trades(last_tid) else: trades = []
def handle(self, *args, **options): if already_running(): #self.stdout.write("Already running") return time_started = util.get_utc_time_now() has_expired = False now = util.get_utc_time_now() one_hour = datetime.timedelta(0, 3600, 0) try: last_bitcoin_price = Bitcoin_Price.objects.order_by('-time')[0] last_tid = last_bitcoin_price.rollover_id_b except IndexError: last_tid = int(util.datetime_to_unix_time(now-one_hour) * 1e6) trades = self.get_gox_trades(last_tid - 1) # needs to include the last rollover trade if len(trades) > 0: try: last_tid = int(trades[0]["tid"]) except: return last_price = trades[0]["price"] while (len(trades) > 0 and not has_expired): prices = find_clear_minute_prices(trades, last_tid, last_price) for price in prices: bitcoin_price = Bitcoin_Price(**price) bitcoin_price.save() last_tid = int(trades[-1]["tid"]) last_price = trades[-1]["price"] time.sleep(1) # Don't hammer the gox server too hard time_taken = util.get_utc_time_now() - time_started has_expired = time_taken.total_seconds() > 30 # Check if there are more trades after the last trade in the # previous set of trades if (len(trades) == 500): trades = self.get_gox_trades(last_tid) else: trades = []