示例#1
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
}
示例#2
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
}