func GetEx(
	exchange model.Exchange,
	client interface{},
	market string,
	ticker float64,
	avg float64,
	dip, pip float64,
	max, min float64,
	top int,
	strict bool,
) (float64, float64, float64, error) {
	var (
		err  error
		out  float64
		book interface{}  
	)
	Max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	if book, err = exchange.GetBook(client, market, model.BOOK_SIDE_BIDS); err != nil {
		return 0, dip, pip, err
	}
	for cnt := Max(top, 4); cnt >= Max(top, 2); cnt-- {
		if out, err = get(exchange, client, market, ticker, avg, book, dip, pip, max, min, cnt); err == nil {
			return out, dip, pip, err
		}
	}
	if !strict {
		x := math.Round(dip)
		y := math.Round(pip)
		for y < 50 {
			y++
			for cnt := Max(top, 4); cnt >= Max(top, 2); cnt-- {
				if out, err = get(exchange, client, market, ticker, avg, book, x, y, max, min, cnt); err == nil {
					return out, x, y, err
				}
			}
		}
		for x > 0 {
			x--
			for cnt := Max(top, 4); cnt >= Max(top, 2); cnt-- {
				if out, err = get(exchange, client, market, ticker, avg, book, x, y, max, min, cnt); err == nil {
					return out, x, y, err
				}
			}
		}
		for y < 100 {
			y++
			for cnt := Max(top, 4); cnt >= Max(top, 2); cnt-- {
				if out, err = get(exchange, client, market, ticker, avg, book, x, y, max, min, cnt); err == nil {
					return out, x, y, err
				}
			}
		}
	}
	if err != nil {
		return 0, dip, pip, err
	} else {
		return 0, dip, pip, EOrderBookTooThin
	}
}
returns (agg, dip, pip, error)
package aggregation
import (
	"math"
	"github.com/svanas/nefertiti/errors"
	"github.com/svanas/nefertiti/model"
	"github.com/svanas/nefertiti/precision"
)
var (
	EOrderBookTooThin = errors.New("Cannot find any supports. Order book is too thin. Please reconsider this market.")
)
func Round(input, agg float64) float64 {
	return float64(int64(((input / agg) + 0.5))) * agg
}
func Get(
	exchange model.Exchange,
	market string,
	dip, pip float64,
	max, min float64,
	top int,
	strict, sandbox bool,
) (float64, float64, float64, error) {
	var (
		err    error
		client interface{}
		ticker float64
		stats  *model.Stats  
		avg    float64       
	)
	if client, err = exchange.GetClient(model.BOOK, sandbox); err != nil {
		return 0, dip, pip, err
	}
	if ticker, err = exchange.GetTicker(client, market); err != nil {
		return 0, dip, pip, err
	}
	if stats, err = exchange.Get24h(client, market); err != nil {
		return 0, dip, pip, err
	}
	if avg, err = stats.Avg(exchange, sandbox); err != nil {
		return 0, dip, pip, err
	}
	return GetEx(exchange, client, market, ticker, avg, dip, pip, max, min, top, strict)
}