github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v1/pairs_test.go (about) 1 package bitfinex 2 3 import ( 4 "bytes" 5 "io/ioutil" 6 "net/http" 7 "testing" 8 ) 9 10 func TestPairsGetAll(t *testing.T) { 11 httpDo = func(req *http.Request) (*http.Response, error) { 12 msg := `["btcusd","ltcusd","ltcbtc","ethusd","ethbtc"]` 13 resp := http.Response{ 14 Body: ioutil.NopCloser(bytes.NewBufferString(msg)), 15 StatusCode: 200, 16 } 17 return &resp, nil 18 } 19 20 pairs, err := NewClient().Pairs.All() 21 22 numPairs := len(pairs) 23 24 if err != nil { 25 t.Error(err) 26 } 27 28 if numPairs != 5 { 29 t.Error("Expected", 5) 30 t.Error("Actual ", numPairs) 31 } 32 33 if (pairs)[0] != "btcusd" { 34 t.Error("Expected", "btcusd") 35 t.Error("Actual ", pairs[0]) 36 } 37 } 38 39 func TestPairsAllDetailed(t *testing.T) { 40 httpDo = func(req *http.Request) (*http.Response, error) { 41 msg := `[{ 42 "pair":"btcusd", 43 "price_precision":5, 44 "initial_margin":"30.0", 45 "minimum_margin":"15.0", 46 "maximum_order_size":"2000.0", 47 "minimum_order_size":"0.01", 48 "expiration":"NA", 49 "margin":true 50 },{ 51 "pair":"ltcusd", 52 "price_precision":5, 53 "initial_margin":"30.0", 54 "minimum_margin":"15.0", 55 "maximum_order_size":"5000.0", 56 "minimum_order_size":"0.1", 57 "expiration":"NA", 58 "margin":false 59 }]` 60 resp := http.Response{ 61 Body: ioutil.NopCloser(bytes.NewBufferString(msg)), 62 StatusCode: 200, 63 } 64 return &resp, nil 65 } 66 67 pairs, err := NewClient().Pairs.AllDetailed() 68 69 if err != nil { 70 t.Error(err) 71 } 72 73 if len(pairs) != 2 { 74 t.Error("Expected", 2) 75 t.Error("Actual", len(pairs)) 76 } 77 78 pairMargin := pairs[0].InitialMargin 79 expectedMargin := 30.0 80 if (pairMargin-expectedMargin) > 0.1 || (expectedMargin-pairMargin) > 0.1 { 81 t.Error("Expected", expectedMargin) 82 t.Error("Actual", pairMargin) 83 } 84 85 if pairs[0].Pair != "btcusd" { 86 t.Error("Expected", "btcusd") 87 t.Error("Actual", pairs[0].Pair) 88 } 89 90 if pairs[0].Expiration != "NA" { 91 t.Error("Expected", "NA") 92 t.Error("Actual", pairs[0].Expiration) 93 } 94 95 if !pairs[0].Margin { 96 t.Error("Expected", true) 97 t.Error("Actual", pairs[0].Margin) 98 } 99 }