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

     1  package bitfinex
     2  
     3  import (
     4  	"bytes"
     5  	"io/ioutil"
     6  	"net/http"
     7  	"testing"
     8  )
     9  
    10  func TestOfferNew(t *testing.T) {
    11  	httpDo = func(req *http.Request) (*http.Response, error) {
    12  		msg := `{
    13            "id":13800585,
    14            "currency":"USD",
    15            "rate":"20.0",
    16            "period":2,
    17            "direction":"lend",
    18            "timestamp":"1444279698.21175971",
    19            "is_live":true,
    20            "is_cancelled":true,
    21            "original_amount":"50.0",
    22            "remaining_amount":"50.0",
    23            "executed_amount":"0.0",
    24            "offer_id":13800585
    25          }`
    26  		resp := http.Response{
    27  			Body:       ioutil.NopCloser(bytes.NewBufferString(msg)),
    28  			StatusCode: 200,
    29  		}
    30  		return &resp, nil
    31  	}
    32  
    33  	offer, err := NewClient().Offers.New("USD", 50, 20.0, 2, LEND)
    34  
    35  	if err != nil {
    36  		t.Error(err)
    37  	}
    38  
    39  	if offer.Currency != "USD" {
    40  		t.Error("Expected", "USD")
    41  		t.Error("Actual ", offer.Currency)
    42  	}
    43  
    44  	expectedId := int64(13800585)
    45  	if offer.OfferId != expectedId {
    46  		t.Error("Expected", expectedId)
    47  		t.Error("Actual ", offer.OfferId)
    48  	}
    49  
    50  	if offer.Id != expectedId {
    51  		t.Error("Expected", expectedId)
    52  		t.Error("Actual ", offer.Id)
    53  	}
    54  	if !offer.IsLive {
    55  		t.Error("Expected", true)
    56  		t.Error("Actual ", offer.IsLive)
    57  	}
    58  
    59  	newOffer, err := NewClient().Offers.Cancel(offer.Id)
    60  
    61  	if err != nil {
    62  		t.Error(err)
    63  	}
    64  
    65  	if newOffer.Currency != "USD" {
    66  		t.Error("Expected", "USD")
    67  		t.Error("Actual ", newOffer.Currency)
    68  	}
    69  
    70  	if !newOffer.IsCancelled {
    71  		t.Error("Expected", true)
    72  		t.Error("Actual ", newOffer.IsCancelled)
    73  	}
    74  
    75  }