Use -1 and 'f' for formatting floats.

This commit is contained in:
Adrian Gallagher
2015-06-20 17:01:14 +10:00
parent 1f6f160c23
commit 8761189400
12 changed files with 54 additions and 54 deletions

View File

@@ -365,7 +365,7 @@ func (a *Alphapoint) WithdrawCoins(symbol, product string, amount float64, addre
request := make(map[string]interface{}) request := make(map[string]interface{})
request["ins"] = symbol request["ins"] = symbol
request["product"] = product request["product"] = product
request["amount"] = strconv.FormatFloat(amount, 'f', 8, 64) request["amount"] = strconv.FormatFloat(amount, 'f', -1, 64)
request["sendToAddress"] = address request["sendToAddress"] = address
type Response struct { type Response struct {
@@ -390,8 +390,8 @@ func (a *Alphapoint) CreateOrder(symbol, side string, orderType int, quantity, p
request["ins"] = symbol request["ins"] = symbol
request["side"] = side request["side"] = side
request["orderType"] = orderType request["orderType"] = orderType
request["qty"] = strconv.FormatFloat(quantity, 'f', 8, 64) request["qty"] = strconv.FormatFloat(quantity, 'f', -1, 64)
request["px"] = strconv.FormatFloat(price, 'f', 2, 64) request["px"] = strconv.FormatFloat(price, 'f', -1, 64)
type Response struct { type Response struct {
ServerOrderID int64 `json:"serverOrderId"` ServerOrderID int64 `json:"serverOrderId"`

View File

@@ -220,8 +220,8 @@ func (b *Bitstamp) GetOpenOrders() {
func (b *Bitstamp) PlaceOrder(price float64, amount float64, Type int) { func (b *Bitstamp) PlaceOrder(price float64, amount float64, Type int) {
var req = url.Values{} var req = url.Values{}
req.Add("amount", strconv.FormatFloat(amount, 'f', 8, 64)) req.Add("amount", strconv.FormatFloat(amount, 'f', -1, 64))
req.Add("price", strconv.FormatFloat(price, 'f', 2, 64)) req.Add("price", strconv.FormatFloat(price, 'f', -1, 64))
orderType := BITSTAMP_API_BUY orderType := BITSTAMP_API_BUY
if Type == 1 { if Type == 1 {
@@ -247,7 +247,7 @@ func (b *Bitstamp) GetWithdrawalRequests() {
func (b *Bitstamp) BitcoinWithdrawal(amount float64, address string) { func (b *Bitstamp) BitcoinWithdrawal(amount float64, address string) {
var req = url.Values{} var req = url.Values{}
req.Add("amount", strconv.FormatFloat(amount, 'f', 8, 64)) req.Add("amount", strconv.FormatFloat(amount, 'f', -1, 64))
req.Add("address", address) req.Add("address", address)
err := b.SendAuthenticatedHTTPRequest(BITSTAMP_API_BITCOIN_WITHDRAWAL, req, nil) err := b.SendAuthenticatedHTTPRequest(BITSTAMP_API_BITCOIN_WITHDRAWAL, req, nil)
@@ -275,7 +275,7 @@ func (b *Bitstamp) UnconfirmedBitcoin() {
func (b *Bitstamp) RippleWithdrawal(amount float64, address, currency string) { func (b *Bitstamp) RippleWithdrawal(amount float64, address, currency string) {
var req = url.Values{} var req = url.Values{}
req.Add("amount", strconv.FormatFloat(amount, 'f', 8, 64)) req.Add("amount", strconv.FormatFloat(amount, 'f', -1, 64))
req.Add("address", address) req.Add("address", address)
req.Add("currency", currency) req.Add("currency", currency)

View File

@@ -313,8 +313,8 @@ func (b *BTCChina) GetAccountInfo(infoType string) {
func (b *BTCChina) PlaceOrder(buyOrder bool, price, amount float64, market string) { func (b *BTCChina) PlaceOrder(buyOrder bool, price, amount float64, market string) {
params := make([]interface{}, 0) params := make([]interface{}, 0)
params = append(params, strconv.FormatFloat(price, 'f', 2, 64)) params = append(params, strconv.FormatFloat(price, 'f', -1, 64))
params = append(params, strconv.FormatFloat(amount, 'f', 8, 64)) params = append(params, strconv.FormatFloat(amount, 'f', -1, 64))
if len(market) > 0 { if len(market) > 0 {
params = append(params, market) params = append(params, market)
@@ -507,10 +507,10 @@ func (b *BTCChina) RequestWithdrawal(currency string, amount float64) {
func (b *BTCChina) IcebergOrder(buyOrder bool, price, amount, discAmount, variance float64, market string) { func (b *BTCChina) IcebergOrder(buyOrder bool, price, amount, discAmount, variance float64, market string) {
params := make([]interface{}, 0) params := make([]interface{}, 0)
params = append(params, strconv.FormatFloat(price, 'f', 2, 64)) params = append(params, strconv.FormatFloat(price, 'f', -1, 64))
params = append(params, strconv.FormatFloat(amount, 'f', 8, 64)) params = append(params, strconv.FormatFloat(amount, 'f', -1, 64))
params = append(params, strconv.FormatFloat(discAmount, 'f', 2, 64)) params = append(params, strconv.FormatFloat(discAmount, 'f', -1, 64))
params = append(params, strconv.FormatFloat(variance, 'f', 2, 64)) params = append(params, strconv.FormatFloat(variance, 'f', -1, 64))
if len(market) > 0 { if len(market) > 0 {
params = append(params, market) params = append(params, market)
@@ -587,15 +587,15 @@ func (b *BTCChina) PlaceStopOrder(buyOder bool, stopPrice, price, amount, traili
params = append(params, stopPrice) params = append(params, stopPrice)
} }
params = append(params, strconv.FormatFloat(price, 'f', 2, 64)) params = append(params, strconv.FormatFloat(price, 'f', -1, 64))
params = append(params, strconv.FormatFloat(amount, 'f', 8, 64)) params = append(params, strconv.FormatFloat(amount, 'f', -1, 64))
if trailingAmt > 0 { if trailingAmt > 0 {
params = append(params, strconv.FormatFloat(trailingAmt, 'f', 2, 64)) params = append(params, strconv.FormatFloat(trailingAmt, 'f', -1, 64))
} }
if trailingPct > 0 { if trailingPct > 0 {
params = append(params, strconv.FormatFloat(trailingPct, 'f', 2, 64)) params = append(params, strconv.FormatFloat(trailingPct, 'f', -1, 64))
} }
if len(market) > 0 { if len(market) > 0 {

View File

@@ -222,8 +222,8 @@ func (b *BTCE) Trade(pair, orderType string, amount, price float64) {
req := url.Values{} req := url.Values{}
req.Add("pair", pair) req.Add("pair", pair)
req.Add("type", orderType) req.Add("type", orderType)
req.Add("amount", strconv.FormatFloat(amount, 'f', 8, 64)) req.Add("amount", strconv.FormatFloat(amount, 'f', -1, 64))
req.Add("rate", strconv.FormatFloat(price, 'f', 2, 64)) req.Add("rate", strconv.FormatFloat(price, 'f', -1, 64))
err := b.SendAuthenticatedHTTPRequest(BTCE_TRADE, req) err := b.SendAuthenticatedHTTPRequest(BTCE_TRADE, req)

View File

@@ -463,8 +463,8 @@ func (c *Coinbase) PlaceOrder(clientRef string, price, amount float64, side stri
request["client_oid"] = clientRef request["client_oid"] = clientRef
} }
request["price"] = strconv.FormatFloat(price, 'f', 2, 64) request["price"] = strconv.FormatFloat(price, 'f', -1, 64)
request["size"] = strconv.FormatFloat(amount, 'f', 8, 64) request["size"] = strconv.FormatFloat(amount, 'f', -1, 64)
request["side"] = side request["side"] = side
request["product_id"] = productID request["product_id"] = productID
@@ -574,7 +574,7 @@ func (c *Coinbase) GetFills(params url.Values) {
func (c *Coinbase) Transfer(transferType string, amount float64, accountID string) { func (c *Coinbase) Transfer(transferType string, amount float64, accountID string) {
request := make(map[string]interface{}) request := make(map[string]interface{})
request["type"] = transferType request["type"] = transferType
request["amount"] = strconv.FormatFloat(amount, 'f', 8, 64) request["amount"] = strconv.FormatFloat(amount, 'f', -1, 64)
request["coinbase_account_id"] = accountID request["coinbase_account_id"] = accountID
err := c.SendAuthenticatedHTTPRequest("POST", COINBASE_API_URL+COINBASE_TRANSFERS, request, nil) err := c.SendAuthenticatedHTTPRequest("POST", COINBASE_API_URL+COINBASE_TRANSFERS, request, nil)

View File

@@ -409,8 +409,8 @@ func (c *Cryptsy) CreateOrder(marketid, orderType string, amount, price float64)
req := url.Values{} req := url.Values{}
req.Set("marketid", marketid) req.Set("marketid", marketid)
req.Set("ordertype", orderType) req.Set("ordertype", orderType)
req.Set("quantity", strconv.FormatFloat(amount, 'f', 8, 64)) req.Set("quantity", strconv.FormatFloat(amount, 'f', -1, 64))
req.Set("price", strconv.FormatFloat(amount, 'f', 8, 64)) req.Set("price", strconv.FormatFloat(amount, 'f', -1, 64))
err := c.SendAuthenticatedHTTPRequest("POST", CRYPTSY_API_URL+CRYPTSY_ORDER, req) err := c.SendAuthenticatedHTTPRequest("POST", CRYPTSY_API_URL+CRYPTSY_ORDER, req)
@@ -441,10 +441,10 @@ func (c *Cryptsy) CreateTrigger(marketid int64, orderType string, quantity float
req := url.Values{} req := url.Values{}
req.Set("marketid", strconv.FormatInt(marketid, 10)) req.Set("marketid", strconv.FormatInt(marketid, 10))
req.Set("type", orderType) req.Set("type", orderType)
req.Set("quantity", strconv.FormatFloat(quantity, 'f', 8, 64)) req.Set("quantity", strconv.FormatFloat(quantity, 'f', -1, 64))
req.Set("comparison", comparison) req.Set("comparison", comparison)
req.Set("price", strconv.FormatFloat(price, 'f', 8, 64)) req.Set("price", strconv.FormatFloat(price, 'f', -1, 64))
req.Set("orderprice", strconv.FormatFloat(orderprice, 'f', 8, 64)) req.Set("orderprice", strconv.FormatFloat(orderprice, 'f', -1, 64))
if expires > 0 { if expires > 0 {
req.Set("expires", strconv.FormatInt(expires, 10)) req.Set("expires", strconv.FormatInt(expires, 10))

View File

@@ -157,8 +157,8 @@ func (h *HUOBI) Trade(orderType string, coinType int, price, amount float64) {
orderType = "sell" orderType = "sell"
} }
values.Set("coin_type", strconv.Itoa(coinType)) values.Set("coin_type", strconv.Itoa(coinType))
values.Set("amount", strconv.FormatFloat(amount, 'f', 8, 64)) values.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64))
values.Set("price", strconv.FormatFloat(price, 'f', 8, 64)) values.Set("price", strconv.FormatFloat(price, 'f', -1, 64))
err := h.SendAuthenticatedRequest(orderType, values) err := h.SendAuthenticatedRequest(orderType, values)
if err != nil { if err != nil {
@@ -172,8 +172,8 @@ func (h *HUOBI) MarketTrade(orderType string, coinType int, price, amount float6
orderType = "sell_market" orderType = "sell_market"
} }
values.Set("coin_type", strconv.Itoa(coinType)) values.Set("coin_type", strconv.Itoa(coinType))
values.Set("amount", strconv.FormatFloat(amount, 'f', 8, 64)) values.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64))
values.Set("price", strconv.FormatFloat(price, 'f', 8, 64)) values.Set("price", strconv.FormatFloat(price, 'f', -1, 64))
err := h.SendAuthenticatedRequest(orderType, values) err := h.SendAuthenticatedRequest(orderType, values)
if err != nil { if err != nil {
@@ -196,8 +196,8 @@ func (h *HUOBI) ModifyOrder(orderType string, coinType, orderID int, price, amou
values := url.Values{} values := url.Values{}
values.Set("coin_type", strconv.Itoa(coinType)) values.Set("coin_type", strconv.Itoa(coinType))
values.Set("id", strconv.Itoa(orderID)) values.Set("id", strconv.Itoa(orderID))
values.Set("amount", strconv.FormatFloat(amount, 'f', 8, 64)) values.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64))
values.Set("price", strconv.FormatFloat(price, 'f', 8, 64)) values.Set("price", strconv.FormatFloat(price, 'f', -1, 64))
err := h.SendAuthenticatedRequest("modify_order", values) err := h.SendAuthenticatedRequest("modify_order", values)
if err != nil { if err != nil {

View File

@@ -223,8 +223,8 @@ func (i *ItBit) PlaceWalletOrder(walletID, side, orderType, currency string, amo
params["side"] = side params["side"] = side
params["type"] = orderType params["type"] = orderType
params["currency"] = currency params["currency"] = currency
params["amount"] = strconv.FormatFloat(amount, 'f', 8, 64) params["amount"] = strconv.FormatFloat(amount, 'f', -1, 64)
params["price"] = strconv.FormatFloat(price, 'f', 2, 64) params["price"] = strconv.FormatFloat(price, 'f', -1, 64)
params["instrument"] = instrument params["instrument"] = instrument
if clientRef != "" { if clientRef != "" {
@@ -287,7 +287,7 @@ func (i *ItBit) WalletTransfer(walletID, sourceWallet, destWallet string, amount
params := make(map[string]interface{}) params := make(map[string]interface{})
params["sourceWalletId"] = sourceWallet params["sourceWalletId"] = sourceWallet
params["destinationWalletId"] = destWallet params["destinationWalletId"] = destWallet
params["amount"] = strconv.FormatFloat(amount, 'f', 8, 64) params["amount"] = strconv.FormatFloat(amount, 'f', -1, 64)
params["currencyCode"] = currency params["currencyCode"] = currency
err := i.SendAuthenticatedHTTPRequest("POST", path, params) err := i.SendAuthenticatedHTTPRequest("POST", path, params)

View File

@@ -525,11 +525,11 @@ func (k *Kraken) AddOrder(symbol, side, orderType string, price, price2, volume,
values.Set("pairs", symbol) values.Set("pairs", symbol)
values.Set("type", side) values.Set("type", side)
values.Set("ordertype", orderType) values.Set("ordertype", orderType)
values.Set("price", strconv.FormatFloat(price, 'f', 2, 64)) values.Set("price", strconv.FormatFloat(price, 'f', -1, 64))
values.Set("price2", strconv.FormatFloat(price, 'f', 2, 64)) values.Set("price2", strconv.FormatFloat(price, 'f', -1, 64))
values.Set("volume", strconv.FormatFloat(volume, 'f', 2, 64)) values.Set("volume", strconv.FormatFloat(volume, 'f', -1, 64))
values.Set("leverage", strconv.FormatFloat(leverage, 'f', 2, 64)) values.Set("leverage", strconv.FormatFloat(leverage, 'f', -1, 64))
values.Set("position", strconv.FormatFloat(position, 'f', 2, 64)) values.Set("position", strconv.FormatFloat(position, 'f', -1, 64))
result, err := k.SendAuthenticatedHTTPRequest(KRAKEN_ORDER_PLACE, values) result, err := k.SendAuthenticatedHTTPRequest(KRAKEN_ORDER_PLACE, values)

View File

@@ -160,7 +160,7 @@ func (l *LakeBTC) GetAccountInfo() {
} }
func (l *LakeBTC) Trade(orderType int, amount, price float64, currency string) { func (l *LakeBTC) Trade(orderType int, amount, price float64, currency string) {
params := strconv.FormatFloat(price, 'f', 8, 64) + "," + strconv.FormatFloat(amount, 'f', 8, 64) + "," + currency params := strconv.FormatFloat(price, 'f', -1, 64) + "," + strconv.FormatFloat(amount, 'f', -1, 64) + "," + currency
err := errors.New("") err := errors.New("")
if orderType == 0 { if orderType == 0 {

View File

@@ -437,8 +437,8 @@ func (o *OKCoin) GetFuturesPosition(symbol, contractType string) {
func (o *OKCoin) Trade(amount, price float64, symbol, orderType string) { func (o *OKCoin) Trade(amount, price float64, symbol, orderType string) {
v := url.Values{} v := url.Values{}
v.Set("amount", strconv.FormatFloat(amount, 'f', 8, 64)) v.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64))
v.Set("price", strconv.FormatFloat(price, 'f', 8, 64)) v.Set("price", strconv.FormatFloat(price, 'f', -1, 64))
v.Set("symbol", symbol) v.Set("symbol", symbol)
v.Set("type", orderType) v.Set("type", orderType)
@@ -453,8 +453,8 @@ func (o *OKCoin) FuturesTrade(amount, price float64, matchPrice, leverage int64,
v := url.Values{} v := url.Values{}
v.Set("symbol", symbol) v.Set("symbol", symbol)
v.Set("contract_type", contractType) v.Set("contract_type", contractType)
v.Set("price", strconv.FormatFloat(price, 'f', 8, 64)) v.Set("price", strconv.FormatFloat(price, 'f', -1, 64))
v.Set("amount", strconv.FormatFloat(amount, 'f', 8, 64)) v.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64))
v.Set("type", orderType) v.Set("type", orderType)
v.Set("match_price", strconv.FormatInt(matchPrice, 10)) v.Set("match_price", strconv.FormatInt(matchPrice, 10))
v.Set("lever_rate", strconv.FormatInt(leverage, 10)) v.Set("lever_rate", strconv.FormatInt(leverage, 10))
@@ -591,10 +591,10 @@ func (o *OKCoin) GetOrderHistory(orderID, pageLength, currentPage int64, orderTy
func (o *OKCoin) Withdrawal(symbol string, fee float64, tradePWD, address string, amount float64) { func (o *OKCoin) Withdrawal(symbol string, fee float64, tradePWD, address string, amount float64) {
v := url.Values{} v := url.Values{}
v.Set("symbol", symbol) v.Set("symbol", symbol)
v.Set("chargefee", strconv.FormatFloat(fee, 'f', 8, 64)) v.Set("chargefee", strconv.FormatFloat(fee, 'f', -1, 64))
v.Set("trade_pwd", tradePWD) v.Set("trade_pwd", tradePWD)
v.Set("withdraw_address", address) v.Set("withdraw_address", address)
v.Set("withdraw_amount", strconv.FormatFloat(amount, 'f', 8, 64)) v.Set("withdraw_amount", strconv.FormatFloat(amount, 'f', -1, 64))
err := o.SendAuthenticatedHTTPRequest("withdraw.do", v) err := o.SendAuthenticatedHTTPRequest("withdraw.do", v)
@@ -652,8 +652,8 @@ func (o *OKCoin) Borrow(symbol, days string, amount, rate float64) {
v := url.Values{} v := url.Values{}
v.Set("symbol", symbol) v.Set("symbol", symbol)
v.Set("days", days) v.Set("days", days)
v.Set("amount", strconv.FormatFloat(amount, 'f', 8, 64)) v.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64))
v.Set("rate", strconv.FormatFloat(rate, 'f', 8, 64)) v.Set("rate", strconv.FormatFloat(rate, 'f', -1, 64))
err := o.SendAuthenticatedHTTPRequest("borrow_money.do", v) err := o.SendAuthenticatedHTTPRequest("borrow_money.do", v)
if err != nil { if err != nil {

View File

@@ -254,8 +254,8 @@ func (o *OKCoin) WebsocketSpotTrade(symbol, orderType string, price, amount floa
values := make(map[string]string) values := make(map[string]string)
values["symbol"] = symbol values["symbol"] = symbol
values["type"] = orderType values["type"] = orderType
values["price"] = strconv.FormatFloat(price, 'f', 8, 64) values["price"] = strconv.FormatFloat(price, 'f', -1, 64)
values["amount"] = strconv.FormatFloat(amount, 'f', 8, 64) values["amount"] = strconv.FormatFloat(amount, 'f', -1, 64)
channel := "" channel := ""
if o.WebsocketURL == OKCOIN_WEBSOCKET_URL_CHINA { if o.WebsocketURL == OKCOIN_WEBSOCKET_URL_CHINA {
@@ -271,8 +271,8 @@ func (o *OKCoin) WebsocketFuturesTrade(symbol, contractType string, price, amoun
values := make(map[string]string) values := make(map[string]string)
values["symbol"] = symbol values["symbol"] = symbol
values["contract_type"] = contractType values["contract_type"] = contractType
values["price"] = strconv.FormatFloat(price, 'f', 8, 64) values["price"] = strconv.FormatFloat(price, 'f', -1, 64)
values["amount"] = strconv.FormatFloat(amount, 'f', 8, 64) values["amount"] = strconv.FormatFloat(amount, 'f', -1, 64)
values["type"] = strconv.Itoa(orderType) values["type"] = strconv.Itoa(orderType)
values["match_price"] = strconv.Itoa(matchPrice) values["match_price"] = strconv.Itoa(matchPrice)
values["lever_rate"] = strconv.Itoa(orderType) values["lever_rate"] = strconv.Itoa(orderType)