github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v1/order_book_test.go (about)

     1  package bitfinex
     2  
     3  import (
     4  	"bytes"
     5  	"io/ioutil"
     6  	"net/http"
     7  	"testing"
     8  )
     9  
    10  func TestOrderBookGet(t *testing.T) {
    11  	httpDo = func(req *http.Request) (*http.Response, error) {
    12  		msg := `{
    13             "bids":[{
    14             "rate":"9.1287",
    15             "amount":"5000.0",
    16             "period":30,
    17             "timestamp":"1444257541.0",
    18             "frr":"No"
    19         }],
    20             "asks":[{
    21             "rate":"8.3695",
    22             "amount":"407.5",
    23             "period":2,
    24             "timestamp":"1444260343.0",
    25             "frr":"No"
    26         }]
    27         }`
    28  
    29  		resp := http.Response{
    30  			Body:       ioutil.NopCloser(bytes.NewBufferString(msg)),
    31  			StatusCode: 200,
    32  		}
    33  		return &resp, nil
    34  	}
    35  
    36  	orderBook, err := NewClient().OrderBook.Get("btcusd", 0, 0, false)
    37  
    38  	if err != nil {
    39  		t.Error(err)
    40  	}
    41  
    42  	if len(orderBook.Bids) != 1 {
    43  		t.Error("Expected", 1)
    44  		t.Error("Actual ", len(orderBook.Bids))
    45  	}
    46  
    47  }