Skip to content

Commit

Permalink
Merge pull request #236 from kommitters/v0.10
Browse files Browse the repository at this point in the history
Release v0.10.2
  • Loading branch information
miguelnietoa authored Sep 21, 2022
2 parents 91df0f2 + 6326f69 commit 1d4cc55
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 44 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.10.2 (21.09.2022)
* Update assets parameters for Offers and Trades.

## 0.10.1 (21.09.2022)
* Fix bug by adding `CreateClaimableBalance` within allowed operations.

Expand Down
64 changes: 54 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The **Stellar SDK** is composed of two complementary components: **`TxBuild`** +
```elixir
def deps do
[
{:stellar_sdk, "~> 0.10.1"}
{:stellar_sdk, "~> 0.10.2"}
]
end
```
Expand Down Expand Up @@ -602,11 +602,41 @@ Stellar.Horizon.Offers.all(sponsor: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYU
# list offers by seller
Stellar.Horizon.Offers.all(seller: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD", order: :desc)

# list offers by selling_asset_issuer
Stellar.Horizon.Offers.all(selling_asset_issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD", limit: 20)
# list offers by selling_asset
Stellar.Horizon.Offers.all(
selling_asset: [
code: "TEST",
issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD"
]
)

# list offers by buying_asset
Stellar.Horizon.Offers.all(
buying_asset: [
code: "TEST",
issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD"
]
)

# list offers by selling_asset and buying_asset
Stellar.Horizon.Trades.all(
selling_asset: [
code: "TEST",
issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD"
],
buying_asset: [
code: "TOKEN",
issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD"
]
)

# list offers by buying_asset_type and buying_asset_code
Stellar.Horizon.Offers.all(buying_asset_type: "credit_alphanum4", buying_asset_code: "TEST")
Stellar.Horizon.Offers.all(
selling_asset: [
code: "TEST",
issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD"
],
buying_asset: :native
)

# list offer's trades
Stellar.Horizon.Offers.list_trades(165563085, limit: 20)
Expand All @@ -623,11 +653,25 @@ Stellar.Horizon.Trades.all(limit: 20, order: :asc)
# list trades by offer_id
Stellar.Horizon.Trades.all(offer_id: 165563085)

# list trades by base_asset_type and base_asset_code
Stellar.Horizon.Trades.all(base_asset_type: "credit_alphanum4", base_asset_code: "TEST")

# list trades by counter_asset_issuer
Stellar.Horizon.Trades.all(counter_asset_issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD", limit: 20)
# list trades by specific orderbook
Stellar.Horizon.Trades.all(
base_asset: [
code: "TEST",
issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD"
],
counter_asset: [
code: "TOKEN",
issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD"
]
)

Stellar.Horizon.Trades.all(
base_asset: [
code: "TEST",
issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD"
],
counter_asset: :native
)

# list trades by trade_type
Stellar.Horizon.Trades.all(trade_type: "liquidity_pools", limit: 20)
Expand Down
40 changes: 28 additions & 12 deletions lib/horizon/offers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Stellar.Horizon.Offers do
Horizon API reference: https://developers.stellar.org/api/resources/offers/
"""

alias Stellar.Horizon.{Collection, Error, Offer, Request, Trade}
alias Stellar.Horizon.{Collection, Error, Offer, Request, Trade, RequestParams}

@type offer_id :: String.t()
@type options :: Keyword.t()
Expand Down Expand Up @@ -45,12 +45,8 @@ defmodule Stellar.Horizon.Offers do
* `sponsor`: The account ID of the sponsor who is paying the reserves for all the offers included in the response.
* `seller`: The account ID of the offer creator.
* `selling_asset_type`: The type for the selling asset. Either `native`, `credit_alphanum4`, or `credit_alphanum12`.
* `selling_asset_issuer`: The account ID of the selling asset’s issuer.
* `selling_asset_code`: The code for the selling asset.
* `buying_asset_type`: The type for the buying asset. Either `native`, `credit_alphanum4`, or `credit_alphanum12`.
* `buying_asset_issuer`: The account ID of the buying asset’s issuer.
* `buying_asset_code`: The code for the buying asset.
* `selling_asset`: `:native` or `[code: "selling_asset_code", issuer: "selling_asset_issuer"]`.
* `buying_asset`: `:native` or `[code: "buying_asset_code", issuer: "buying_asset_issuer"]`.
* `cursor`: A number that points to a specific location in a collection of responses and is pulled from the `paging_token` value of a record.
* `order`: A designation of the order in which records should appear. Options include `asc` (ascending) or `desc` (descending).
* `limit`: The maximum number of records returned. The limit can range from 1 to 200. Defaults to 10.
Expand All @@ -68,19 +64,39 @@ defmodule Stellar.Horizon.Offers do
iex> Offers.all(seller: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD", order: :desc)
{:ok, %Collection{records: [%Offer{}, ...]}}
# list by selling_asset_issuer
iex> Offers.all(selling_asset_issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD", limit: 20)
# list by selling_asset
iex> Offers.all(
selling_asset: [
code: "TEST",
issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD"
],
limit: 20
)
{:ok, %Collection{records: [%Offer{}, ...]}}
# list by buying_asset_type and buying_asset_code
iex> Offers.all(buying_asset_type: "credit_alphanum4", buying_asset_code: "TEST")
# list by buying_asset
iex> Offers.all(
buying_asset: [
code: "TEST",
issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD"
],
limit: 20
)
{:ok, %Collection{records: [%Offer{}, ...]}}
"""
@spec all(options :: options()) :: response()
def all(options \\ []) do
selling_asset = RequestParams.build_assets_params(options, :selling_asset)
buying_asset = RequestParams.build_assets_params(options, :buying_asset)

params =
options
|> Keyword.merge(selling_asset)
|> Keyword.merge(buying_asset)

:get
|> Request.new(@endpoint)
|> Request.add_query(options, extra_params: allowed_query_options())
|> Request.add_query(params, extra_params: allowed_query_options())
|> Request.perform()
|> Request.results(collection: {Offer, &all/1})
end
Expand Down
4 changes: 2 additions & 2 deletions lib/horizon/order_books.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ defmodule Stellar.Horizon.OrderBooks do
Retrieve order books
## Parameters
* `selling_asset`: :native or [code: `selling_asset_code`, issuer: `selling_asset_issuer` ]
* `buying_asset`: :native or [code: `buying_asset_code`, issuer: `buying_asset_issuer` ]
* `selling_asset`: `:native` or `[code: "selling_asset_code", issuer: "selling_asset_issuer"]`
* `buying_asset`: `:native` or `[code: "buying_asset_code", issuer: "buying_asset_issuer"]`
## Options
* `limit`: The maximum number of records returned
Expand Down
6 changes: 3 additions & 3 deletions lib/horizon/payment_paths.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule Stellar.Horizon.PaymentPaths do
## Parameters
* `source_account`: The Stellar address of the sender.
* `destination_asset` :native or [code: `destination_asset_code`, issuer: `destination_asset_issuer`]
* `destination_asset`: `:native` or `[code: "destination_asset_code", issuer: "destination_asset_issuer"]`
* `destination_amount`: The amount of the destination asset that should be received.
## Options
Expand Down Expand Up @@ -82,7 +82,7 @@ defmodule Stellar.Horizon.PaymentPaths do
## Parameters
Using either `source_account` or `source_assets` as an argument is required for strict receive path payments.
* `destination_asset`: :native or [code: `destination_asset_code`, issuer: `destination_asset_issuer`]
* `destination_asset`: `:native` or `[code: "destination_asset_code", issuer: "destination_asset_issuer"]`
* `destination_amount`: The amount of the destination asset that should be received.
## Options
Expand Down Expand Up @@ -139,7 +139,7 @@ defmodule Stellar.Horizon.PaymentPaths do
## Parameters
Using either `destination_account` or `destination_assets` as an argument is required for strict send path payments.
* `source_asset`: :native or [code: `source_asset_code`, issuer: `source_asset_issuer`]
* `source_asset`: `:native` or `[code: "source_asset_code", issuer: "source_asset_issuer"]`
* `source_amount`: The amount of the source asset that should be sent.
## Options
Expand Down
4 changes: 2 additions & 2 deletions lib/horizon/trade_aggregations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ defmodule Stellar.Horizon.TradeAggregations do
## Parameters
* `base_asset`: :native or [code: `base_asset_code`, issuer: `base_asset_issuer`]
* `counter_asset`: :native or [code: `counter_asset_code`, issuer: `counter_asset_issuer`]
* `base_asset`: `:native` or `[code: "base_asset_code", issuer: "base_asset_issuer"]`
* `counter_asset`: `:native` or `[code: "counter_asset_code", issuer: "counter_asset_issuer"]`
* `resolution`: The segment duration represented as milliseconds.
## Options
Expand Down
35 changes: 21 additions & 14 deletions lib/horizon/trades.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Stellar.Horizon.Trades do
Horizon API reference: https://developers.stellar.org/api/resources/trades/
"""

alias Stellar.Horizon.{Collection, Error, Request, Trade}
alias Stellar.Horizon.{Collection, Error, Request, Trade, RequestParams}

@type options :: Keyword.t()
@type resource :: Trade.t() | Collection.t()
Expand All @@ -22,12 +22,8 @@ defmodule Stellar.Horizon.Trades do
## Options
* `offer_id`: The offer ID. Used to filter for trades originating from a specific offer.
* `base_asset_type`: The type for the base asset. Either `native`, `credit_alphanum4`, or `credit_alphanum12`.
* `base_asset_issuer`: The account ID of the base asset’s issuer.
* `base_asset_code`: The code for the base asset.
* `counter_asset_type`: The type for the counter asset. Either `native`, `credit_alphanum4`, or `credit_alphanum12`.
* `counter_asset_issuer`: The account ID of the counter asset’s issuer.
* `counter_asset_code`: The code for the counter asset.
* `base_asset`: `:native` or `[code: "base_asset_code", issuer: "base_asset_issuer"]`.
* `counter_asset`: `:native` or `[code: "counter_asset_code", issuer: "counter_asset_issuer"]`.
* `trade_type`: Can be set to `all`, `orderbook`, or `liquidity_pools` to filter only trades executed across a given mechanism.
* `cursor`: A number that points to a specific location in a collection of responses and is pulled from the `paging_token` value of a record.
* `order`: A designation of the order in which records should appear. Options include `asc` (ascending) or `desc` (descending).
Expand All @@ -42,12 +38,15 @@ defmodule Stellar.Horizon.Trades do
iex> Trades.all(offer_id: 165563085)
{:ok, %Collection{records: [%Trade{}, ...]}}
# list by base_asset_type and base_asset_code
iex> Trades.all(base_asset_type: "credit_alphanum4", base_asset_code: "TEST")
{:ok, %Collection{records: [%Trade{}, ...]}}
# list by counter_asset_issuer
iex> Trades.all(counter_asset_issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD", limit: 20)
# list by specific orderbook
iex> Trades.all(
base_asset: [
code: "TEST",
issuer: "GCXMWUAUF37IWOOV2FRDKWEX3O2IHLM2FYH4WPI4PYUKAIFQEUU5X3TD"
],
counter_asset: :native,
limit: 20
)
{:ok, %Collection{records: [%Trade{}, ...]}}
# list by trade_type
Expand All @@ -56,9 +55,17 @@ defmodule Stellar.Horizon.Trades do
"""
@spec all(options :: options()) :: response()
def all(options \\ []) do
base_asset = RequestParams.build_assets_params(options, :base_asset)
counter_asset = RequestParams.build_assets_params(options, :counter_asset)

params =
options
|> Keyword.merge(base_asset)
|> Keyword.merge(counter_asset)

:get
|> Request.new(@endpoint)
|> Request.add_query(options, extra_params: allowed_query_options())
|> Request.add_query(params, extra_params: allowed_query_options())
|> Request.perform()
|> Request.results(collection: {Trade, &all/1})
end
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Stellar.MixProject do
use Mix.Project

@github_url "https://github.com/kommitters/stellar_sdk"
@version "0.10.1"
@version "0.10.2"

def project do
[
Expand Down

0 comments on commit 1d4cc55

Please sign in to comment.