github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v1/trades_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 TestTradesServiceGet(t *testing.T) {
    12  	httpDo = func(req *http.Request) (*http.Response, error) {
    13  		msg := `[{
    14             "timestamp":1444266681,
    15             "tid":11988919,
    16             "price":"244.8",
    17             "amount":"0.03297384",
    18             "exchange":"bitfinex",
    19             "type":"sell"
    20         }]`
    21  
    22  		resp := http.Response{
    23  			Body:       ioutil.NopCloser(bytes.NewBufferString(msg)),
    24  			StatusCode: 200,
    25  		}
    26  		return &resp, nil
    27  	}
    28  
    29  	trades, err := NewClient().Trades.All("ethusd", time.Time{}, 0)
    30  
    31  	if err != nil {
    32  		t.Error(err)
    33  	}
    34  
    35  	if len(trades) != 1 {
    36  		t.Error("Expected", 1)
    37  		t.Error("Actual ", len(trades))
    38  	}
    39  }