github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v1/margin_info_test.go (about) 1 package bitfinex 2 3 import ( 4 "encoding/json" 5 "testing" 6 ) 7 8 func TestMarginInfo_Unmarshal(t *testing.T) { 9 // data from an actual Bitfinex's response 10 data := []byte(`[{"margin_balance":"3168.43615333","tradable_balance":"-4105.85460135","unrealized_pl":"-174.0072","unrealized_swap":"-3.77879387","net_value":"2990.65015946","required_margin":"1344.0","leverage":"2.5","margin_requirement":"13.0","margin_limits":[{"on_pair":"BTCUSD","initial_margin":"30.0","margin_requirement":"15.0","tradable_balance":"-2544.520981132333333333"},{"on_pair":"LTCUSD","initial_margin":"30.0","margin_requirement":"15.0","tradable_balance":"-2544.520981132333333333"},{"on_pair":"LTCBTC","initial_margin":"30.0","margin_requirement":"15.0","tradable_balance":"-1634.516821132333333333"}],"message":"Margin requirement, leverage and tradable balance are now per pair. Values displayed in the root of the JSON message are incorrect (deprecated). You will find the correct ones under margin_limits, for each pair. Please update your code as soon as possible."}]`) 11 12 var v []MarginInfo 13 err := json.Unmarshal(data, &v) 14 15 if err != nil { 16 t.Fatalf("Failed unmarshaling MarginInfo: %s", err.Error()) 17 } 18 }