-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2020 Summer Internship Project: Bitcoin Price & History Data #6
Comments
This library seems useful for this project: https://github.com/ccxt/ccxt
To reduce the time it takes to retrieve the price, the ideal approach would be to have the backend of the hidden service connect to an exchange via a Websocket API. However, I can't seem to find a free Websocket pricing API. I also have experience hosting hidden services, so I can help with this project. |
@Fonta1n3 What price feed are we using now? What others have we investigated and we can't use because of API or other limitations? Also, if we do our own API, any thoughts on your preferences? We already are doing some connections with https://blockstream.info via their .onion service — I know that they said they may offer it someday (Blockstream has the data, but they may be restricted in sharing it due to their contract with ICE/NYSE). Have they published any price API thoughts? @wolfmcnally, you also looked at a bunch of bitcoin APIs at one point — if we do our own APIs, do you have any strong preferences? -- Christopher Allen |
Unfortunately we are using blockchain.info/ticker currently. We were using blockchair.com/api but quickly found it is not free. |
I'm volunteering to lead the Bitcoin price data project. ProposalFirst, build a Flask REST API that returns the current price of Bitcoin, along with historical price data. The API would be accessible as a .onion v3 hidden service.
Most likely the ccxt/ccxt library will be used to retrieve price data from multiple exchanges. Tasks
|
I would suggest separating out this into separate sub-projects.
— Christopher Allen |
I'd like to offer my help on this project - I have experience with flask, python generally, and data mining. I don't have a mac so can't do any of the FN2 related stuff but could certainly be helpful with the API. Here is a websocket service that aggregates data from several exchanges: https://docs.cryptoapis.io/websockets/index#websockets |
@watersnake1 Cool, I think we can split this project into 2 parts, the API and FN2. You can work on the API and I can work on integrating it with FN2. I have experience in hosting .onions so I can help with writing a setup script for running the API behind a hidden service. |
Great. It looks like the cctx library you mentioned is a great starting point. FN2-API ProposalSummaryCreate a local web server that provides API access to bitcoin price data across many exchanges. Store selected in a local db for quicker access. Once running, the server can be accessed locally or remotely (i.e. FN2) to provide updated price information for btc and historical price data. Proposal
I would also add on here that the server should store some data in a local db. Keeping historical data cached will allow the server to serve historical feeds without being ratelimited (most exchange APIs limit to ~30 calls / minute). Even if everything ran on websocket data this could still be an issue if nothing is cached, because websockets only give you new data. |
This is perfect, once we have this running we can add this service to the Standup Script. |
You certainly have the technical prowess to take lead on this! Need to do a little research on some of the technologies you mentioned to have proper input, but here to help in any way. Have previous experience w/ python + sql. |
Ok, it looks like we are pretty close to a plan. We have two leads, @watersnake1 for a new repo for the service, @jodobear for a feature branch to FN2. Additional support and review of API from @cprkrn, @Fonta1n3 and myself, and @cprkrn also as a key tester. @Fonta1n3 in particular should review the API proposals above and tasks and give a +1. What we need now are ~3 reasonable top-level milestone for these two projects with the last being public service, docs, and publicity. Then we add that to the internship agreements, sign them, and we are a go! -- Christopher Allen |
FN2 is written in Swift, i have never written Swift so, how do i contribute? |
@ChristopherA @jodobear I have experience with Swift, I can work on a feature branch for FN2. |
I would put it on the wishlist that this returns an average price over a certain time period (30 mins for example) from an array of exchanges and is not just limited to USD but includes all major currencies in the response, sorted by ticker. That way we can easily support many fx rates.
You can see it here
FN2 already does this.
Would certainly prefer this approach to using USD by default.
I imagine this could open up some liability issues and many complaints from customers (see why Samourai abandoned fiat) if slippage occurs, probably best to just keep it in BTC and simply display balances in fiat.
Currently we have the ability to save transaction data but no ability to look up historic fx rates (only current), it would be nice if we do include this functionality to automatically parse all cc @ChristopherA (apologies had not seen your request for me to review yet, these are my initial requests/feedback) Cheers, |
FN2 Branch Proposal
|
sgtm +1
The foundation for this has already been added, currently when you broadcast a transaction in FN2 the app will save the transaction along with an optional user added memo, we include the current fx rate (usd/btc) with this meta data (core data). When you tap the "info" button on the home screen in the transaction cell we display that data to the user. If that particular tx was not broadcast with FN2 it won't be stored locally and no historic fiat data will be available. The user may add a memo to the transaction at which point it will be saved locally. Once we have a means of fetching historic price data (for transactions that were not broadcast with FN2) we can add a function that parses all historic transactions that way users who want to "do the right thing" and utilize FN2 as an accounting tool can easily tap an "export to beancount" button (@ChristopherA is more familiar with beancount then I am). The only reason they need to be saved locally is for the ability to add memos, other than that we can just fetch everything we need from bitcoind on the fly. If you want to start working on this just let me know so we can coordinate, I am currently working off of this branch on my fork, it would probably be smoothest if you waited till we merge it into Blockchain Commons FN2 development branch that way we are working from the same code base. |
Here is my first attempt at a design spec for the api server. This version should focus on using existing libraries or plain GET requests to obtain data. Then, support for websockets should be added. The server should run in the background as a system service. FN-Server Design SpecLanguage: Python3 API RoutesAPI responses are returned as JSON
Methods
Config FileThe config file should have the following settings to be defined by the user
|
Internship milestones
*The latest completion date is an upper bound, I will probably finish before it |
This looks a good start. It mostly lacks some rough completion dates, and connecting those dates with some dependences (milestone 2 is dependent on some version of the API server being available, and 2nd part of milestone 3 that that code ready to be installable by itself, or possibly using some BitcoinStandup plugin method.) -- Christopher Allen |
BTW, an archive of some details on what I learned about using Beancount for Bitcoin Accounting: This feature on a per Bitcoin account in FN2 I think would be an incredibly useful tool for someone trying to "do the right thing" with bitcoin accounting. It uses the "brew install beancount" command-line ledger system. The following file would be available in each FN2 account, created from the transaction data. The top would have some default bookkeeping accounts (someday changeable in the settings for other account name preferences). Example of a two in events (receiving bitcoin), and then an outgoing event which should be an expense, but in fact it also generates a small income event has the bitcoin price went up. Input put this into beancount and it will properly show it. An important thing I learned is that if you know the cost basis for the UTXO's being spent (i.e. have been using our wallet the whole time, or at least until we find a historical price feed), you need to store the cost basis of the change output as well, using HIFO (Highest cost base UTXO is spent first, until you have the lowest cost one as the price for change.
This was a HUGE pain in the ass for me in 2019, and will be worse in 2020, so I'm sure I'm not the only one dealing with this as a problem. |
@ChristopherA thanks for the info about beancount, I'll be looking into how to design the exporting feature soon. I've also added rough completion dates along with dependencies for each milestone (the dates are an upper bound). |
@gg2001 Looks good. Here is some example text toward a signed work order: This is a Work Order under the most recently released version of Blockchain Commons and Intern agree: Start Date2020-06-15 End Date2020-08-21 Repositories[list of existing or new repositories you will be contributing to] Milestones[your list of milestones above] Total Hours40 hours. If intern exceeds 40 hours, any additional effort toward these milestones will not be compensated by Blockchain Commons. All such contributions after 40 hours will at Intern's own choice as part of any normal open source contribution under the standard Contributor License Agreement (aka CLA) in that repo for that project. FeeFlat fee of US$564.00, in three installments of US$188. Rate will be USD/BTC based on the Gemini exchange at time of transfer. CurrencyBitcoin Intern's Payment InstructionsIntern will provide Blockchain Commons a new bitcoin address for each payment over a secure channel. Blockchain Commons' Billing InstructionsFirst payment to be paid in Bitcoin for US$188 in Bitcoin within 5 days of digital signature of this work order and terms. 2nd payment for completion of 2nd milestone. Payment US$188 in Bitcoin within 5 days of notice to Blockchain Commons. 3rd payment on completion of 3rd milestone, or completion of 40 hours of effort by intern, no later than August 21st. Payment of US$188 in Bitcoin within 5 days of notice to Blockchain Commons. |
See discussion about onionbalance, my conflating requirements of different hosted projects, and a need for understanding risk models in #5 (comment) -- Christopher Allen |
BTCPay is actually integrating with many exchanges and has its own rating script DSL. (Where you can define more complex rules of calculation)
means that every pair will use bitflyer
Mean that usd will use coinbase and any pair with JPY will use bitflyer. Then you can compose it.
which mean the LTC_USD pair will use We already provide a public endpoint for those rate on your own instance. We just need to document it better. We use a mix a direct API integration, and for some exchanges, coingecko. We do not provide history. |
@NicolasDorier — thank you for that information! Any chance that you'd be willing to make that public endpoint also available at a Tor v3 hidden service, the way blockstream.info also has a hidden service version? -- Christopher Allen |
@NicolasDorier, we are also investigating using Onion Balance so that we can host anycast-like services from multiple places around the world. This might be something of interest to your community as well. https://onionbalance.readthedocs.io/en/latest/v3/tutorial-v3.html#tutorial-v3 |
So that it is easier to follow the conversation in this thread, here is an excerpt from another threat that should be here: #5 You are correct, I've conflating the requirements of the two (or more) projects. Especially given your onion balance suggestion, we can try to have greater security in one place, and be less rigorous in the others. But in the long run I really want our users not to even depend on us for these services, instead give them a choice of many. We are definitely need to do significantly more puzzling through the current price API risk models. Anything we do will be likely be better than the current state of the art where mobile wallets use a single source of current price information, typically the wallet vendor or a single exchange's API. Not only is this model vulnerable to DOS attacks, I suspect there are other tricks an attacker can do if they can make your remote wallet think the price has changed when it has not. Offering this services via Tor v3 also means we add a new attack surface that is less well known. I don't necessarily want to replicate what Blockstream is doing with their current price data, but more desire to enable those who want to source it themselves for their own full node / remote wallet combos, that they can install an app alongside their full node that sources its own current data from APIs that user chooses. If they want to point their remote app to us, another reputable clone of our service, or directly to the API of their favorite exchange, or even test against multiple exchanges, it is up to them. Our key requirement for this service is as much self-sovereignty for the full-node / remote wallet user as possible. The historical data is also useful, but finding some way to distribute it safely is a different risk model than that for current price data. |
@ChristopherA all btcpay installs (via the docker install method) come with a hidden service properly set up. |
@NicolasDorier wrote:
What I meant was a hidden service for your:
|
@slush0 wrote in a telegram group:
I’ve asked if there is an onion feed. |
Our https://mainnet.demo.btcpayserver.org/ that you can access to http://fc4booz5wmoq3knc63gf4sn7oisz45sc7zxtlgnqkeqb2pvzqow6ydqd.onion/ support it. This is our demo server, so everybody installing BTCPay has their own service as well. |
In regards to the local database, I think sqlite3 is a good option. It is an easy to use / integrate db thats pretty lightweight. Although it is not the best choice for use as a webserver, I think that it is a safe assumption that most server instances anyone runs will not be used by more than a few people (and probably just one person a lot of the time). Does anyone have any other db suggestions, or resources on hardening / making sqlite3 as secure as possible? As for the database design, I am not sure whether to store all price entries in one table, like this:
or to separate each supported exchange into its own table:
Since the actual table structure would be abstracted away from the user via the API, I suppose that the specific table setup doesn't effect anything too much. But any input is appreciated. I will be integrating the db design into the final spec that I will complete by the deadline for my project phase one goal. |
fn-server spec (draft 2, final for milestone 1)This is my final version of the spec for this project. I will use this as my reference when implementing during milestone 2. API RoutesAPI responses are returned as JSON
GET /hist/[currency]/[exchange]/[date_start]/[date_end]
GET /status/
ConfigurationThe user will configure the program via a config file, which will be located in a hidden subdirectory of the users home folder. The following settings will be included:
DatabaseThe database will be an sqlite3 db. One database will be created. Inside of it, each exchange will have a separate table. Entries from different currencies will be in different rows. The columns of each table shall be Methods
Execution Flow
|
Thanks to @watersnake1 with support from @jodobear and @javiervargas, we now have spotbit, an amazing bit of progress for a mere summer's work. Thanks folks! |
To fully function as a mainnet Bitcoin mobile wallet, FullyNoded 2 needs to have price data. Right now this means we've had to turn off locking the wallet down to only speak to hidden .onion addresses, as there doesn't appear to be any free APIs for price data.
In addition, we'd like to users being able to support adding price data history to your transactional data in your personal wallet. For instance, to allow export to a personal Beancount accounting database.
Thus at minimum we'd like to host our own hidden .onion service with current price data, and in the principle of self-sovereignty, allow people to host this service themselves if they want on their own VPS, VM or personal node.
Other features are the price history, possibly scraped from multiple sources, various forms of validation (public lists of price servers, data is signed by the .onion servers keys, is this the same in 3 or more sites, etc.)
Right now Cooper Kernan (@cprkrn) has the most background about price data, and is likely the intern lead on this project. But he'll need support to design how to do this portably so that we can can potentially host this at multiple .onion sites at multiple locations.
As with all of these, this conversation is open to better ideas and solutions.
cc/ @fakhrulKhir @TheBlueMatt
The text was updated successfully, but these errors were encountered: