This project is about creating a rudimentary market for cryptocurrencies. A class, name…
- User
This project is about creating a rudimentary market for cryptocurrencies. A class, name "Exchange", has public member functions that allow for the deposit and withdrawl of various assets (e.g. Bitcoin, Etherum and US Dollars). Orders to buy and sell assets at a specified price can also be made and the exchange will perform trades as possible to fulfill orders. Lastly, the exchange has a member function dedicated to printing out the current status of the exchange (i.e. what is in each user’s portfolio, what orders have been opened and filled, what trades have taken place, and what the current prices are for the assets being traded. The starter code has three header files and 4 implementation files. Some of these files have content in them already, but you are welcome to add, remove or change any part of the code given. Each test case will compile the implementation files and include the exchange.hpp and/or utility.hpp if it makes use of a class declared within. The useraccount files are not directly tested in the test cases, but they can be optionally used to store and manipulate information associated with a user’s account (as helper class(es) for the exchange). The provided main file is never used by any test cases, but it provides an example use of the exchange for your own testing purposes.
main.cpp: #include #include #include #include
#include "exchange.hpp" #include "useraccount.hpp" #include "utility.hpp"
int main() { std::cout << "start" << std::endl;
Exchange base; base.MakeDeposit("Nahum", "USD", 1000); base.MakeDeposit("Nahum", "ETH", 400); base.MakeDeposit("Dolson", "BTC", 100); base.MakeDeposit("Dolson", "USD", 7000); base.MakeDeposit("Enbody", "USD", 7000); base.MakeDeposit("Ofria", "BCH", 9); base.MakeWithdrawal("Dolson", "BTC", 10); base.PrintUserPortfolios(std::cout); std::cout << std::endl; Order o_n{"Nahum", "Buy", "BTC", 2, 22}; Order o_d{"Dolson", "Sell", "BTC", 3, 17}; std::cout << "Before 1st add order" << std::endl;
base.AddOrder(o_n); std::cout << "After 1st add order" << std::endl; base.PrintUsersOrders(std::cout);
std::cout << std::endl;
std::cout << "Before 2nd add order" << std::endl;
base.AddOrder(o_d);
std::cout << "After 2nd add order" << std::endl;
base.PrintTradeHistory(std::cout); std::cout << std::endl; base.PrintUserPortfolios(std::cout); std::cout << std::endl; base.PrintUsersOrders(std::cout); std::cout << std::endl; base.AddOrder({"Dolson", "Buy", "ETH", 10, 200}); base.AddOrder({"Enbody", "Buy", "ETH", 15, 300}); base.AddOrder({"Nahum", "Sell", "ETH", 20, 100});
base.PrintTradeHistory(std::cout); base.PrintUsersOrders(std::cout); base.AddOrder({"Nahum", "Sell", "ETH", 20, 1000}); base.AddOrder({"Dolson", "Sell", "ETH", 2, 250}); base.AddOrder({"Enbody", "Buy", "BTC", 1, 10}); base.PrintTradeHistory(std::cout); base.PrintUserPortfolios(std::cout); std::cout << std::endl << std::endl; base.PrintUsersOrders(std::cout); base.AddOrder({"Enbody", "Buy", "LTC", 1, 10}); base.AddOrder({"Ofria", "Sell", "BCH", 2, 55}); base.PrintBidAskSpread(std::cout);
- Assistant
MakeWithdrawal: this function should take a username, an asset, and an amount as input. It should check if the user has enough of the specified asset in their portfolio (i.e. not involved in any open orders) to withdraw the specified amount. If they do, the function should remove the specified amount from the user's portfolio and return true. If they do not, the function should return false without making any changes.
AddOrder: this function should take an Order object as input and try to execute the order according to the current state of the exchange's order book. If the order is a buy order, the function should try to match it with existing sell orders in the order book (starting with the lowest sell price). If the order is a sell order, the function should try to match it with existing buy orders in the order book (starting with the highest buy price). If there is a match, the function should execute the trade with the matched order, update the relevant portfolios (including the portfolios of the traders involved in the trade as well as the exchange's own portfolio), and add the executed trade to the exchange's trade history. If there is no match, the function should simply add the new order to the exchange's order book.
- User
Can you write out the code in the files I typed out?
- Assistant