def fillhistory(request): candle_interval = "MINUTE_1" market_symbol = "USDT-BTC" start_date = date(2016, 10, 12) end_date = date(2021, 4, 29) market_sym_exp = market_symbol.split("-") for single_date in daterange(start_date, end_date): year = single_date.strftime("%Y") month = single_date.strftime("%m") day = single_date.strftime("%d") bittrex_api_link = f"https://api.bittrex.com/v3/markets/{market_sym_exp[1]}-{market_sym_exp[0]}" \ f"/candles/{candle_interval}/historical/{year}/{month}/{day}" response = Request.get(bittrex_api_link) if "code" in response.json(): return print("ERROR: ", response.json()["code"]) else: for entry in response.json(): new_record = PairHistory(starts_at=entry["startsAt"], pair=market_symbol, open=entry["open"], high=entry["high"], low=entry["low"], close=entry["close"], volume=entry["volume"], quote_volume=entry["quoteVolume"]) new_record.save() print( f"Responce of {single_date} contains {len(response.json())} records" ) return HttpResponse("Started")
def sell_limit(self, market: str = "", quantity: Decimal = 0.0, price: Decimal = 0.0): if self.testing: return { "exchange_type": self.exchange_type, "quantity": quantity, "price": price, } payload = { "marketSymbol": market, "direction": "SELL", "type:": "LIMIT", "timeInForce": "GOOD_TIL_CANCELLED", "quantity": quantity, "limit": price } response = Request.post(f"{BITTREX_BASE}/orders", data=payload).json() if response.get("code"): return print("ERROR: ", response.get("code")) return response
def get_ticker(pair): print(f"Requesting {BITTREX_BASE}markets/{str(pair).upper()}/ticker") response = Request.get( f"{BITTREX_BASE}markets/{str(pair).upper()}/ticker").json() if response.get("code"): return print("ERROR: ", response.get("code")) return response
def _send_request(url): return Request.get(self.base + url)
def _handle_response(url): return Request.get(url)
def get_open_orders(self, marketsymbol: str = ""): # Return local exchange orders and remote response = Request.get(f"{BITTREX_BASE}orders/open") if response.get("code"): return print("ERROR: ", response.get("code")) return response