Skip to content

Commit

Permalink
feat(stock-market): update mock-stock-data-server
Browse files Browse the repository at this point in the history
- change port to avoid conflicts with defaults on macos
- update .gitignore to exclude expanded stock data
- remove repeated if statement in utils.py
- remove comments
  • Loading branch information
nprimo committed Aug 14, 2023
1 parent 2841ba3 commit 99a55ec
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

sample-stocks/
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
IMAGE_NAME="stock-server"
SERVER_PORT=5000
PUBLIC_PORT=5000
SERVER_PORT=5001
PUBLIC_PORT=5001

sample-stocks:
tar xf sample-stocks.zip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Below an example on how to use it (remember that the server needs to be running
locally).

```shell
$ curl -s localhost:5000/stocks_list | jq | head
$ curl -s localhost:5001/stocks_list | jq | head
[
"BRID",
"WRB",
Expand All @@ -42,9 +42,9 @@ $ curl -s localhost:5000/stocks_list | jq | head
"UMBF",
"MTRN",
"UNT",
$ curl localhost:5000/exchange_rate/WRB
$ curl localhost:5001/exchange_rate/WRB
{"rate":0.12680993974208832,"symbol":"USD","timestamp":1691667858.912409}
$ curl localhost:5000/exchange_rate/BRID
$ curl localhost:5001/exchange_rate/BRID
{"rate":0.38091352581977844,"symbol":"USD","timestamp":1691667862.3328483}
$
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

start_time = time.time()

historical_data = load_historical_data() # Dictionary to store historical data
historical_data = load_historical_data()

@app.route('/exchange_rate/<symbol>')
def get_stock_data(symbol):
Expand All @@ -32,4 +32,4 @@ def list_symbols():


if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
app.run(host='0.0.0.0', port=5001)
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ def load_historical_data(directory_path='./sample-stocks/'):

file_list = [filename for filename in os.listdir(directory_path) if filename.endswith(".csv")]
for filename in file_list:
if filename.endswith(".csv"):
symbol = filename.replace(".csv", "")

historical_data[symbol] = {}
file_path = os.path.join(directory_path, filename)
with open(file_path, 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)
historical_data[symbol] = [row['Close'] for row in csv_reader]
symbol = filename.replace(".csv", "")

historical_data[symbol] = {}
file_path = os.path.join(directory_path, filename)
with open(file_path, 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)
historical_data[symbol] = [row['Close'] for row in csv_reader]

return historical_data

Expand Down

0 comments on commit 99a55ec

Please sign in to comment.