From 3fff76d40db0ead0732e239c352b211fd8553946 Mon Sep 17 00:00:00 2001 From: Balazs Toldi Date: Mon, 4 Jan 2021 20:42:17 +0100 Subject: [PATCH] Initial commit --- .gitignore | 192 +++++++++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 14 ++++ external/curl | 1 + external/jsoncpp | 1 + main.cpp | 51 +++++++++++++ 5 files changed, 259 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 160000 external/curl create mode 160000 external/jsoncpp create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3fcff76 --- /dev/null +++ b/.gitignore @@ -0,0 +1,192 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# -*- mode: gitignore; -*- +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ +dist/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el + +# network security +/network-security.data + +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +.idea +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ +build/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + + Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b6269ce --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.17) +project(TradeSim) + +set(CMAKE_CXX_STANDARD 14) + + + +add_subdirectory(external/curl) +add_subdirectory(external/jsoncpp) +add_executable(TradeSim main.cpp) +target_link_libraries(TradeSim libcurl) +target_link_libraries(TradeSim jsoncpp_lib) +include_directories(${CURL_INCLUDE_DIR}) +include_directories(${Jsoncpp_INCLUDE_DIR}) \ No newline at end of file diff --git a/external/curl b/external/curl new file mode 160000 index 0000000..aa8de5d --- /dev/null +++ b/external/curl @@ -0,0 +1 @@ +Subproject commit aa8de5d6ee457456ce665282d1bf5d74648683dc diff --git a/external/jsoncpp b/external/jsoncpp new file mode 160000 index 0000000..9409824 --- /dev/null +++ b/external/jsoncpp @@ -0,0 +1 @@ +Subproject commit 940982438d01fe2575acef8dd98a9b6893ccc9bb diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..adef0cb --- /dev/null +++ b/main.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +size_t writefunc(void *ptr, size_t size, size_t nmemb, std::string *s) +{ + s->append(static_cast(ptr), size*nmemb); + return size*nmemb; +} + +int main(void) +{ + CURL *curl; + CURLcode res; + + curl = curl_easy_init(); + if(curl) { + std::string s; + curl_easy_setopt(curl, CURLOPT_URL, "https://api3.binance.com/api/v3/trades?symbol=ETHEUR&limit=10"); + + + curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); + + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); + /* Perform the request, res will get the return code */ + + res = curl_easy_perform(curl); + + /* Check for errors */ + if(res != CURLE_OK) + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); + Json::Value root; + JSONCPP_STRING err; + Json::CharReaderBuilder builder; + const std::unique_ptr reader(builder.newCharReader()); + if (!reader->parse(s.c_str(), s.c_str() + s.length(), &root, + &err)) { + std::cout << "error" << std::endl; + return EXIT_FAILURE; + } + std::cout << root[0]["price"].asString() << std::endl; + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} \ No newline at end of file