Skip to content

Commit

Permalink
feat: Add support for fetching crypto prices using ticker symbol (#13)
Browse files Browse the repository at this point in the history
* feat: add ticker parameter, separate fetch_price & fetch_single_price function

* feat: add new function header

* feat: Discord bot add select menu handler for multiple coin with same ticker

* chore(deps): bump DPP v10.1.0

* docs: update available command
  • Loading branch information
heronimus authored Feb 18, 2025
1 parent f520774 commit 10e0741
Show file tree
Hide file tree
Showing 6 changed files with 365 additions and 135 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ option(USE_EXTERNAL_DPP "Use an external DPP library" ON)
option(USE_EXTERNAL_JSON "Use an external JSON library" ON)

if(USE_EXTERNAL_DPP)
find_package(dpp 10.0.23 REQUIRED)
find_package(dpp 10.1.0 REQUIRED)
else()
FetchContent_Declare(
dpp
GIT_REPOSITORY https://github.com/brainboxdotcc/DPP.git
GIT_TAG v10.0.23
GIT_TAG v10.1.0
)
FetchContent_MakeAvailable(dpp)
endif()
Expand Down Expand Up @@ -64,3 +64,6 @@ set_target_properties(${PROJECT_NAME} PROPERTIES

#Set Linker flags
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")

# Generate compile_commands.json automatically for clangd
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN mkdir build

# Build the project
WORKDIR /app/build
RUN wget -O libdpp.deb https://github.com/brainboxdotcc/DPP/releases/download/v10.0.23/libdpp-10.0.23-linux-x64.deb \
RUN wget -O libdpp.deb https://github.com/brainboxdotcc/DPP/releases/download/v10.1.0/libdpp-10.1.0-linux-x64.deb \
&& dpkg -i libdpp.deb \
&& ldconfig
RUN cmake -DUSE_EXTERNAL_JSON=OFF .. -B./ && make
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ docker compose -f docker-compose.yml up
### Build

#### Build Using External Precompiled Dependency (Recommended)
- Install Precompiled Lib (Debian, Ubuntu, Derivatives), check [this link](https://dpp.dev/10.0.23/md_docpages_01_installing.html) for other distro.
- Install Precompiled Lib (Debian, Ubuntu, Derivatives), check [this link](https://dpp.dev/installing.html) for other distro.

DPP:
```
Expand Down Expand Up @@ -64,6 +64,19 @@ docker compose -f docker-compose.yml up
make
```

### Available Commands

The bot supports the following slash commands:

#### Price Query
Get cryptocurrency prices in USD and IDR:
- Using CoinGecko ID: `/price coingecko_id:bitcoin`
- Using ticker symbol: `/price ticker:btc` or `/price ticker:$BTC`

Note: When multiple coins share the same ticker (e.g., "ETH" for both Ethereum and Ethereum Classic),
a dropdown menu will appear allowing you to select the specific coin.


### Additional
- In case you're got error while trying `make` that caused by `curl` try install it first. ex: `sudo apt-get install libcurl4-openssl-dev`

Expand Down
11 changes: 5 additions & 6 deletions include/coingecko.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
#include "nlohmann/json.hpp"

namespace gecko {

void fetch_tokens(dpp::slashcommand_t event);
void fetch_price(dpp::slashcommand_t event);
void fetch_market_chart(dpp::slashcommand_t event);
size_t write_callback(char* ptr, size_t size, size_t nmemb, std::string* data);

void fetch_tokens(dpp::slashcommand_t event);
void fetch_price(dpp::slashcommand_t event);
void fetch_single_price(const std::string& coingecko_id, const dpp::interaction_create_t& event);
void fetch_market_chart(dpp::slashcommand_t event);
size_t write_callback(char* ptr, size_t size, size_t nmemb, std::string* data);
} // namespace gecko
Loading

0 comments on commit 10e0741

Please sign in to comment.