Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions account_transaction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package bitstamp

import (
"strconv"
"strings"
)

const (
UserDeposit UserTransactionType = iota
UserWithdrawal
UserMarketTrade
UserSubAccountTransfer
)

type UserTransactionType int8

func (t *UserTransactionType) UnmarshalJSON(b []byte) error {
s := strings.Trim(string(b), "\"")
i, err := strconv.ParseInt(s, 10, 8)
*t = UserTransactionType(i)
return err
}

func (t UserTransactionType) String() string {
switch t {
case UserDeposit:
return "Deposit"
case UserWithdrawal:
return "Withdrawal"
case UserMarketTrade:
return "MarketTrade"
case UserSubAccountTransfer:
return "SubAccountTransfer"
default:
return ""
}
}

type Float float64

func (f *Float) UnmarshalJSON(b []byte) error {
s := strings.Trim(string(b), "\"")
_f, err := strconv.ParseFloat(s, 64)
*f = Float(_f)
return err
}

// accountTransactionResult is used internally to ease the process of unmarshalling.
// For some reason, for the transaction endpoint, Bitstamp is sends numbers
// encoded as both strings and floats, intermingled. This means that we cannot
// use the `json:"name,string"` automagic conversion here.
type accountTransactionResult struct {
DateTime string `json:"datetime"`
Id int64 `json:"id"`
Type UserTransactionType `json:"type"`
Usd Float `json:"usd"`
Eur Float `json:"eur"`
Btc Float `json:"btc"`
Xrp Float `json:"xrp"`
Ltc Float `json:"ltc"`
Eth Float `json:"eth"`
BtcUsd Float `json:"btc_usd"`
UsdBtc Float `json:"usd_btc"`
Fee Float `json:"fee"`
OrderId int64 `json:"order_id"`
}

type AccountTransactionResult struct {
DateTime string `json:"datetime"`
Id int64 `json:"id"`
Type UserTransactionType `json:"type"`
Usd float64 `json:"usd"`
Eur float64 `json:"eur"`
Btc float64 `json:"btc"`
Xrp float64 `json:"xrp"`
Ltc float64 `json:"ltc"`
Eth float64 `json:"eth"`
BtcUsd float64 `json:"btc_usd"`
UsdBtc float64 `json:"usd_btc"`
Fee float64 `json:"fee"`
OrderId int64 `json:"order_id"`
}
31 changes: 30 additions & 1 deletion bitstamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func privateQuery(path string, values url.Values, v interface{}) error {
}

//parse the JSON response into the response object
//log.Println(string(body))
// log.Println(string(body))
return json.Unmarshal(body, v)
}

Expand Down Expand Up @@ -312,3 +312,32 @@ func OpenOrders() (*[]OpenOrder, error) {
}
return result, nil
}

func AccountTransactions() ([]AccountTransactionResult, error) {
internalTs := make([]accountTransactionResult, 0)
err := privateQuery("/user_transactions/", url.Values{}, &internalTs)
if err != nil {
return nil, err
}

ts := make([]AccountTransactionResult, len(internalTs))
for i, t := range internalTs {
ts[i] = AccountTransactionResult{
DateTime: t.DateTime,
Id: t.Id,
Type: t.Type,
Usd: float64(t.Usd),
Eur: float64(t.Eur),
Btc: float64(t.Btc),
Xrp: float64(t.Xrp),
Ltc: float64(t.Ltc),
Eth: float64(t.Eth),
BtcUsd: float64(t.BtcUsd),
UsdBtc: float64(t.UsdBtc),
Fee: float64(t.Fee),
OrderId: t.OrderId,
}
}

return ts, nil
}