Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

/prices endpoint #58

Merged
merged 6 commits into from
Feb 12, 2020
Merged

/prices endpoint #58

merged 6 commits into from
Feb 12, 2020

Conversation

dekz
Copy link
Member

@dekz dekz commented Jan 8, 2020

Currently fetching prices of 1 unit of each token on with a base asset pair (defaults to WETH). I.e buying 1 USDC with WETH. We could make the unitAmount configurable by param.

In essence this is similar to performing a quote on every asset with the base asset. So in essence we use Native and Bridge orders. We do this in batches, as at writing this results in concurrent ~4 RPC requests. Currently this takes approximately 3.5-5 0.8 seconds to serve the result.

Note:

  • We're performing a buy operation (this excludes Kyber)
  • We do not perform multiple samples, just the entire amount
  • Base asset defaults to WETH though an alternative base can be supplied. E.g DAI or ZRX
  • Some batches are heavier than others due to the order of our Metadata, i.e one batch gets DAI,USDC,ZRX,WBTC and can take longer than a batch which has less native 0x orders.
{
  "records": [
    {
      "symbol": "ZRX",
      "price": "0.236163269460202302"
    },
    {
      "symbol": "WETH",
      "price": "173.60906274565"
    },
    {
      "symbol": "USDC",
      "price": "1.0014178"
    },
    {
      "symbol": "REP",
      "price": "14.960892941419549045"
    },
    {
      "symbol": "BAT",
      "price": "0.226468941872908147"
    },
    {
      "symbol": "MKR",
      "price": "511.244597947585170695"
    },
    {
      "symbol": "WBTC",
      "price": "9429.613550419299758978"
    },
    {
      "symbol": "SNX",
      "price": "1.206704957537004611"
    },
    {
      "symbol": "SUSD",
      "price": "0"
    },
    {
      "symbol": "KNC",
      "price": "0.292187720041790738"
    },
    {
      "symbol": "BNT",
      "price": "0.247097767988558581"
    },
    {
      "symbol": "GNO",
      "price": "13.262758986270229453"
    },
    {
      "symbol": "LINK",
      "price": "2.662818213761736781"
    },
    {
      "symbol": "REN",
      "price": "0.043421732202252796"
    },
    {
      "symbol": "OMG",
      "price": "0"
    },
    {
      "symbol": "ANT",
      "price": "0.652467493582113766"
    },
    {
      "symbol": "SAI",
      "price": "1.011433228749002679"
    },
    {
      "symbol": "CVL",
      "price": "0.004493489821836914"
    },
    {
      "symbol": "DTH",
      "price": "0.00237372494026652"
    },
    {
      "symbol": "FOAM",
      "price": "0.021644772854356194"
    },
    {
      "symbol": "AST",
      "price": "0.019088117413905174"
    },
    {
      "symbol": "GEN",
      "price": "0.139065317870529154"
    },
    {
      "symbol": "STORJ",
      "price": "0.114971244075358828"
    },
    {
      "symbol": "MANA",
      "price": "0.035897758799774541"
    },
    {
      "symbol": "ENTRP",
      "price": "0.698231373357677776"
    },
    {
      "symbol": "MLN",
      "price": "6.054717525181436224"
    },
    {
      "symbol": "LOOM",
      "price": "0.018287607933776055"
    },
    {
      "symbol": "CELR",
      "price": "0.003656190108206738"
    },
    {
      "symbol": "RLC",
      "price": "0.509953183050306052"
    },
    {
      "symbol": "DGD",
      "price": "31.586487605764545281"
    },
    {
      "symbol": "ZIL",
      "price": "0.010404865027214572"
    },
    {
      "symbol": "cBAT",
      "price": "0.005469334634742278"
    },
    {
      "symbol": "cSAI",
      "price": "0.020367839992946705"
    },
    {
      "symbol": "cSAI",
      "price": "0.021504356859570453"
    },
    {
      "symbol": "cETH",
      "price": "3.477011082422843025"
    },
    {
      "symbol": "cUSDC",
      "price": "0.021115501873979603"
    },
    {
      "symbol": "cZRX",
      "price": "0.004821894418576017"
    },
    {
      "symbol": "0xBTC",
      "price": "0.127406745124729286"
    },
    {
      "symbol": "SNT",
      "price": "0.011065190592788876"
    },
    {
      "symbol": "SPANK",
      "price": "0.003108800198118512"
    },
    {
      "symbol": "BOOTY",
      "price": "0.058353852162690072"
    },
    {
      "symbol": "BNB",
      "price": "6.574486616745281429"
    },
    {
      "symbol": "NMR",
      "price": "6.101405008792310903"
    },
    {
      "symbol": "GUSD",
      "price": "1.274566010501262615"
    },
    {
      "symbol": "FUN",
      "price": "0.003051938411077114"
    },
    {
      "symbol": "PAX",
      "price": "1.030249646987991769"
    },
    {
      "symbol": "TUSD",
      "price": "1.004938117938229358"
    },
    {
      "symbol": "LPT",
      "price": "2.525573245390085536"
    },
    {
      "symbol": "ENJ",
      "price": "0.090251282521339027"
    },
    {
      "symbol": "POWR",
      "price": "0.042595647573863637"
    },
    {
      "symbol": "REQ",
      "price": "0.013208264467134681"
    },
    {
      "symbol": "DNT",
      "price": "0.017624902664240927"
    },
    {
      "symbol": "MATIC",
      "price": "0.019577923256901625"
    },
    {
      "symbol": "LRC",
      "price": "0.025550301228465698"
    },
    {
      "symbol": "RDN",
      "price": "0.126877838427880865"
    },
    {
      "symbol": "USDT",
      "price": "0"
    }
  ]
}

Perf

Staging

λ hey -n 50 -c 1 'https://staging.api.0x.org/swap/v0/price'                                                                                                                     master

Summary:
  Total:	44.9667 secs
  Slowest:	1.9547 secs
  Fastest:	0.6047 secs
  Average:	0.8992 secs
  Requests/sec:	1.1119


Response time histogram:
  0.605 [1]	|■■
  0.740 [11]	|■■■■■■■■■■■■■■■■■■■■■
  0.875 [21]	|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  1.010 [7]	|■■■■■■■■■■■■■
  1.145 [2]	|■■■■
  1.280 [4]	|■■■■■■■■
  1.415 [1]	|■■
  1.550 [1]	|■■
  1.685 [1]	|■■
  1.820 [0]	|
  1.955 [1]	|■■

MY (slow) machine

Summary:
  Total:	451.8158 secs
  Slowest:	7.3228 secs
  Fastest:	2.0762 secs
  Average:	4.5181 secs
  Requests/sec:	0.2213

  Total data:	261000 bytes
  Size/request:	2610 bytes

Response time histogram:
  2.076 [1]	|■■
  2.601 [2]	|■■■
  3.126 [3]	|■■■■■
  3.650 [14]	|■■■■■■■■■■■■■■■■■■■■■■
  4.175 [21]	|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  4.700 [26]	|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  5.224 [11]	|■■■■■■■■■■■■■■■■■
  5.749 [7]	|■■■■■■■■■■■
  6.274 [7]	|■■■■■■■■■■■
  6.798 [4]	|■■■■■■
  7.323 [4]	|■■■■■■

@dekz dekz force-pushed the feature/prices-endpoint branch 3 times, most recently from aa57227 to ec38ac0 Compare January 14, 2020 00:40
@dekz dekz force-pushed the feature/prices-endpoint branch 2 times, most recently from 415118a to a7c03e8 Compare January 23, 2020 02:50
@dekz dekz marked this pull request as ready for review January 23, 2020 02:52
@dekz dekz force-pushed the feature/prices-endpoint branch 2 times, most recently from 3d89ef4 to a7b1509 Compare January 28, 2020 03:27
Copy link
Contributor

@fragosti fragosti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Can we not return a price if we don't know it (ie. not return price: 0).
  • My instinct was to query /prices. Thoughts on calling it that?

src/services/swap_service.ts Show resolved Hide resolved
src/services/swap_service.ts Outdated Show resolved Hide resolved
@dekz dekz force-pushed the feature/prices-endpoint branch from a7b1509 to ac7a628 Compare February 5, 2020 04:45
@dekz
Copy link
Member Author

dekz commented Feb 5, 2020

  • My instinct was to query /prices. Thoughts on calling it that?

SGTM, updated to /prices

@dekz dekz force-pushed the feature/prices-endpoint branch from ac7a628 to 2c6a92f Compare February 12, 2020 06:37
@dekz dekz changed the title /price endpoint /prices endpoint Feb 12, 2020
@dekz
Copy link
Member Author

dekz commented Feb 12, 2020

deploy staging

@dekz dekz merged commit 45cf9cf into master Feb 12, 2020
@dekz dekz deleted the feature/prices-endpoint branch February 12, 2020 07:02
@github-actions
Copy link

🎉 This PR is included in version 1.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants