def list(self, request): pair_view_set = PairViewSet() data = [] pairs_names = self._get_bestchange_pair_names() pairs = Pair.objects.filter(disabled=False, test_mode=False, name__in=pairs_names) for pair in pairs: if not pair_view_set._get_dynamic_test_mode(pair): order = Order(pair=pair, amount_base=Decimal('1')) try: order.calculate_quote_from_base() except Price.DoesNotExist: continue data.append(self._get_order_return_data(order)) reverse_pair = pair.reverse_pair if reverse_pair and not pair_view_set._get_dynamic_test_mode( reverse_pair): order = Order(pair=reverse_pair, amount_quote=Decimal('1')) try: order.calculate_base_from_quote() except Price.DoesNotExist: continue data.append(self._get_order_return_data(order)) return Response(data)
def _create_order_with_default_values(self, pair): base_maximal = pair.base.current_maximal_amount_to_sell base_minimal = pair.base.minimal_amount quote_maximal = pair.quote.maximal_amount quote_minimal = pair.quote.minimal_amount if pair.is_crypto: amount_quote = \ quote_minimal * \ settings.DEFAULT_CRYPTO_ORDER_DEPOSIT_AMOUNT_MULTIPLIER if amount_quote >= quote_maximal: amount_quote = (quote_maximal + quote_minimal) / Decimal('2') else: amount_quote = settings.DEFAULT_FIAT_ORDER_DEPOSIT_AMOUNT if amount_quote < quote_minimal: amount_quote = \ quote_minimal \ * settings.DEFAULT_FIAT_ORDER_DEPOSIT_AMOUNT_MULTIPLIER order = Order(pair=pair, amount_quote=amount_quote) order.calculate_base_from_quote() if all([ not base_minimal <= order.amount_base <= base_maximal, base_maximal > base_minimal ]): if order.amount_base > base_maximal: # return value between minimal and maximal possible # (closer to maximal to avoid minimal quote error) amount_base = \ (base_minimal + Decimal('4') * base_maximal) / Decimal('5') else: amount_base = base_minimal order = Order(pair=pair, amount_base=amount_base) order.calculate_quote_from_base() return order
def _get_order(self, request, pair_name=None): amount_base = self._amount_to_decimal('amount_base') amount_quote = self._amount_to_decimal('amount_quote') if not pair_name: raise self.PAIR_REQUIRED try: pair = Pair.objects.get(name=pair_name) except (ObjectDoesNotExist, MultipleObjectsReturned): raise self.PAIR_DOES_NOT_EXIST if amount_base: amount_base = Decimal(amount_base) order = Order(pair=pair, amount_base=amount_base) order.calculate_quote_from_base() elif amount_quote: amount_quote = Decimal(amount_quote) order = Order(pair=pair, amount_quote=amount_quote) order.calculate_base_from_quote() else: order = self._create_order_with_default_values(pair) return order