github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v1/history_test.go (about) 1 package bitfinex 2 3 import ( 4 "bytes" 5 "io/ioutil" 6 "net/http" 7 "testing" 8 "time" 9 ) 10 11 func TestHistoryBalance(t *testing.T) { 12 httpDo = func(req *http.Request) (*http.Response, error) { 13 msg := `[{ 14 "currency":"USD", 15 "amount":"-246.94", 16 "balance":"515.4476526", 17 "description":"Position claimed @ 245.2 on wallet trading", 18 "timestamp":"1444277602.0" 19 }]` 20 resp := http.Response{ 21 Body: ioutil.NopCloser(bytes.NewBufferString(msg)), 22 StatusCode: 200, 23 } 24 return &resp, nil 25 } 26 27 balance, err := NewClient().History.Balance("BTC", "", time.Time{}, time.Time{}, 0) 28 29 if err != nil { 30 t.Error(err) 31 } 32 33 if len(balance) != 1 { 34 t.Error("Expected", 1) 35 t.Error("Actual ", len(balance)) 36 } 37 38 } 39 40 func TestHistoryMovements(t *testing.T) { 41 httpDo = func(req *http.Request) (*http.Response, error) { 42 msg := `[{ 43 "id":581183, 44 "currency":"BTC", 45 "method":"BITCOIN", 46 "type":"WITHDRAWAL", 47 "amount":".01", 48 "description":"3QXYWgRGX2BPYBpUDBssGbeWEa5zq6snBZ, offchain transfer ", 49 "status":"COMPLETED", 50 "timestamp":"1443833327.0" 51 }]` 52 resp := http.Response{ 53 Body: ioutil.NopCloser(bytes.NewBufferString(msg)), 54 StatusCode: 200, 55 } 56 return &resp, nil 57 } 58 59 movements, err := NewClient().History.Movements("BTC", "", time.Time{}, time.Time{}, 0) 60 61 if err != nil { 62 t.Error(err) 63 } 64 65 if len(movements) != 1 { 66 t.Error("Expected", 1) 67 t.Error("Actual ", len(movements)) 68 } 69 70 } 71 72 func TestHistoryTrades(t *testing.T) { 73 httpDo = func(req *http.Request) (*http.Response, error) { 74 msg := `[{ 75 "price":"246.94", 76 "amount":"1.0", 77 "timestamp":"1444141857.0", 78 "exchange":"", 79 "type":"Buy", 80 "fee_currency":"USD", 81 "fee_amount":"-0.49388", 82 "tid":11970839, 83 "order_id":446913929 84 }]` 85 resp := http.Response{ 86 Body: ioutil.NopCloser(bytes.NewBufferString(msg)), 87 StatusCode: 200, 88 } 89 return &resp, nil 90 } 91 92 trades, err := NewClient().History.Trades("BTC", time.Time{}, time.Time{}, 0, false) 93 94 if err != nil { 95 t.Error(err) 96 } 97 98 if len(trades) != 1 { 99 t.Error("Expected", 1) 100 t.Error("Actual ", len(trades)) 101 } 102 if trades[0].TID != 11970839 { 103 t.Error("Expected", 11970839) 104 t.Error("Actual ", trades[0].TID) 105 } 106 107 }