Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
SPX (Systems Programming Exchange) is a marketplace that enables highly sought after computer components to be traded amongst seasoned computer programmers. Traditionally, trading is inperson, however due to COVID-19 restrictions trading must now be done remotely.
Your task is to implement a new system for SPX that allows trading to take place electronically. This consists of two parts, the exchange (handles orders) and an auto-trader (a program which trades based on predefifined conditions).
You are encouraged to ask questions on Ed using the assignments category. As with any assignment,make sure that your work is your own, and you do not share your code or solutions with other students.
To complete this assignment, you should be familiar with:
The purpose of the SPX is to allow trading to happen in an effificient and orderly manner. It receives orders from traders and matches them, allowing the buying and selling of computer components.
The exchange also tracks the cash balance of each trader (which starts at $0 for each trading session).
For providing such trading avenue, SPX collects a 1% transaction fee on all successful orders.
The exchange communicates with trader processes using a combination of named pipes (FIFOs) and signals. All messages are followed by the delimiter ; and signal SIGUSR1.
All messages sent through FIFOs are highlighted in this document:
EXAMPLE;
Traders carry out their buying and selling activities by placing orders on the exchange.
The following commands may be sent from traders to the exchange:
BUY <ORDER_ID> <PRODUCT> <QTY> <PRICE>;
SELL <ORDER_ID> <PRODUCT> <QTY> <PRICE>;
AMEND <ORDER_ID> <QTY> <PRICE>;
CANCEL <ORDER_ID>;
Order ID is unique per Trader (i.e. Trader 0 and 1 can both have their own Order ID 0). Order IDs are not reused (with the exception of Invalid orders, which can be fifixed and re-sent with the same ID, given the next ID is not yet used).
Products traded on the exchange are provided through a text fifile of the following structure:
n_items
Product 1
Product 2
…
Product N
For example:
2
GPU
Motherboard
Write programs in C that implement SPX as shown in the examples.
You are guaranteed not to have NULL returned from malloc() or realloc() in this context.
Your submission must be contained in the following fifiles and produce no errors when built and run on Ed C compiler.
Read / write with FIFOs and/or write to stdout as instructed.
Your program output must match the exact output format shown in the examples and on Ed. You are encouraged to submit your assignment while you are working on it, so you can obtain feedback.
You may modify any of the existing scaffold fifiles, or make your own.
No external code outside the standard C library functions should be required.
In order to obtain full marks, your program must free all of the dynamic memory it allocates.
The exchange accepts command line arguments as follows:
./spx_exchange [product file] [trader 0] [trader 1] … [trader n]
The following example uses a product fifile named products.txt and trader binaries trader_a and trader_b:
./spx_exchange products.txt ./trader_a ./trader_b
Upon start up, the exchange should read the product fifile to fifind out about what it will trade. It should then create two named pipes for each trader:
/tmp/spx_exchange_<Trader ID>
/tmp/spx_trader_<Trader ID>
The spx_exchange_* named pipes are for the exchange write to each trader and spx_trader_* named pipes are for each trader to write to the exchange.
After both pipes are created for a trader, the exchange shall launch that trader binary as a new child process, assigning it a trader ID starting from 0, in the Command Line Argument order. The trader ID shall be passed to the trader binary as a command line argument.
For the example above, the trader binaries should be launched like so:
./trader_a 0
./trader_b 1
Upon launching each binary, the exchange and trader should attempt to connect to both named pipes.
After all binaries are launched and pipes are connected, the exchange should send each trader (lowest trader IDs fifirst) the following message using the spx_exchange_* named pipes; afterwards, notify each trader using the SIGUSR1 signal.