Skip to content

Commit

Permalink
[R4R]add limit param to get depth api for RPC (#73)
Browse files Browse the repository at this point in the history
* add limit param to get depth api for RPC

* update change log
  • Loading branch information
unclezoro authored Aug 7, 2019
1 parent eb7b0b0 commit 3f52c48
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# Changelog

## latest

FEATURES
* [\#71](https://github.com/binance-chain/go-sdk/pull/71) [RPC] add timelock query support
* [\#73](https://github.com/binance-chain/go-sdk/pull/73) [RPC] add limit param to get depth api for RPC


## v1.0.8
IMPROVEMENTS
* [\#53](https://github.com/binance-chain/go-sdk/pull/53) [SOURCE] change the default source into 0
* [\#56](https://github.com/binance-chain/go-sdk/pull/56) [RPC] add reconnect strategy when timeout to receive response
* [\#61](https://github.com/binance-chain/go-sdk/pull/61) [KEY] support bip44 to derive many address from same seed phase
* [\#71](https://github.com/binance-chain/go-sdk/pull/71) [RPC] add timelock query support

FEATURES

* [\#66](https://github.com/binance-chain/go-sdk/pull/66) [API] support set account flag transaction

BREAKING
Expand Down
9 changes: 6 additions & 3 deletions client/rpc/dex_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type DexClient interface {
GetFee() ([]types.FeeParam, error)
GetOpenOrders(addr types.AccAddress, pair string) ([]types.OpenOrder, error)
GetTradingPairs(offset int, limit int) ([]types.TradingPair, error)
GetDepth(tradePair string) (*types.OrderBook, error)
GetDepth(tradePair string, level int) (*types.OrderBook, error)
GetProposals(status types.ProposalStatus, numLatest int64) ([]types.Proposal, error)
GetProposal(proposalId int64) (types.Proposal, error)
GetTimelocks(address string) ([]types.TimeLockRecord, error)
Expand Down Expand Up @@ -227,11 +227,14 @@ func (c *HTTP) GetTradingPairs(offset int, limit int) ([]types.TradingPair, erro
return pairs, err
}

func (c *HTTP) GetDepth(tradePair string) (*types.OrderBook, error) {
func (c *HTTP) GetDepth(tradePair string, level int) (*types.OrderBook, error) {
if err := ValidatePair(tradePair); err != nil {
return nil, err
}
rawDepth, err := c.ABCIQuery(fmt.Sprintf("dex/orderbook/%s", tradePair), nil)
if err := ValidateDepthLevel(level); err != nil {
return nil, err
}
rawDepth, err := c.ABCIQuery(fmt.Sprintf("dex/orderbook/%s/%d", tradePair, level), nil)
if err != nil {
return nil, err
}
Expand Down
9 changes: 9 additions & 0 deletions client/rpc/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
maxABCIQueryStrLength = 1024
maxTxSearchStrLength = 1024
maxUnConfirmedTxs = 100
maxDepthLevel = 1000

tokenSymbolMaxLen = 14
tokenSymbolMinLen = 3
Expand All @@ -35,6 +36,7 @@ var (
OffsetNegativeError = fmt.Errorf("offset can't be less than 0")
SymbolLengthExceedRangeError = fmt.Errorf("length of symbol should be in range [%d,%d]", tokenSymbolMinLen, tokenSymbolMaxLen)
PairFormatError = fmt.Errorf("the pair should in format 'symbol1_symbol2'")
DepthLevelExceedRangeError = fmt.Errorf("the level is out of range [%d, %d]", 0, maxDepthLevel)
)

func ValidateABCIPath(path string) error {
Expand Down Expand Up @@ -139,3 +141,10 @@ func ValidatePair(pair string) error {
}
return nil
}

func ValidateDepthLevel(level int) error {
if level < 0 || level > maxDepthLevel {
return DepthLevelExceedRangeError
}
return nil
}
2 changes: 1 addition & 1 deletion e2e/e2e_rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func TestGetTradePair(t *testing.T) {

func TestGetDepth(t *testing.T) {
c := defaultClient()
depth, err := c.GetDepth(testTradePair)
depth, err := c.GetDepth(testTradePair, 2)
assert.NoError(t, err)
bz, err := json.Marshal(depth)
fmt.Println(string(bz))
Expand Down

0 comments on commit 3f52c48

Please sign in to comment.