perich / ethereum-dex-prices-service Goto Github PK
View Code? Open in Web Editor NEWAn API wrapper that fetches prices from the most popular Ethereum decentralized exchanges
License: MIT License
An API wrapper that fetches prices from the most popular Ethereum decentralized exchanges
License: MIT License
Currently, all of the DEX classes return a result
object to every query. It matches the following structure:
result = {
exchangeName: String,
totalPrice: Number | null,
tokenAmount: Number
tokenSymbol: String,
avgPrice: Number | null,
timestamp: Number,
error: String | null,
}
This structure doesn't always tell the full story when it comes to price and expectations. For example, the prices reported by the Bancor API are subject to slippage. That slippage isn't reflected at all anywhere in the library. While a user won't experience slippage every time they execute a trade, they should certainly be aware of the possibility. To handle these kinds of non-deterministic details, I am proposing a "metadata" field be added to the result
object. This is where we can store useful details about each DEX to help users and developers make more informed decisions when analyzing price data generated from this library.
While skimming through the available 0x relayers to get a better idea of what exchanges may be possible to be supported, I noticed that the 0x schema for order books actually returns asks and bids in terms of the maker and taker address, not by the resolved symbol. Example:
https://github.com/0xProject/standard-relayer-api/blob/master/http/v2.md#get-v2orderbook
Are there plans to support exchanges that use the 0x SRA? This would require the ability to pass in a contract address as an alternative to a symbol. On a similar note, it raises the question of asset resolution. For example, if a user passes ABC
, there currently aren't any checks to ensure that ABC
actually corresponds to the same assets. Given the goal of supporting any asset on any exchange, I see a couple paths off the top of my head:
1a) For major exchanges, keep a hard-coded mapping of symbol -> contract address if it's easily identifiable (ZRX, AST, BNB, etc.)
1b) Only support exchanges that provide tokens included in the "supported assets" mapping
2) Only support exchanges that allow retrieval of order books with contract addresses
And the potential issues:
1a) This obviously has a scaling problem and also brings up issues if contracts are redeployed
1b) This limits the amount of exchanges and assets available unless they're manually maintained in 1a
2) This allows for more flexibility in the sense that I could provide any address and if it shows up in an exchange we know that it's the same asset across exchanges but it limits consumers to knowing the address for the token contract, which they may not. Similar to 1b, this limits the amount of exchanges that could be supported.
Just some things that crossed my mind while looking around. Interested to get some feedback. :)
The Ocean is a 0x relayer. Their API allows for retrieval of orderbook info behind unauthenticated, rate-limited endpoints: https://docs.theocean.trade/#rate-limit
A client is also provided if you want some wrapper functions for interacting with the API:
https://docs.theocean.trade/#order-book-3
Based on some of the other examples, I think these are the two endpoints that will be useful:
Frequently crashes after running for several hour with this error:
Error: WebSocket is not open: readyState 2 (CLOSING)
at WebSocket.ping (/home/jake/ethereum-dex-prices-service/node_modules/ws/lib/websocket.js:257:19)
at Timeout.interval.setInterval [as _onTimeout] (/home/jake/ethereum-dex-prices-service/exchanges/AirSwap.js:182:18)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
EthFinex has a trustless API that could easily be implemented in this library https://trustless.ethfinex.com
Requirements:
OrderBookExchange
class and implements the EthFinex API correctlymain()
routineTo ensure the library is functioning properly, unit tests should be included for Uniswap. Since this exchange uses the token metadata provided as part of the library as well as the ethers
library, we should think about creating a mock module for ethers
as there would be some reusability across the Airswap and Bancor tests as well. Consideration should be given to available test tools related to the ethers
library if any exist.
This one looks like it will be a bit more challenging since there is no HTTP API available. The docs are here for anyone who wants to give it a shot: https://docs.uniswap.io/
@conlan on Twitter is working on an HTTP API that will make it much easier.
Until then you can pull all the NewExchange events from the factory:
0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95
Or use getExchange() functions on the factory:
https://docs.uniswap.io/frontend-integration/connect-to-uniswap
or
https://github.com/Uniswap/uniswap-info/blob/master/src/constants/Uniswap.js#L4
API docs: https://github.com/forkdelta/backend-replacement/tree/master/docs/api
Requirements:
OrderBookExchange
class_createCanonicalOrderBook
order book method and return an order book matching the canonical order book schema// canonical order book example
const exampleBook = {
asks: [
{ amount: '100', price: '0.005', lotAmount: '100', lotPrice: '0.5' },
{ amount: '200', price: '0.006', lotAmount: '300', lotPrice: '1.7' },
{ amount: '300', price: '0.007', lotAmount: '600', lotPrice: '3.8' },
],
bids: [
{ amount: '100', price: '0.004', lotAmount: '100', lotPrice: '0.4' },
{ amount: '200', price: '0.003', lotAmount: '300', lotPrice: '1.0' },
{ amount: '300', price: '0.002', lotAmount: '600', lotPrice: '1.6' },
],
}
Just a small bug that is probably resolved in next release.
After following the instructions form the Quickstart, the cli.js command fails.
yarn search buy 500 ETH
The issue is coming from the import in cli.js.
const { main } = require('../main')
As there is no main file, replacing with below fixed the issue.
const { main } = require('../index')
Eth2Dai now changed on Oasis.
New address: 0x8018280076d7fA2cAa1147e441352E8a89e1DDbe
I'm thinking it would be valuable to have unit tests per exchange and possibly integration tests to assert some of the calculation logic / catch an API non-passively changing? Thoughts?
The Ethfinex class is no longer returning price data when queried. It seems that some changes may have been made to the underlying API in the last 6-9 months. They have also rebranded to https://deversifi.com
To do:
Hi there!,
@grahamperich my name is Elio and I am the admin of inDEX (https://github.com/distribuyed/index). inDEX is a comprehensive list of decentralized exchanges of cryptocurrencies, tokens, derivatives and futures, their protocols, and other resources.
I do not have the time neither skills to collaborate as much as I would like with your project, but if it is helpful, I can help you by indicating DEXes with API that you can use for your project.
For example, the last I found:
DEX | URL | API |
---|---|---|
TOKENMON | https://tokenmom.com | https://docs.tokenmom.com/#introduction |
Thanks a lot in advance and congratulations for the project!
Getting this since this morning:
UnhandledPromiseRejectionWarning: Could not connect to socket
When running
node entrypoints/cli.js buy 1 MKR
Worked fine yesterday.
It appears that the Radar Relay class doesn't return any price info. This may be a consequence of breaking API changes as part of the upgrade to 0x v3.
Latest API docs here, for investigation and refactoring:
Eth2Dai has been permanently migrated to Oasis https://oasis.app/trade
Changes needed in the service:
Change the eth2dai class name to Oasis
Remove the guard that limits queries to only ETH/DAI. Oasis has removed this restriction and allows many markets besides just DAI
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.