diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..3827ff5d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,33 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**Version** +vX.X.X + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Run '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. Linux, Windows] + - Version [e.g. 10] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..11fc491e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..65cc7310 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,22 @@ + + + + +## Implementation details +- Do 1 +- Do 2 + +## Please ensure the following requirements are met before submitting a pull request: + +- [ ] The pull request is targeted against the correct target branch +- [ ] The pull request is linked to an issue with appropriate discussion and an accepted design OR is linked to a spec that describes the work. +- [ ] The pull request includes a description of the implementation/work done in detail. +- [ ] The pull request includes any appropriate unit/integration tests +- [ ] You have added a relevant changelog entry to `CHANGELOG.md` +- [ ] You have re-reviewed the files affected by the pull request (e.g. using the `Files changed` tab in the GitHub PR explorer) diff --git a/.gitignore b/.gitignore index ea8c4bf7..68afbcf2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,18 @@ -/target +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + + +.vscode/ + \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..b97cdf04 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,23 @@ +# Contributing + +Thank you for your interest in contributing! You can contribute to `band-price-adapter` in many ways. + +1. **Issues** + + If you find any bug/issues with the `band-price-adapter` from any perspective (document/function/usage), you can always open the [issue](https://github.com/bandprotocol/band-price-adapter/issues/new/choose) in GitHub to tell us. + +2. **Discussion** + + If you have any idea on how to improve and want to discuss your idea with our community. We also open [a discussion board](https://github.com/bandprotocol/band-price-adapter/discussions) for it. + +3. **Pull requests** + + In case, you want to add more features that you think will improve developer experiences. You can open the [pull request](https://github.com/bandprotocol/band-price-adapter/pulls) to our main branch. + +4. **Forking** + + We also welcome you to fork our repository to either do a pull request or create your version. + +5. **Star** + + If you like or use our work, you can also give a star to our repository. diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 6cae992b..00000000 --- a/Cargo.lock +++ /dev/null @@ -1,1517 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "backtrace" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "base64" -version = "0.21.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bumpalo" -version = "3.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - -[[package]] -name = "cc" -version = "1.0.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f8e7c90afad890484a21653d08b6e209ae34770fb5ee298f9c699fcc1e5c856" -dependencies = [ - "libc", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "chrono" -version = "0.4.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" -dependencies = [ - "android-tzdata", - "iana-time-zone", - "js-sys", - "num-traits", - "wasm-bindgen", - "windows-targets", -] - -[[package]] -name = "core-foundation" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" - -[[package]] -name = "cpufeatures" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "data-encoding" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "either" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" - -[[package]] -name = "encoding_rs" -version = "0.8.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "errno" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c18ee0ed65a5f1f81cac6b1d213b69c35fa47d4252ad41f1486dbd8226fe36e" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "fastrand" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures-channel" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" -dependencies = [ - "futures-core", -] - -[[package]] -name = "futures-core" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" - -[[package]] -name = "futures-macro" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" - -[[package]] -name = "futures-task" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" - -[[package]] -name = "futures-util" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" -dependencies = [ - "futures-core", - "futures-macro", - "futures-sink", - "futures-task", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "gimli" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" - -[[package]] -name = "h2" -version = "0.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "hermit-abi" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" - -[[package]] -name = "http" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" -dependencies = [ - "bytes", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" - -[[package]] -name = "httpdate" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" - -[[package]] -name = "hyper" -version = "0.14.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2 0.4.10", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper", - "native-tls", - "tokio", - "tokio-native-tls", -] - -[[package]] -name = "iana-time-zone" -version = "0.1.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - -[[package]] -name = "idna" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] -name = "ipnet" -version = "2.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" - -[[package]] -name = "itertools" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "js-sys" -version = "0.3.65" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.150" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" - -[[package]] -name = "linux-raw-sys" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" - -[[package]] -name = "lock_api" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - -[[package]] -name = "miniz_oxide" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" -dependencies = [ - "libc", - "wasi", - "windows-sys", -] - -[[package]] -name = "native-tls" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - -[[package]] -name = "nu-ansi-term" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" -dependencies = [ - "overload", - "winapi", -] - -[[package]] -name = "num-traits" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "openssl" -version = "0.10.59" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a257ad03cd8fb16ad4172fedf8094451e1af1c4b70097636ef2eac9a5f0cc33" -dependencies = [ - "bitflags 2.4.1", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.95" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40a4130519a360279579c2053038317e40eff64d13fd3f004f9e1b72b8a6aaf9" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "pkg-config" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] -name = "price-adapter-raw" -version = "0.1.0" -dependencies = [ - "chrono", - "futures-util", - "itertools", - "rand", - "reqwest", - "serde", - "serde_json", - "thiserror", - "tokio", - "tokio-tungstenite", - "tokio-util", - "tracing", - "tracing-subscriber", -] - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "reqwest" -version = "0.11.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" -dependencies = [ - "base64", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-tls", - "ipnet", - "js-sys", - "log", - "mime", - "native-tls", - "once_cell", - "percent-encoding", - "pin-project-lite", - "serde", - "serde_json", - "serde_urlencoded", - "system-configuration", - "tokio", - "tokio-native-tls", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - -[[package]] -name = "rustix" -version = "0.38.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80109a168d9bc0c7f483083244543a6eb0dba02295d33ca268145e6190d6df0c" -dependencies = [ - "bitflags 2.4.1", - "errno", - "libc", - "linux-raw-sys", - "windows-sys", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "schannel" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "security-framework" -version = "2.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "serde" -version = "1.0.192" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.192" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.108" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sha1" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" - -[[package]] -name = "socket2" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "socket2" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "syn" -version = "2.0.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "system-configuration" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "tempfile" -version = "3.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" -dependencies = [ - "cfg-if", - "fastrand", - "redox_syscall", - "rustix", - "windows-sys", -] - -[[package]] -name = "thiserror" -version = "1.0.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "thread_local" -version = "1.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" -dependencies = [ - "cfg-if", - "once_cell", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "tokio" -version = "1.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2 0.5.5", - "tokio-macros", - "windows-sys", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] -name = "tokio-tungstenite" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" -dependencies = [ - "futures-util", - "log", - "native-tls", - "tokio", - "tokio-native-tls", - "tungstenite", -] - -[[package]] -name = "tokio-util" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", - "tracing", -] - -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - -[[package]] -name = "tracing" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" -dependencies = [ - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -dependencies = [ - "once_cell", - "valuable", -] - -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" -dependencies = [ - "nu-ansi-term", - "sharded-slab", - "smallvec", - "thread_local", - "tracing-core", - "tracing-log", -] - -[[package]] -name = "try-lock" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" - -[[package]] -name = "tungstenite" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" -dependencies = [ - "byteorder", - "bytes", - "data-encoding", - "http", - "httparse", - "log", - "native-tls", - "rand", - "sha1", - "thiserror", - "url", - "utf-8", -] - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "unicode-bidi" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-normalization" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "url" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wasm-bindgen" -version = "0.2.88" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.88" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.88" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.88" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.88" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" - -[[package]] -name = "web-sys" -version = "0.3.65" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-core" -version = "0.51.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "winreg" -version = "0.50.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" -dependencies = [ - "cfg-if", - "windows-sys", -] diff --git a/Cargo.toml b/Cargo.toml index d7102caa..e5b98cd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,2 @@ [workspace] -members = ["price-adapter-raw"] +members = ["price-adapter-raw", "price-adapter"] diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 00000000..1b5ec8b7 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 00000000..9cf10627 --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,19 @@ +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 0a1d7234..0fac8e0b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,25 @@ -# Band-Price-Adapter +# Band Price Adapter +`band-price-adapter` is a Rust library designed to facilitate the retrieval of price information for various cryptocurrencies and assets from diverse sources. -TBD. +## Packages +This project comprises two distinct packages: + +### price-adapter +This package offers unified interfaces for seamless interaction with various sources. It includes utility functions that enhance the ease of integration into user applications. + +For more details about this package, refer to the documentation [here](./price-adapter/README.md), and the changelog is accessible [here](./price-adapter/CHANGELOG.md). + +### price-adapter-raw +This package serves as a wrapper for each data source, enabling direct querying of prices from the respective sources. + +For more details about this package, refer to the documentation [here](./price-adapter-raw/README.md), and the changelog is accessible [here](./price-adapter-raw/CHANGELOG.md). + +## Contributing +We welcome contributions from the community! Before submitting a pull request, please review our [contributing guidelines](CONTRIBUTING.md). + +## License + +Licensed under either of + +- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://apache.org/licenses/LICENSE-2.0) +- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) diff --git a/price-adapter-raw/CHANGELOG.md b/price-adapter-raw/CHANGELOG.md new file mode 100644 index 00000000..4101e4ab --- /dev/null +++ b/price-adapter-raw/CHANGELOG.md @@ -0,0 +1,6 @@ +# CHANGELOG + +## Unreleased + +- Support CoinGecko sources +- Support Binance Websocket source diff --git a/price-adapter-raw/README.md b/price-adapter-raw/README.md new file mode 100644 index 00000000..4779afe0 --- /dev/null +++ b/price-adapter-raw/README.md @@ -0,0 +1,69 @@ +# price-adapter-raw + +`price-adapter-raw` is a price query adapter for crypto exchanges and price aggregators. + +Currently, it supports the following exchanges and price aggregators: + +- Binance +- CoinGecko + +## Usage + +### Coingecko + +To use coingecko API, you need to create a `CoingeckoPro` instance and set the api key. + +```rust +use price_adapter_raw::CoinGecko; + +#[tokio::main] +async fn main() { + let coingecko = CoinGecko::new_with_api_key("$API_KEY".into()); + let queries = vec!["ethereum"]; + let prices = coingecko.get_prices(&queries).await; + println!("prices: {:?}", prices); +} +``` + +### Binance Websocket + +To use binance websocket API, you need to create a `BinanceWebsocket` instance and set the query symbols. + +```rust +use price_adapter_raw::BinanceWebsocket; +use futures_util::StreamExt; + +#[tokio::main] +async fn main() { + let mut binance_ws = BinanceWebsocket::new("wss://stream.binance.com:9443"); + binance_ws.connect().await.unwrap(); + binance_ws.subscribe(&["ethbtc", "btcusdt"]).await; + let data = binance_ws.next().await.unwrap(); + match data { + Ok(price) => { + println!("price: {:?}", price); + } + Err(e) => { + eprintln!("Error: {}", e); + } + } +} +``` + +Or use `BinanceWebsocketService` to query price data. + +```rust +use price_adapter_raw::{BinanceWebsocket, BinanceWebsocketService}; +use std::time::Duration; + +#[tokio::main] +async fn main() { + let mut binance_ws = BinanceWebsocket::new("wss://stream.binance.com:9443"); + let mut service = BinanceWebsocketService::new(binance_ws); + service.start(&["ethbtc", "btcusdt"]).await.unwrap(); + tokio::time::sleep(Duration::from_secs(1)).await; + + let price = service.get_prices(&["btcusdt"]).await; + println!("price: {:?}", price); +} +``` diff --git a/price-adapter-raw/src/binance_websocket/websocket.rs b/price-adapter-raw/src/binance_websocket/websocket.rs index 38206b04..1b48d983 100644 --- a/price-adapter-raw/src/binance_websocket/websocket.rs +++ b/price-adapter-raw/src/binance_websocket/websocket.rs @@ -143,7 +143,7 @@ impl Stream for BinanceWebsocket { match socket.poll_next_unpin(cx) { Poll::Ready(Some(message)) => match message { Ok(Message::Text(text)) => { - tracing::info!("received text message: {}", text); + tracing::trace!("received text message: {}", text); match parse_message(text) { Ok(info) => Poll::Ready(Some(Ok(info))), Err(err) => { diff --git a/price-adapter-raw/src/lib.rs b/price-adapter-raw/src/lib.rs index 6e7ff191..0d2c6d6f 100644 --- a/price-adapter-raw/src/lib.rs +++ b/price-adapter-raw/src/lib.rs @@ -1,8 +1,7 @@ -//! # price-explorer -//! price-explorer is a price query adapter for crypto exchanges and price aggregators. +//! # price-adapter-raw +//! price-adapter-raw is a price query adapter for crypto exchanges and price aggregators. //! -//! It provides a unified interface for querying price data from different exchanges and -//! price aggregators. Currently, it supports the following exchanges and price aggregators: +//! Currently, it supports the following exchanges and price aggregators: //! - Binance //! - CoinGecko diff --git a/price-adapter/CHANGELOG.md b/price-adapter/CHANGELOG.md new file mode 100644 index 00000000..1332a7b3 --- /dev/null +++ b/price-adapter/CHANGELOG.md @@ -0,0 +1,7 @@ +# CHANGELOG + +## Unreleased + +- Support CoinGecko sources +- Support Binance Websocket source +- Create Interval and Websocket service to manage sources diff --git a/price-adapter/Cargo.toml b/price-adapter/Cargo.toml new file mode 100644 index 00000000..39214a1d --- /dev/null +++ b/price-adapter/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "price-adapter" +description = "price-adapter" +version = "0.1.8" +edition = "2021" +license = "MIT OR Apache-2.0" + +[dependencies] +price-adapter-raw = { version = "0.1.0", path = "../price-adapter-raw" } +thiserror = "1.0.50" +tokio = { version = "1.0", features = ["full"] } +serde = { version = "1.0.192", features = ["serde_derive"] } +serde_json = "1.0.108" +tokio-tungstenite = { version = "0.20.1", features = ["native-tls"] } +futures-util = "0.3.29" +tokio-util = "0.7.10" +async-trait = "0.1.74" +tracing = "0.1.40" +tracing-subscriber = "0.3.18" diff --git a/price-adapter/README.md b/price-adapter/README.md new file mode 100644 index 00000000..92f95cae --- /dev/null +++ b/price-adapter/README.md @@ -0,0 +1,36 @@ +# price-adapter + +`price-adapter` is a Rust library that provides different services for fetching price information for various cryptocurrencies and assets. It includes sources for popular data providers such as CoinGecko and Binance, and offers both HTTP-based and WebSocket-based interfaces for retrieving prices. + +## Features + +* **Multiple data sources:** `price-adapter` supports multiple sources for obtaining cryptocurrency prices, including: + * CoinGecko + * Binance + * BandStableCoin +* **HTTP and WebSocket interfaces:** You can fetch prices either through HTTP requests or WebSocket connections, depending on your application's requirements. +* **Caching and interval-based updating:** The library features caching and interval-based updating of prices to optimize performance and reduce API calls. +* **Extensibility:** It's easy to add new data sources or implement custom mapping rules to adapt the library to your specific needs. + +## Getting Started + +To use `price-adapter`, add the following to your Cargo.toml file: + +```toml +[dependencies] +price-adapter = "0.1.0" +``` + +## Services + +`price-adapter` offers two types of services: + +1. **IntervalService:** This service fetches prices from a specified source at regular intervals and caches them. This is a convenient option if you need to access prices frequently and don't want to make API calls every time. + +2. **WebsocketService:** This service establishes a WebSocket connection to a source and subscribes to specific symbols. It then streams price updates over the WebSocket connection, allowing you to receive real-time price changes. + +Both services implement the `Service` trait, which defines the common interface for starting, stopping, and checking the status of the service. + +## Examples + +The `examples` directory contains several example scripts demonstrating how to use `price-adapter`. These examples cover scenarios such as using the HTTP and WebSocket interfaces, creating a custom mapper, and employing the interval and Websocket services. diff --git a/price-adapter/examples/binance-websocket-service.rs b/price-adapter/examples/binance-websocket-service.rs new file mode 100644 index 00000000..43400ffb --- /dev/null +++ b/price-adapter/examples/binance-websocket-service.rs @@ -0,0 +1,17 @@ +use price_adapter::services::WebsocketService; +use price_adapter::sources::BinanceWebsocket; +use price_adapter::types::{Service, Source}; +use std::time::Duration; + +#[tokio::main] +async fn main() { + tracing_subscriber::fmt::init(); + let binance_websocket = BinanceWebsocket::new_with_default().unwrap(); + let mut service = WebsocketService::new(binance_websocket); + service.start(vec!["BTC"].as_slice()).await.unwrap(); + + loop { + tokio::time::sleep(Duration::from_secs(1)).await; + println!("{:?}", service.get_prices(&["BTC"]).await); + } +} diff --git a/price-adapter/examples/binance-websocket.rs b/price-adapter/examples/binance-websocket.rs new file mode 100644 index 00000000..0bba4632 --- /dev/null +++ b/price-adapter/examples/binance-websocket.rs @@ -0,0 +1,20 @@ +use futures_util::StreamExt; +use price_adapter::sources::BinanceWebsocket; +use price_adapter::types::WebSocketSource; + +#[tokio::main] +async fn main() { + tracing_subscriber::fmt::init(); + let mut binance_websocket = BinanceWebsocket::new_with_default().unwrap(); + let symbols = vec!["ETH", "BTC"]; + + binance_websocket.connect().await.unwrap(); + binance_websocket + .subscribe(symbols.as_slice()) + .await + .unwrap(); + + while let Some(data) = binance_websocket.next().await { + println!("{:?}", data); + } +} diff --git a/price-adapter/examples/coingecko-basic.rs b/price-adapter/examples/coingecko-basic.rs new file mode 100644 index 00000000..6018ebf1 --- /dev/null +++ b/price-adapter/examples/coingecko-basic.rs @@ -0,0 +1,11 @@ +use price_adapter::sources::CoinGecko; +use price_adapter::types::Source; + +#[tokio::main] +async fn main() { + tracing_subscriber::fmt::init(); + let coingecko = CoinGecko::new_with_default(None).unwrap(); + let queries = vec!["ETH", "BAND"]; + let prices = coingecko.get_prices(&queries).await; + println!("prices: {:?}", prices); +} diff --git a/price-adapter/examples/coingecko-interval-service.rs b/price-adapter/examples/coingecko-interval-service.rs new file mode 100644 index 00000000..37b7ea67 --- /dev/null +++ b/price-adapter/examples/coingecko-interval-service.rs @@ -0,0 +1,17 @@ +use price_adapter::services::IntervalService; +use price_adapter::sources::CoinGecko; +use price_adapter::types::{Service, Source}; +use std::time::Duration; + +#[tokio::main] +async fn main() { + tracing_subscriber::fmt::init(); + let coingecko = CoinGecko::new_with_default(None).unwrap(); + let mut service = IntervalService::new(coingecko, Duration::from_secs(20)); + service.start(vec!["BTC"].as_slice()).await.unwrap(); + + loop { + tokio::time::sleep(Duration::from_secs(1)).await; + println!("{:?}", service.get_prices(&["BTC"]).await); + } +} diff --git a/price-adapter/resources/binance.json b/price-adapter/resources/binance.json new file mode 100644 index 00000000..ba9607bb --- /dev/null +++ b/price-adapter/resources/binance.json @@ -0,0 +1,133 @@ +{ + "1INCH": "1inchusdt", + "AAVE": "aaveusdt", + "ADA": "adausdt", + "ALGO": "algousdt", + "ALPHA": "alphausdt", + "ANKR": "ankrusdt", + "ANT": "antusdt", + "APE": "apeusdt", + "ARB": "arbusdt", + "ARPA": "arpausdt", + "ASTR": "astrusdt", + "ATOM": "atomusdt", + "AUTO": "autousdt", + "AVAX": "avaxusdt", + "AXS": "axsusdt", + "BAL": "balusdt", + "BAND": "bandusdt", + "BAT": "batusdt", + "BCH": "bchusdt", + "BEL": "belusdt", + "BETA": "betausdt", + "BLZ": "blzusdt", + "BNB": "bnbusdt", + "BNT": "bntusdt", + "BTC": "btcusdt", + "BTT": "bttcusdt", + "BUSD": "busdusdt", + "C98": "c98usdt", + "CAKE": "cakeusdt", + "CELO": "celousdt", + "CLV": "clvusdt", + "COMP": "compusdt", + "CRV": "crvusdt", + "CVC": "cvcusdt", + "DASH": "dashusdt", + "DCR": "dcrusdt", + "DOGE": "dogeusdt", + "DOT": "dotusdt", + "DYDX": "dydxusdt", + "EGLD": "egldusdt", + "ENJ": "enjusdt", + "EOS": "eosusdt", + "ETC": "etcusdt", + "ETH": "ethusdt", + "FET": "fetusdt", + "FIL": "filusdt", + "FLOW": "flowusdt", + "FTM": "ftmusdt", + "GLMR": "glmrusdt", + "GMX": "gmxusdt", + "GRT": "grtusdt", + "HBAR": "hbarusdt", + "ICX": "icxusdt", + "ILV": "ilvusdt", + "INJ": "injusdt", + "IOST": "iostusdt", + "IOTX": "iotxusdt", + "JST": "jstusdt", + "KAVA": "kavausdt", + "KDA": "kdausdt", + "KEY": "keyusdt", + "KLAY": "klayusdt", + "KNC": "kncusdt", + "KP3R": "kp3rusdt", + "KSM": "ksmusdt", + "LINK": "linkusdt", + "LRC": "lrcusdt", + "LSK": "lskusdt", + "LTC": "ltcusdt", + "MANA": "manausdt", + "MATIC": "maticusdt", + "MEME": "memeusdt", + "MKR": "mkrusdt", + "MTL": "mtlusdt", + "NEAR": "nearusdt", + "NEO": "neousdt", + "NMR": "nmrusdt", + "OCEAN": "oceanusdt", + "OGN": "ognusdt", + "OMG": "omgusdt", + "ONE": "oneusdt", + "ONT": "ontusdt", + "OP": "opusdt", + "PAXG": "paxgusdt", + "PENDLE": "pendleusdt", + "PEPE": "pepeusdt", + "PNT": "pntusdt", + "POWR": "powrusdt", + "QTUM": "qtumusdt", + "REN": "renusdt", + "REP": "repusdt", + "RLC": "rlcusdt", + "ROSE": "roseusdt", + "RSR": "rsrusdt", + "RUNE": "runeusdt", + "RVN": "rvnusdt", + "SAND": "sandusdt", + "SC": "scusdt", + "SCRT": "scrtusdt", + "SHIB": "shibusdt", + "SKL": "sklusdt", + "SNX": "snxusdt", + "SOL": "solusdt", + "SPELL": "spellusdt", + "SRM": "srmusdt", + "STX": "stxusdt", + "SUN": "sunusdt", + "SUSHI": "sushiusdt", + "SXP": "sxpusdt", + "THETA": "thetausdt", + "TOMO": "tomousdt", + "TRB": "trbusdt", + "TRX": "trxusdt", + "TWT": "twtusdt", + "UMA": "umausdt", + "UNI": "uniusdt", + "VET": "vetusdt", + "WAN": "wanusdt", + "WAVES": "wavesusdt", + "WNXM": "wnxmusdt", + "XLM": "xlmusdt", + "XMR": "xmrusdt", + "XRP": "xrpusdt", + "XTZ": "xtzusdt", + "XVS": "xvsusdt", + "YFI": "yfiusdt", + "YFII": "yfiiusdt", + "YGG": "yggusdt", + "ZEC": "zecusdt", + "ZIL": "zilusdt", + "ZRX": "zrxusdt" +} diff --git a/price-adapter/resources/coingecko.json b/price-adapter/resources/coingecko.json new file mode 100644 index 00000000..07f08780 --- /dev/null +++ b/price-adapter/resources/coingecko.json @@ -0,0 +1,203 @@ +{ + "1INCH": "1inch", + "AAVE": "aave", + "ABYSS": "the-abyss", + "ADA": "cardano", + "AKRO": "akropolis", + "ALCX": "alchemix", + "ALGO": "algorand", + "ALPHA": "alpha-finance", + "AMPL": "ampleforth", + "ANKR": "ankr", + "ANT": "aragon", + "APE": "apecoin", + "ARB": "arbitrum", + "ARPA": "arpa", + "AST": "airswap", + "ASTR": "astar", + "ATOM": "cosmos", + "AUTO": "auto", + "AVAX": "avalanche-2", + "AXS": "axie-infinity", + "BAL": "balancer", + "BAND": "band-protocol", + "BAT": "basic-attention-token", + "BCH": "bitcoin-cash", + "BEL": "bella-protocol", + "BETA": "beta-finance", + "BETH": "binance-eth", + "BLZ": "bluzelle", + "BNB": "binancecoin", + "BNT": "bancor", + "BOBA": "boba-network", + "BORA": "bora", + "BSV": "bitcoin-cash-sv", + "BTC": "bitcoin", + "BTCB": "bitcoin-bep2", + "BTG": "bitcoin-gold", + "BTM": "bytom", + "BTS": "bitshares", + "BTT": "bittorrent", + "BUSD": "binance-usd", + "BZRX": "bzx-protocol", + "C98": "coin98", + "CAKE": "pancakeswap-token", + "CELO": "celo", + "CKB": "nervos-network", + "CLV": "clover-finance", + "COMP": "compound-governance-token", + "CREAM": "cream-2", + "CRO": "crypto-com-chain", + "CRV": "curve-dao-token", + "CUSD": "celo-dollar", + "CVC": "civic", + "DAI": "dai", + "DASH": "dash", + "DCR": "decred", + "DGB": "digibyte", + "DIA": "dia-data", + "DOGE": "dogecoin", + "DOT": "polkadot", + "DPI": "defipulse-index", + "DYDX": "dydx", + "EGLD": "elrond-erd-2", + "ELF": "aelf", + "ENJ": "enjincoin", + "EOS": "eos", + "ETC": "ethereum-classic", + "ETH": "ethereum", + "EURS": "stasis-eurs", + "EWT": "energy-web-token", + "FET": "fetch-ai", + "FIL": "filecoin", + "FLOW": "flow", + "FOR": "force-protocol", + "FRAX": "frax", + "FTM": "fantom", + "GALA": "gala", + "GLMR": "moonbeam", + "GMX": "gmx", + "GNO": "gnosis", + "GRT": "the-graph", + "GMT": "stepn", + "HBAR": "hedera-hashgraph", + "HEGIC": "hegic", + "HNT": "helium", + "HT": "huobi-token", + "ICX": "icon", + "ILV": "illuvium", + "INJ": "injective-protocol", + "IOST": "iostoken", + "IOTX": "iotex", + "JOE": "joe", + "JST": "just", + "KAI": "kardiachain", + "KAVA": "kava", + "KDA": "kadena", + "KEY": "selfkey", + "KLAY": "klay-token", + "KMD": "komodo", + "KNC": "kyber-network-crystal", + "KP3R": "keep3rv1", + "KSM": "kusama", + "LEO": "leo-token", + "LINA": "linear", + "LINK": "chainlink", + "LOOM": "loom-network", + "LRC": "loopring", + "LSK": "lisk", + "LTC": "litecoin", + "MANA": "decentraland", + "MATIC": "matic-network", + "MEME": "memecoin-2", + "MIM": "magic-internet-money", + "MIOTA": "iota", + "MKR": "maker", + "MLN": "melon", + "MOVR": "moonriver", + "MTL": "metal", + "MVL": "mass-vehicle-ledger", + "NEAR": "near", + "NEO": "neo", + "NFT": "apenft", + "NMR": "numeraire", + "OCEAN": "ocean-protocol", + "OGN": "origin-protocol", + "OKB": "okb", + "OMG": "omisego", + "ONE": "harmony", + "ONT": "ontology", + "OP": "optimism", + "OSMO": "osmosis", + "PAXG": "pax-gold", + "PENDLE": "pendle", + "PEPE": "pepe", + "PLR": "pillar", + "PNK": "kleros", + "PNT": "pnetwork", + "POLY": "polymath", + "POWR": "power-ledger", + "QKC": "quark-chain", + "QNT": "quant-network", + "QTUM": "qtum", + "REN": "republic-protocol", + "REP": "augur", + "REQ": "request-network", + "RLC": "iexec-rlc", + "ROSE": "oasis-network", + "RSR": "reserve-rights-token", + "RSV": "reserve", + "RUNE": "thorchain", + "RVN": "ravencoin", + "SAND": "the-sandbox", + "SC": "siacoin", + "SCRT": "secret", + "SFI": "saffron-finance", + "SHIB": "shiba-inu", + "SKL": "skale", + "SNT": "status", + "SNX": "havven", + "SOL": "solana", + "SPELL": "spell-token", + "SRM": "serum", + "STMX": "storm", + "STORJ": "storj", + "STRK": "strike", + "STX": "blockstack", + "SUN": "sun-token", + "SUSD": "nusd", + "SUSHI": "sushi", + "SXP": "swipe", + "THETA": "theta-token", + "TOMO": "tomochain", + "TRB": "tellor", + "TRX": "tron", + "TUSD": "true-usd", + "TWT": "trust-wallet-token", + "UBT": "unibright", + "UMA": "uma", + "UNI": "uniswap", + "UPP": "sentinel-protocol", + "USDC": "usd-coin", + "USDP": "paxos-standard", + "USDT": "tether", + "VET": "vechain", + "VIDT": "v-id-blockchain", + "WAN": "wanchain", + "WAVES": "waves", + "WBTC": "wrapped-bitcoin", + "WNXM": "wrapped-nxm", + "WRX": "wazirx", + "XEM": "nem", + "XLM": "stellar", + "XMR": "monero", + "XRP": "ripple", + "XTZ": "tezos", + "XVS": "venus", + "YFI": "yearn-finance", + "YFII": "yfii-finance", + "YGG": "yield-guild-games", + "ZEC": "zcash", + "ZIL": "zilliqa", + "ZRX": "0x" +} diff --git a/price-adapter/src/error.rs b/price-adapter/src/error.rs new file mode 100644 index 00000000..1b78c4ca --- /dev/null +++ b/price-adapter/src/error.rs @@ -0,0 +1,38 @@ +use thiserror::Error; + +/// Custom error type for the application. +#[derive(Debug, Error)] +pub enum Error { + #[error("unknown error")] + Unknown, + + #[error("price-adapter-raw error: {0}")] + PriceAdapterRawError(#[from] price_adapter_raw::error::Error), + + #[error("file error: {0}")] + FileError(#[from] std::io::Error), + + #[error("serde-json error: {0}")] + SerdeJsonError(#[from] serde_json::Error), + + #[error("unsupported symbol")] + UnsupportedSymbol, + + #[error("unsupported source")] + UnsupportedSource, + + #[error("mapping error")] + MappingError, + + #[error("service already started")] + AlreadyStarted, + + #[error("service not connected")] + NotConnected, + + #[error("Not found: {0}")] + NotFound(String), + + #[error("system-time error: {0}")] + SystemTimeError(#[from] std::time::SystemTimeError), +} diff --git a/price-adapter/src/lib.rs b/price-adapter/src/lib.rs new file mode 100644 index 00000000..e26c154a --- /dev/null +++ b/price-adapter/src/lib.rs @@ -0,0 +1,5 @@ +pub mod error; +pub mod mappers; +pub mod services; +pub mod sources; +pub mod types; diff --git a/price-adapter/src/mappers.rs b/price-adapter/src/mappers.rs new file mode 100644 index 00000000..c6f6e88d --- /dev/null +++ b/price-adapter/src/mappers.rs @@ -0,0 +1,3 @@ +mod band_static_mapper; + +pub use band_static_mapper::*; diff --git a/price-adapter/src/mappers/band_static_mapper.rs b/price-adapter/src/mappers/band_static_mapper.rs new file mode 100644 index 00000000..10317f5d --- /dev/null +++ b/price-adapter/src/mappers/band_static_mapper.rs @@ -0,0 +1,63 @@ +use crate::error::Error; +use crate::types::Mapper; +use serde_json::Value; +use std::collections::HashMap; +use std::fs::File; +use std::io::Read; +use std::path::Path; + +/// A struct representing a static mapper using a HashMap of String keys to Values. +pub struct BandStaticMapper { + mapping: HashMap, +} + +impl BandStaticMapper { + /// Constructor to create a new BandStaticMapper from a pre-existing mapping. + pub fn new(mapping: HashMap) -> Self { + Self { mapping } + } + + /// Constructor to create a BandStaticMapper from a source file. + pub fn from_source(source: &str) -> Result { + let content = match source { + "binance" => Ok(include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/resources/binance.json" + ))), + "coingecko" => Ok(include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/resources/coingecko.json" + ))), + _ => Err(Error::UnsupportedSource), // Add more matches for other sources + }?; + + // Deserialize the JSON content into a HashMap. + let mapping = serde_json::from_str(content)?; + + Ok(Self { mapping }) + } + + /// Constructor to create a BandStaticMapper from a file path. + pub fn from_path>(path: P) -> Result { + // Attempt to open the file at the specified path. + let mut file = File::open(&path)?; + + // Read the file content into a String. + let mut content = String::new(); + file.read_to_string(&mut content)?; + + // Deserialize the JSON content into a HashMap. + let mapping = serde_json::from_str(&content)?; + + Ok(Self { mapping }) + } +} + +/// Implementing the Mapper trait for BandStaticMapper. +#[async_trait::async_trait] +impl Mapper for BandStaticMapper { + /// Retrieve the mapping as a reference, wrapped in a Result. + async fn get_mapping(&self) -> Result<&HashMap, Error> { + Ok(&self.mapping) + } +} diff --git a/price-adapter/src/services.rs b/price-adapter/src/services.rs new file mode 100644 index 00000000..fba4e8a7 --- /dev/null +++ b/price-adapter/src/services.rs @@ -0,0 +1,5 @@ +mod interval; +mod websocket; + +pub use interval::*; +pub use websocket::*; diff --git a/price-adapter/src/services/interval.rs b/price-adapter/src/services/interval.rs new file mode 100644 index 00000000..e802bda1 --- /dev/null +++ b/price-adapter/src/services/interval.rs @@ -0,0 +1,112 @@ +use crate::types::{Service, Source}; +use crate::{error::Error, types::PriceInfo}; +use std::time::Duration; +use std::{collections::HashMap, sync::Arc}; +use tokio::time::sleep; +use tokio::{select, sync::Mutex}; +use tokio_util::sync::CancellationToken; + +/// A caching object storing prices received from Source at regular intervals. +pub struct IntervalService { + adapter: Arc>, + interval: Duration, + cached_prices: Arc>>, + cancellation_token: Option, +} + +impl IntervalService { + /// Creates a new `IntervalService` with the provided Source. + pub fn new(adapter: S, interval: Duration) -> Self { + Self { + adapter: Arc::new(Mutex::new(adapter)), + interval, + cached_prices: Arc::new(Mutex::new(HashMap::new())), + cancellation_token: None, + } + } +} + +#[async_trait::async_trait] +impl Service for IntervalService { + /// Starts the service, fetching prices at regular intervals and caching them. + async fn start(&mut self, symbols: &[&str]) -> Result<(), Error> { + if self.is_started().await { + return Err(Error::AlreadyStarted); + } + + let token = CancellationToken::new(); + let cloned_token = token.clone(); + let cloned_adapter = Arc::clone(&self.adapter); + let cloned_symbols: Vec = symbols.iter().map(|&s| s.to_string()).collect(); + let cloned_cached_prices = Arc::clone(&self.cached_prices); + let interval_duration = self.interval; + self.cancellation_token = Some(token); + + tokio::spawn(async move { + loop { + let borrowed_symbols: Vec<&str> = + cloned_symbols.iter().map(|s| s.as_str()).collect(); + let locked_adapter = cloned_adapter.lock().await; + + select! { + _ = cloned_token.cancelled() => { + break; + } + + prices = locked_adapter.get_prices(&borrowed_symbols) => { + drop(locked_adapter); + + let mut locked_cached_prices = cloned_cached_prices.lock().await; + for price in prices.into_iter().flatten() { + locked_cached_prices.insert(price.symbol.to_string(), price); + } + } + } + + sleep(interval_duration).await; + } + }); + + Ok(()) + } + + /// Stops the service, cancelling the interval fetching. + async fn stop(&mut self) { + if let Some(token) = &self.cancellation_token { + token.cancel(); + } + self.cancellation_token = None; + } + + // To check if the service is started. + async fn is_started(&self) -> bool { + self.cancellation_token.is_some() + } +} + +#[async_trait::async_trait] +impl Source for IntervalService { + /// Retrieves prices for the specified symbols from the cached prices. + async fn get_prices(&self, symbols: &[&str]) -> Vec> { + let locked_cached_prices = self.cached_prices.lock().await; + symbols + .iter() + .map(|&symbol| { + locked_cached_prices + .get(&symbol.to_ascii_uppercase()) + .map_or_else( + || Err(Error::NotFound(symbol.to_string())), + |price| Ok(price.clone()), + ) + }) + .collect() + } + + // Asynchronous function to get price for a symbol. + async fn get_price(&self, symbol: &str) -> Result { + self.get_prices(&[symbol]) + .await + .pop() + .ok_or(Error::Unknown)? + } +} diff --git a/price-adapter/src/services/websocket.rs b/price-adapter/src/services/websocket.rs new file mode 100644 index 00000000..56538072 --- /dev/null +++ b/price-adapter/src/services/websocket.rs @@ -0,0 +1,120 @@ +use crate::{ + error::Error, + types::{PriceInfo, Service, Source, WebSocketSource, WebsocketMessage}, +}; +use std::{collections::HashMap, sync::Arc}; +use tokio::{select, sync::Mutex}; +use tokio_util::sync::CancellationToken; + +/// A caching object storing prices received from WebSocketSource. +pub struct WebsocketService { + socket: Arc>, + cached_prices: Arc>>, + cancellation_token: Option, +} + +impl WebsocketService { + /// Creates a new `WebsocketService` with the provided WebSocketSource. + pub fn new(socket: S) -> Self { + Self { + socket: Arc::new(Mutex::new(socket)), + cached_prices: Arc::new(Mutex::new(HashMap::new())), + cancellation_token: None, + } + } +} + +#[async_trait::async_trait] +impl Service for WebsocketService { + /// Starts the service, connecting to the WebSocket and subscribing to symbols. + async fn start(&mut self, symbols: &[&str]) -> Result<(), Error> { + if self.is_started().await { + return Err(Error::AlreadyStarted); + } + + let mut locked_socket = self.socket.lock().await; + if !locked_socket.is_connected().await { + locked_socket.connect().await?; + locked_socket.subscribe(symbols).await?; + } + drop(locked_socket); + + let token = CancellationToken::new(); + let cloned_token = token.clone(); + let cloned_socket = Arc::clone(&self.socket); + let cloned_cached_prices = Arc::clone(&self.cached_prices); + self.cancellation_token = Some(token); + + tokio::spawn(async move { + loop { + let mut locked_socket = cloned_socket.lock().await; + select! { + _ = cloned_token.cancelled() => { + break; + } + + result = locked_socket.next() => { + drop(locked_socket); + + match result { + Some(Ok(WebsocketMessage::PriceInfo(price_info))) => { + let mut locked_cached_prices = cloned_cached_prices.lock().await; + locked_cached_prices.insert(price_info.symbol.to_string(), price_info); + } + Some(Ok(WebsocketMessage::SettingResponse(_response))) => {} + Some(Err(err)) => { + tracing::trace!("cannot get price: {}", err); + } + None => { + tracing::trace!("cannot get price: stream ended"); + break; + } + } + } + } + } + }); + + Ok(()) + } + + /// Stops the service, cancelling the WebSocket subscription. + async fn stop(&mut self) { + if let Some(token) = &self.cancellation_token { + token.cancel(); + } + self.cancellation_token = None; + } + + // To check if the service is started. + async fn is_started(&self) -> bool { + self.cancellation_token.is_some() + } +} + +#[async_trait::async_trait] +impl Source for WebsocketService { + /// Retrieves prices for the specified symbols from the cached prices. + async fn get_prices(&self, symbols: &[&str]) -> Vec> { + let locked_cached_prices = self.cached_prices.lock().await; + symbols + .iter() + .map(|&symbol| { + locked_cached_prices + .get(&symbol.to_ascii_uppercase()) + .map_or_else( + || Err(Error::NotFound(symbol.to_string())), + |price| Ok(price.clone()), + ) + }) + .collect() + } + + // Asynchronous function to get price for a symbol. + async fn get_price(&self, symbol: &str) -> Result { + self.get_prices(&[symbol]) + .await + .pop() + .ok_or(Error::Unknown)? + } +} diff --git a/price-adapter/src/sources.rs b/price-adapter/src/sources.rs new file mode 100644 index 00000000..793a4e81 --- /dev/null +++ b/price-adapter/src/sources.rs @@ -0,0 +1,7 @@ +mod band_stable_coin; +mod binance; +mod coingecko; + +pub use band_stable_coin::*; +pub use binance::*; +pub use coingecko::*; diff --git a/price-adapter/src/sources/band_stable_coin.rs b/price-adapter/src/sources/band_stable_coin.rs new file mode 100644 index 00000000..d6b2bc38 --- /dev/null +++ b/price-adapter/src/sources/band_stable_coin.rs @@ -0,0 +1,56 @@ +use crate::error::Error; +use crate::types::{PriceInfo, Source}; +use std::time::{SystemTime, UNIX_EPOCH}; + +/// A struct representing a stable coin with a constant price. +pub struct BandStableCoin; + +impl BandStableCoin { + /// Constructor to create a new BandStableCoin. + pub fn new() -> Self { + Self + } +} + +impl Default for BandStableCoin { + fn default() -> Self { + Self::new() + } +} + +// Implementing the StableCoin trait for BandStableCoin. +#[async_trait::async_trait] +impl Source for BandStableCoin { + async fn get_prices(&self, symbols: &[&str]) -> Vec> { + let cur_time = SystemTime::now() + .duration_since(UNIX_EPOCH) + .map_err(Error::SystemTimeError); + + match cur_time { + Ok(time) => symbols + .iter() + .map(|symbol| { + Ok(PriceInfo { + symbol: symbol.to_string(), + price: 1_f64, + timestamp: time.as_secs(), + }) + }) + .collect(), + Err(_) => { + return symbols.iter().map(|_| Err(Error::Unknown)).collect(); + } + } + } + + /// Retrieve the price of the stable coin. + /// + /// This method returns a constant value of 1.0 for any symbol. + async fn get_price(&self, symbol: &str) -> Result { + Ok(PriceInfo { + symbol: symbol.to_string(), + price: 1_f64, + timestamp: SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs(), + }) + } +} diff --git a/price-adapter/src/sources/binance.rs b/price-adapter/src/sources/binance.rs new file mode 100644 index 00000000..187b8412 --- /dev/null +++ b/price-adapter/src/sources/binance.rs @@ -0,0 +1,3 @@ +mod websocket; + +pub use websocket::*; diff --git a/price-adapter/src/sources/binance/websocket.rs b/price-adapter/src/sources/binance/websocket.rs new file mode 100644 index 00000000..9833659a --- /dev/null +++ b/price-adapter/src/sources/binance/websocket.rs @@ -0,0 +1,216 @@ +use crate::mappers::BandStaticMapper; +use crate::sources::BandStableCoin; +use crate::types::{Mapper, SettingResponse, Source, WebSocketSource, WebsocketMessage}; +use crate::{error::Error, types::PriceInfo}; +use futures_util::{stream::FusedStream, Stream, StreamExt}; +use price_adapter_raw::{ + types::WebsocketMessage as WebsocketMessageRaw, BinanceWebsocket as BinanceWebsocketRaw, +}; +use std::time::Duration; +use std::{ + collections::HashMap, + pin::Pin, + sync::Arc, + task::{Context, Poll}, +}; +use tokio::sync::Mutex; +use tokio::time::sleep; + +pub type DefaultBinanceWebsocket = BinanceWebsocket; + +/// A generic struct `BinanceWebsocket` parameterized over `Mapper` and `Source` types. +pub struct BinanceWebsocket { + mapper: M, + usdt_source: Arc, + usdt_interval: Duration, + + usdt_price: Arc>>, + raw: Arc>, + mapping_back: HashMap, + ended: bool, +} + +impl BinanceWebsocket { + /// Constructor for the `BinanceWebsocket` struct. + pub fn new(mapper: M, usdt_source: S, usdt_interval: Duration) -> Self { + Self { + mapper, + usdt_source: Arc::new(usdt_source), + usdt_interval, + usdt_price: Arc::new(Mutex::new(None)), + raw: Arc::new(Mutex::new(BinanceWebsocketRaw::new( + "wss://stream.binance.com:9443", + ))), + mapping_back: HashMap::new(), + ended: false, + } + } +} + +// Implementing the WebSocketSource trait for BinanceWebsocket. +#[async_trait::async_trait] +impl WebSocketSource for BinanceWebsocket { + /// Asynchronous function to connect to the WebSocket. + async fn connect(&mut self) -> Result<(), Error> { + let mut locked_raw = self.raw.lock().await; + if !locked_raw.is_connected() { + locked_raw.connect().await?; + } + drop(locked_raw); + + let cloned_usdt_source = Arc::clone(&self.usdt_source); + let cloned_usdt_price = Arc::clone(&self.usdt_price); + let cloned_usdt_interval = self.usdt_interval; + + tokio::spawn(async move { + loop { + let price_info = cloned_usdt_source.get_price("USDT").await; + let mut locked_usdt_price = cloned_usdt_price.lock().await; + if let Ok(price) = price_info { + *locked_usdt_price = Some(price); + } else { + *locked_usdt_price = None; + } + drop(locked_usdt_price); + + sleep(cloned_usdt_interval).await; + } + }); + + Ok(()) + } + + /// Asynchronous function to subscribe to symbols. + async fn subscribe(&mut self, symbols: &[&str]) -> Result { + // Retrieve the symbol-to-id mapping from the provided mapper. + let mapping = self.mapper.get_mapping().await?; + + for (key, value) in mapping { + if let Some(pair) = value.as_str() { + self.mapping_back + .insert(pair.to_string().to_uppercase(), key.to_string()); + } + } + + let ids: Vec<&str> = symbols + .iter() + .filter_map(|&symbol| mapping.get(symbol)) + .filter_map(|val| val.as_str()) + .collect(); + + if ids.len() != symbols.len() { + return Err(Error::UnsupportedSymbol); + } + + let mut locked_raw = self.raw.lock().await; + locked_raw + .subscribe(ids.as_slice()) + .await + .map_err(Error::PriceAdapterRawError) + } + + /// Asynchronous function to unsubscribe from symbols. + async fn unsubscribe(&mut self, symbols: &[&str]) -> Result { + let ids: Vec<&str> = symbols + .iter() + .filter_map(|&symbol| self.mapping_back.get(symbol)) + .map(|string_ref| string_ref.as_str()) + .collect(); + + if ids.len() != symbols.len() { + return Err(Error::UnsupportedSymbol); + } + + let mut locked_raw = self.raw.lock().await; + locked_raw + .unsubscribe(ids.as_slice()) + .await + .map_err(Error::PriceAdapterRawError) + } + + /// Check if the WebSocket is connected. + async fn is_connected(&self) -> bool { + let locked_raw = self.raw.lock().await; + locked_raw.is_connected() + } +} + +// Implementing BinanceWebsocket for specific types (BandStaticMapper, BandStableCoin). +impl DefaultBinanceWebsocket { + /// Constructor for creating a new BinanceWebsocket with default settings. + pub fn new_with_default() -> Result { + let mapper = BandStaticMapper::from_source("binance")?; + let band_stable_coin = BandStableCoin::new(); + Ok(Self::new(mapper, band_stable_coin, Duration::from_secs(5))) + } +} + +// Implementing Stream for BinanceWebsocket. +impl Stream for BinanceWebsocket { + type Item = Result; + + fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + if self.ended { + return Poll::Ready(None); + } + + let Ok(mut locked_raw) = self.raw.try_lock() else { + cx.waker().wake_by_ref(); + return Poll::Pending; + }; + + let clone_usdt_price = Arc::clone(&self.usdt_price); + let Ok(locked_usdt_price) = clone_usdt_price.try_lock() else { + cx.waker().wake_by_ref(); + return Poll::Pending; + }; + + let Some(usdt_price) = &*locked_usdt_price else { + cx.waker().wake_by_ref(); + return Poll::Pending; + }; + + match locked_raw.poll_next_unpin(cx) { + Poll::Ready(Some(message)) => match message { + Ok(WebsocketMessageRaw::PriceInfo(price_info_raw)) => { + tracing::trace!("received price info raw: {}", price_info_raw); + if let Some(symbol) = self.mapping_back.get(&price_info_raw.id) { + Poll::Ready(Some(Ok(WebsocketMessage::PriceInfo(PriceInfo { + symbol: symbol.to_string(), + price: price_info_raw.price / usdt_price.price, + timestamp: price_info_raw.timestamp, + })))) + } else { + // If symbol not found, wake up the waker and return Pending. + tracing::trace!("received symbol doesn't match"); + cx.waker().wake_by_ref(); + Poll::Pending + } + } + Ok(WebsocketMessageRaw::SettingResponse(response)) => { + tracing::trace!("received setting response raw: {:?}", response); + Poll::Ready(Some(Ok(WebsocketMessage::SettingResponse( + SettingResponse { + data: response.data, + }, + )))) + } + Err(err) => Poll::Ready(Some(Err(err.into()))), + }, + Poll::Ready(None) => { + drop(locked_raw); + self.ended = true; + Poll::Ready(None) + } + Poll::Pending => Poll::Pending, + } + } +} + +// Implementing FusedStream for BinanceWebsocket. +impl FusedStream for BinanceWebsocket { + /// Check if the stream is terminated. + fn is_terminated(&self) -> bool { + self.ended + } +} diff --git a/price-adapter/src/sources/coingecko.rs b/price-adapter/src/sources/coingecko.rs new file mode 100644 index 00000000..7d364f76 --- /dev/null +++ b/price-adapter/src/sources/coingecko.rs @@ -0,0 +1,96 @@ +use crate::error::Error; +use crate::mappers::BandStaticMapper; +use crate::types::Mapper; +use crate::types::{PriceInfo, Source}; +use price_adapter_raw::CoinGecko as CoinGeckoRaw; + +pub type DefaultCoinGecko = CoinGecko; + +// Generic struct `CoinGecko` parameterized over a `Mapper` type. +pub struct CoinGecko { + raw: CoinGeckoRaw, + mapper: M, +} + +impl CoinGecko { + // Constructor for the `CoinGecko` struct. + pub fn new(mapper: M, api_key: Option) -> Self { + // Initialize `CoinGeckoRaw` based on the presence of an API key. + let raw = if let Some(key) = &api_key { + CoinGeckoRaw::new_with_api_key(key.to_string()) + } else { + CoinGeckoRaw::new() + }; + + Self { raw, mapper } + } +} + +impl DefaultCoinGecko { + // Constructor for a default `CoinGecko` instance with `BandStaticMapper`. + pub fn new_with_default(api_key: Option) -> Result { + let mapper = BandStaticMapper::from_source("coingecko")?; + Ok(Self::new(mapper, api_key)) + } +} + +#[async_trait::async_trait] +impl Source for CoinGecko { + // Asynchronous function to get prices for symbols. + async fn get_prices(&self, symbols: &[&str]) -> Vec> { + // Retrieve the symbol-to-id mapping from the provided mapper. + let mapping = self.mapper.get_mapping().await; + + // Match on the result of obtaining the mapping. + if let Ok(mapping) = &mapping { + // Collect symbols with associated ids and indices. + let ids_with_index: Vec<(&str, &str, usize)> = symbols + .iter() + .enumerate() + .filter_map(|(index, &symbol)| { + mapping + .get(symbol) + .and_then(|id| id.as_str().map(|id| (symbol, id, index))) + }) + .collect(); + + // Extract only the ids from the collected tuples. + let ids: Vec<&str> = ids_with_index.iter().map(|(_, id, _)| *id).collect(); + + // Retrieve prices for the collected ids asynchronously. + let prices = self.raw.get_prices(ids.as_slice()).await; + + // Initialize a vector to store the results. + let mut res: Vec> = symbols + .iter() + .map(|_| Err(Error::UnsupportedSymbol)) + .collect(); + + // Iterate over collected ids and prices to populate the results vector. + for (&id, price) in ids_with_index.iter().zip(prices) { + // Assign the result based on the price, mapping errors. + res[id.2] = price + .map_err(Error::PriceAdapterRawError) + .map(|p| PriceInfo { + symbol: id.0.to_string(), + price: p.price, + timestamp: p.timestamp, + }); + } + + // Return the results vector. + res + } else { + // Return errors for symbols if there's an issue with the mapping. + symbols.iter().map(|_| Err(Error::MappingError)).collect() + } + } + + // Asynchronous function to get price for a symbol. + async fn get_price(&self, symbol: &str) -> Result { + self.get_prices(&[symbol]) + .await + .pop() + .ok_or(Error::Unknown)? + } +} diff --git a/price-adapter/src/types.rs b/price-adapter/src/types.rs new file mode 100644 index 00000000..12172512 --- /dev/null +++ b/price-adapter/src/types.rs @@ -0,0 +1,9 @@ +mod mapper; +mod response; +mod service; +mod source; + +pub use mapper::*; +pub use response::*; +pub use service::*; +pub use source::*; diff --git a/price-adapter/src/types/mapper.rs b/price-adapter/src/types/mapper.rs new file mode 100644 index 00000000..5c9a3d8f --- /dev/null +++ b/price-adapter/src/types/mapper.rs @@ -0,0 +1,13 @@ +use crate::error::Error; +use serde_json::Value; +use std::collections::HashMap; + +#[async_trait::async_trait] +pub trait Mapper: Send + Sync + Sized + Unpin + 'static { + /// Asynchronously retrieves the mapping data. + /// + /// This method is responsible for fetching and returning the mapping data, + /// which is represented as a `HashMap`. It returns a `Result` + /// containing the mapping data or an `Error` if the operation fails. + async fn get_mapping(&self) -> Result<&HashMap, Error>; +} diff --git a/price-adapter/src/types/response.rs b/price-adapter/src/types/response.rs new file mode 100644 index 00000000..a51749fe --- /dev/null +++ b/price-adapter/src/types/response.rs @@ -0,0 +1,46 @@ +use core::fmt; +use serde::{Deserialize, Serialize}; +use serde_json::Value; + +/// Represents information about the price of a symbol. +/// +/// This struct is used to store details about the price of a symbol, +/// including the symbol name, the price value, and the timestamp. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct PriceInfo { + pub symbol: String, + pub price: f64, + pub timestamp: u64, +} + +impl fmt::Display for PriceInfo { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "PriceInfo {{ symbol: {}, price: {}, timestamp: {} }}", + self.symbol, self.price, self.timestamp + ) + } +} + +/// Represents the response structure for setting-related data. +/// +/// This struct is used to deserialize JSON responses containing +/// setting-related information. +#[derive(Debug, Deserialize)] +pub struct SettingResponse { + pub data: Value, +} + +/// Represents different types of messages received over a WebSocket connection. +/// +/// This enum encapsulates various types of messages that can be received +/// over a WebSocket connection, such as price information or setting responses. +#[derive(Debug)] +pub enum WebsocketMessage { + /// Represents a message containing price information. + PriceInfo(PriceInfo), + + /// Represents a message containing setting-related data. + SettingResponse(SettingResponse), +} diff --git a/price-adapter/src/types/service.rs b/price-adapter/src/types/service.rs new file mode 100644 index 00000000..8259468d --- /dev/null +++ b/price-adapter/src/types/service.rs @@ -0,0 +1,9 @@ +use crate::error::Error; +use crate::types::Source; + +#[async_trait::async_trait] +pub trait Service: Source { + async fn start(&mut self, symbols: &[&str]) -> Result<(), Error>; + async fn stop(&mut self); + async fn is_started(&self) -> bool; +} diff --git a/price-adapter/src/types/source.rs b/price-adapter/src/types/source.rs new file mode 100644 index 00000000..a4c59d02 --- /dev/null +++ b/price-adapter/src/types/source.rs @@ -0,0 +1,48 @@ +use crate::error::Error; +use crate::types::{PriceInfo, WebsocketMessage}; +use futures_util::{stream::FusedStream, StreamExt}; + +#[async_trait::async_trait] +/// Represents a source for fetching prices through HTTP requests. +/// +/// This trait defines methods for obtaining price information for a given set +/// of symbols. Implementors are expected to provide an +/// asynchronous implementation for retrieving prices. +pub trait Source: Send + Sync + Unpin + 'static { + /// Asynchronously retrieves prices for the specified symbols. + /// + /// Return a vector of `Result`. Each result represents the outcome of + /// attempting to fetch price information for a specific symbol. + async fn get_prices(&self, symbols: &[&str]) -> Vec>; + + /// Asynchronously retrieves the price for a specified symbol. + /// + /// Return price information for the specified symbol. + async fn get_price(&self, symbol: &str) -> Result; +} + +#[async_trait::async_trait] +/// Represents a source for streaming WebSocket messages. +/// +/// This trait defines methods for connecting to a WebSocket, subscribing and +/// unsubscribing to symbols, checking the connection status, and streaming +/// WebSocket messages. +pub trait WebSocketSource: + Send + Sync + StreamExt> + FusedStream + Unpin + 'static +{ + /// Asynchronously establishes a connection to the WebSocket. + async fn connect(&mut self) -> Result<(), Error>; + + /// Asynchronously subscribes to the specified symbols on the WebSocket. + /// + /// Returns the number of symbols successfully subscribed. + async fn subscribe(&mut self, symbols: &[&str]) -> Result; + + /// Asynchronously unsubscribes from the specified symbols on the WebSocket. + /// + /// Returns the number of symbols successfully unsubscribed. + async fn unsubscribe(&mut self, symbols: &[&str]) -> Result; + + /// Checks whether the WebSocket is currently connected. + async fn is_connected(&self) -> bool; +}