예제 #1
0
func (client Client) OrderBook() (
	bids []bitcoin.Order, asks []bitcoin.Order, err error) {

	var unparsed unparsedOrderBook
	err = getRequest(API_ORDER_BOOK, &unparsed)
	if err != nil {
		return
	}

	for _, unparsedBid := range unparsed.Bids {
		var price, amount float64
		price, amount, err = parseFloatPair(unparsedBid)
		if err != nil {
			return
		}
		bids = append(bids, bitcoin.BuyOrder(price, amount))
	}
	for _, unparsedAsk := range unparsed.Asks {
		var price, amount float64
		price, amount, err = parseFloatPair(unparsedAsk)
		if err != nil {
			return
		}
		asks = append(asks, bitcoin.SellOrder(price, amount))
	}
	return
}
예제 #2
0
파일: orders.go 프로젝트: dskloet/bitcoin
func (client *Client) OpenOrders() (orders bitcoin.OrderList, err error) {
	var resp ordersResponse
	params := client.createParams()
	err = client.postRequest(API_ORDERS, params, &resp)
	if err != nil {
		return
	}

	for _, responseOrder := range resp {
		var order bitcoin.Order
		var price, amount float64
		price, err = strconv.ParseFloat(responseOrder.Price, 64)
		if err != nil {
			return
		}
		amount, err = strconv.ParseFloat(responseOrder.Remaining_amount, 64)
		if err != nil {
			return
		}
		switch responseOrder.Side {
		case "buy":
			order = bitcoin.BuyOrder(price, amount)
		case "sell":
			order = bitcoin.SellOrder(price, amount)
		}
		order.Id = bitcoin.OrderId(fmt.Sprintf("%d", responseOrder.Id))
		orders = append(orders, order)
	}
	return
}
예제 #3
0
func mapToOrder(result resultMap) (order bitcoin.Order) {
	price := result.getFloat("price")
	amount := result.getFloat("amount")
	orderType := result.getInt("type")
	if orderType == ORDER_BUY {
		order = bitcoin.BuyOrder(price, amount)
	} else {
		order = bitcoin.SellOrder(price, amount)
	}
	order.Id = bitcoin.OrderId(fmt.Sprintf("%v", result.getInt("id")))
	return
}
예제 #4
0
파일: depth.go 프로젝트: dskloet/bitcoin
func (client Client) OrderBook() (
	bids []bitcoin.Order, asks []bitcoin.Order, err error) {

	var book orderBook
	err = getRequest(API_DEPTH, &book)
	if err != nil {
		return
	}
	for _, pair := range book.Bids {
		bids = append(bids, bitcoin.BuyOrder(pair[0], pair[1]))
	}
	for _, pair := range book.Asks {
		asks = append(asks, bitcoin.SellOrder(pair[0], pair[1]))
	}
	return
}
예제 #5
0
func (client *Client) OpenOrders() (orders bitcoin.OrderList, err error) {
	params := client.createParams()
	params.Set("pair", "btc_usd")
	var resp activeOrdersResponse
	err = client.postRequest(API_ACTIVE_ORDERS, params, &resp)
	if err != nil {
		return
	}
	if resp.Success != 1 {
		err = errors.New(resp.Error)
		return
	}
	for id, activeOrder := range resp.Return {
		var order bitcoin.Order
		if activeOrder.Type == "buy" {
			order = bitcoin.BuyOrder(activeOrder.Rate, activeOrder.Amount)
		} else {
			order = bitcoin.SellOrder(activeOrder.Rate, activeOrder.Amount)
		}
		order.Id = id
	}
	return
}
예제 #6
0
func (client *Client) OpenOrders() (orders bitcoin.OrderList, err error) {
	params := client.createParams()
	var resp openOrdersResponse
	err = client.postRequest(API_OPEN_ORDERS, params, &resp)
	if err != nil {
		return
	}

	for id, order := range resp.Result.Open {
		if order.Status != "open" || order.Descr.Ordertype != "limit" {
			continue
		}
		var price, amount float64
		price, err = strconv.ParseFloat(order.Descr.Price, 64)
		if err != nil {
			return
		}
		amount, err = strconv.ParseFloat(order.Vol, 64)
		if err != nil {
			return
		}
		if strings.Contains(order.Oflags, "viqc") {
			amount = amount / price
		}
		if order.Descr.Type == "buy" {
			o := bitcoin.BuyOrder(price, amount)
			o.Id = id
			orders = append(orders, o)
		} else if order.Descr.Type == "sell" {
			o := bitcoin.SellOrder(price, amount)
			o.Id = id
			orders = append(orders, o)
		}
	}
	return
}
예제 #7
0
func NewSellOrder(price, amount float64) *StatusOrder {
	return &StatusOrder{bitcoin.SellOrder(price, amount), ORDER_NEW}
}