-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from lista-dao/main-bbtc
Add bbtc
- Loading branch information
Showing
7 changed files
with
95 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package v1 | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
httpcon "github.com/lista-dao/AuctionBots-go/pkg/httpconn" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
type Client struct { | ||
cn *httpcon.Connector | ||
log *logrus.Logger | ||
} | ||
|
||
func NewClient( | ||
base *url.URL, | ||
log *logrus.Logger, | ||
) *Client { | ||
cli := &Client{ | ||
cn: httpcon.NewConnector(base, nil), | ||
log: log, | ||
} | ||
cli.log.Debug("V3 New Client ", base.Host) | ||
return cli | ||
} | ||
|
||
func (cli *Client) GetRedUsers(ctx context.Context) ([]User, error) { | ||
cli.log.Debug("V3 GetRedUsers Starting...") | ||
code, body, err := cli.cn.Get(ctx, "/api/v2/liquidations/red", nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if *code == http.StatusOK { | ||
var resp CommonDataResp | ||
|
||
if err := json.Unmarshal(body, &resp); err != nil { | ||
return nil, errors.Wrapf(err, "failed to unmarshal body %s", string(body)) | ||
} | ||
|
||
return resp.Data.Users, nil | ||
} | ||
|
||
return nil, errors.New(fmt.Sprintf("failed with %s", http.StatusText(*code))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package v1 | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/shopspring/decimal" | ||
) | ||
|
||
type LiquidationUsersResp struct { | ||
Users []User `json:"users"` | ||
} | ||
|
||
type CommonDataResp struct { | ||
Code string `json:"code"` | ||
Msg string `json:"msg"` | ||
Data struct { | ||
Users []User `json:"users"` | ||
} `json:"data"` | ||
Timestamp int64 `json:"timestamp"` | ||
} | ||
|
||
type User struct { | ||
UserAddress common.Address `json:"userAddress"` | ||
TokenName string `json:"tokenName"` | ||
Collateral decimal.Decimal `json:"collateral"` | ||
//LiquidationCost decimal.Decimal `json:"liquidationCost"` | ||
//RangeFromLiquidation decimal.Decimal `json:"rangeFromLiquidation"` | ||
//LiquidationPrice decimal.Decimal `json:"liquidationPrice"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters