Skip to content

Instantly share code, notes, and snippets.

@emilianobilli
Last active April 14, 2020 22:22
Show Gist options
  • Save emilianobilli/dae71162efa113f74ac8867721c2aacc to your computer and use it in GitHub Desktop.
Save emilianobilli/dae71162efa113f74ac8867721c2aacc to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"encoding/json"
"net/http"
"flag"
)
type Market struct {
MarketId int `json:marketId`
Wei string
}
type Balance struct {
B0 Market `json:"0"`
B1 Market `json:"1"`
B2 Market `json:"2"`
B3 Market `json:"3"`
}
type Account struct {
Owner string
Number string
Balances Balance
}
type DyDxAccount struct {
Owner string
Accounts []Account
}
const BaseUrl = "https://api.dydx.exchange/v1/accounts/"
var a *string = flag.String("a", "", "Account to get")
func getAccount(account string) (*DyDxAccount,error) {
response, err := http.Get(BaseUrl+account)
if err != nil {
return nil, err
}
if response.StatusCode != http.StatusOK {
response.Body.Close()
return nil, fmt.Errorf("Error: %s", response.Status)
}
var result DyDxAccount
if err := json.NewDecoder(response.Body).Decode(&result); err != nil {
response.Body.Close()
return nil, err
}
return &result, nil
}
func main() {
flag.Parse()
account, err := getAccount(*a)
if err == nil {
fmt.Println(account.Owner)
} else {
fmt.Println(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment