Skip to content

Commit ac9ab0a

Browse files
authored
14 improve error logging (#18)
* Handle incorrect interval + switch to error * Fix interval in title of plot * Throw error instead of info * Bump patch version * Fix volume plot
1 parent 5c4fbe9 commit ac9ab0a

4 files changed

Lines changed: 24 additions & 12 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CoinbaseProExchange"
22
uuid = "06c3450d-869c-4596-88b4-6f9fb82f72bd"
33
authors = ["Vikas Negi <vikas.negi10@gmail.com>"]
4-
version = "1.1.1"
4+
version = "1.1.2"
55

66
[deps]
77
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/helper.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ function do_try_catch(endpoint::String, user_data::UserInfo, get_common_df)
4646
end
4747

4848
return df_data
49+
end
50+
51+
function closest_interval(interval::Int64)
52+
53+
_, closest_index = (GRANULARITY .- interval) .|> abs |> findmin
54+
55+
return GRANULARITY[closest_index]
56+
4957
end

src/plotpublic.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ julia> plot_historical_price("ETH-EUR", 86400)
3535
"""
3636
function plot_historical_price(pair::String, interval::Int64 = 300)
3737

38-
df_candles = show_historical_data(pair, interval)
38+
df_candles, closest_match = show_historical_data(pair, interval)
3939

4040
currency = split(pair, "-")[2]
4141

4242
plt = lineplot(
4343
df_candles[!, :time],
4444
df_candles[!, :close],
45-
title = "Closing price for $(pair) in intervals of $(interval) seconds",
45+
title = "Closing price for $(pair) in intervals of $(closest_match) seconds",
4646
xlabel = "Time",
4747
ylabel = "Closing price [$(currency)]",
4848
xticks = true,
@@ -96,14 +96,14 @@ julia> plot_historical_vol("ETH-EUR", 21600)
9696
"""
9797
function plot_historical_vol(pair::String, interval::Int64 = 300)
9898

99-
df_candles = show_historical_data(pair, interval)
99+
df_candles, closest_match = show_historical_data(pair, interval)
100100

101101
coin = split(pair, "-")[1]
102102

103103
plt = lineplot(
104104
df_candles[!, :time],
105105
df_candles[!, :volume],
106-
title = "Volume for $(pair) in intervals of $(interval) seconds",
106+
title = "Volume for $(pair) in intervals of $(closest_match) seconds",
107107
xlabel = "Time",
108108
ylabel = "Number of coins [$(coin)]",
109109
xticks = true,

src/showpublic.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function show_server_time(time_type::String = "iso")
2121
try
2222
server_time = get_server_time()
2323
catch
24-
@info "Unable to retrieve API server time"
24+
error("Unable to retrieve API server time")
2525
end
2626

2727
return server_time[time_type]
@@ -52,20 +52,24 @@ julia> show_historical_data("ETH-EUR", 3600)
5252
function show_historical_data(pair::String, interval::Int64 = 300)
5353

5454
df_candles = DataFrame()
55+
closest_match = interval
5556

5657
try
57-
df_candles = get_historical_data(pair::String, interval::Int64)
58+
df_candles = get_historical_data(pair, interval)
5859
catch e
5960
if isa(e, HTTP.ExceptionRequest.StatusError)
60-
@info "404 Not Found - Check if the pair ID is valid"
61+
error("404 Not Found - Check if the pair ID is valid")
6162
elseif isa(e, AssertionError)
62-
@info "Granularity is NOK, choose only from {60, 300, 900, 3600, 21600, 86400}."
63+
@warn("Granularity is NOK, choose only one from {60, 300, 900, 3600, 21600, 86400} seconds.")
64+
closest_match = closest_interval(interval)
65+
@info("Showing result for closest match $(closest_match)")
66+
df_candles = get_historical_data(pair, closest_match)
6367
else
64-
@info "Could not retrieve historical data, try again!"
68+
error("Could not retrieve historical data, try again!")
6569
end
6670
end
6771

68-
return df_candles
72+
return df_candles, closest_match
6973
end
7074

7175

@@ -99,7 +103,7 @@ function show_all_products(currency::String = "USD")
99103
end
100104

101105
if isempty(products)
102-
@info "No products exist for the given currency, try something else!"
106+
error("No products exist for the given currency, try something else!")
103107
else
104108
return products
105109
end

0 commit comments

Comments
 (0)