-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from crypto-chassis/execution_management
Execution management
- Loading branch information
Showing
31 changed files
with
935 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ on: | |
- master | ||
jobs: | ||
release: | ||
timeout-minutes: 5 | ||
name: release | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
set(NAME execution_management_simple) | ||
project(${NAME}) | ||
add_definitions(-DENABLE_SERVICE_EXECUTION_MANAGEMENT) | ||
add_definitions(-DENABLE_EXCHANGE_BINANCE_US) | ||
add_executable(${NAME} main.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,87 @@ | ||
// #include "ccapi_cpp/ccapi_session.h" | ||
// namespace ccapi { | ||
// class ExampleLogger final: public Logger { | ||
// public: | ||
// void logMessage(Logger::Severity severity, std::thread::id threadId, | ||
// std::chrono::system_clock::time_point time, | ||
// std::string fileName, int lineNumber, | ||
// std::string message) override { | ||
// lock.lock(); | ||
// std::cout << threadId << ": [" << UtilTime::getISOTimestamp(time) << "] {" | ||
// << fileName << ":" << lineNumber << "} " | ||
// << Logger::severityToString(severity) << std::string(8, ' ') << message | ||
// << std::endl; | ||
// lock.unlock(); | ||
// } | ||
// private: | ||
// std::mutex lock; | ||
// }; | ||
// Logger* Logger::logger = 0; // This line is needed. | ||
// class MyEventHandler : public EventHandler { | ||
// bool processEvent(const Event& event, Session *session) override { | ||
// CCAPI_LOGGER_TRACE(toString(event)); | ||
// return true; | ||
// } | ||
// }; | ||
// } /* namespace ccapi */ | ||
// int main(int argc, char** argv) { | ||
// using namespace ccapi; // NOLINT(build/namespaces) | ||
// ExampleLogger exampleLogger; | ||
// Logger::logger = &exampleLogger; | ||
// SessionOptions sessionOptions; | ||
// SessionConfigs sessionConfigs; | ||
// MyEventHandler eventHandler; | ||
// Session session(sessionOptions, sessionConfigs, &eventHandler); | ||
// Request::Operation operation = Request::Operation::CREATE_ORDER; | ||
// std::map<std::string, std::string> credential = { | ||
// {BINANCE_US_API_KEY, UtilSystem::getEnvAsString(BINANCE_US_API_KEY)}, | ||
// {BINANCE_US_API_SECRET, UtilSystem::getEnvAsString(BINANCE_US_API_SECRET)} | ||
// }; | ||
// CorrelationId correlationId("this is my correlation id"); | ||
// Request request(operation, credential, CCAPI_EXCHANGE_NAME_BINANCE_US, "ETHUSD", correlationId); | ||
// request.setParam(CCAPI_EM_SIDE, CCAPI_EM_SIDE_BUY); | ||
// request.setParam(CCAPI_EM_QUANTITY, "0.04"); | ||
// request.setParam(CCAPI_EM_LIMIT_PRICE, "300"); | ||
// Queue<Event> eventQueue; | ||
// session.sendRequest(request, &eventQueue); | ||
// std::vector<Event> eventList = eventQueue.purge(); | ||
// CCAPI_LOGGER_TRACE("eventList = "+toString(eventList)); | ||
// return EXIT_SUCCESS; | ||
// } | ||
#include "ccapi_cpp/ccapi_session.h" | ||
namespace ccapi { | ||
Logger* Logger::logger = nullptr; // This line is needed. | ||
class MyEventHandler : public EventHandler { | ||
bool processEvent(const Event& event, Session *session) override { | ||
std::cout << "Received an event: " + toString(event) << std::endl; | ||
return true; | ||
} | ||
}; | ||
} /* namespace ccapi */ | ||
int main(int argc, char** argv) { | ||
using namespace ccapi; // NOLINT(build/namespaces) | ||
std::vector<std::string> modeList = { "create_order", "cancel_order", "get_order", "get_open_orders", | ||
"cancel_open_orders" }; | ||
if (argc < 2 || std::find(modeList.begin(), modeList.end(), argv[1]) == modeList.end()) { | ||
std::cerr << "Please provide the first command line argument from this list: " + toString(modeList) << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
std::string mode(argv[1]); | ||
std::string key = UtilSystem::getEnvAsString("BINANCE_US_API_KEY"); | ||
if (key.empty()) { | ||
std::cerr << "Please provide environment variable BINANCE_US_API_KEY" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
std::string secret = UtilSystem::getEnvAsString("BINANCE_US_API_SECRET"); | ||
if (secret.empty()) { | ||
std::cerr << "Please provide environment variable BINANCE_US_API_SECRET" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
std::map<std::string, std::string> credential = { { CCAPI_BINANCE_US_API_KEY, key }, { CCAPI_BINANCE_US_API_SECRET, | ||
secret } }; | ||
SessionOptions sessionOptions; | ||
SessionConfigs sessionConfigs; | ||
MyEventHandler eventHandler; | ||
Session session(sessionOptions, sessionConfigs, &eventHandler); | ||
Queue<Event> eventQueue; | ||
if (mode == "create_order") { | ||
if (argc != 6) { | ||
std::cerr << "Usage: <program name> create_order <symbol> <buy or sell> <order quantity> <limit price>\n" | ||
<< "Example:\n" << " main create_order BTCUSD buy 0.0005 20000" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
Request request(Request::Operation::CREATE_ORDER, credential, "binance-us", argv[2]); | ||
request.setParam("SIDE", strcmp(argv[3], "buy") == 0 ? "BUY" : "SELL"); | ||
request.setParam("QUANTITY", argv[4]); | ||
request.setParam("LIMIT_PRICE", argv[5]); | ||
session.sendRequest(request, &eventQueue); | ||
} else if (mode == "cancel_order") { | ||
if (argc != 4) { | ||
std::cerr << "Usage: <program name> cancel_order <symbol> <order id>\n" << "Example:\n" | ||
<< " main cancel_order BTCUSD 4" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
Request request(Request::Operation::CANCEL_ORDER, credential, "binance-us", argv[2]); | ||
request.setParam("ORDER_ID", argv[3]); | ||
session.sendRequest(request, &eventQueue); | ||
} else if (mode == "get_order") { | ||
if (argc != 4) { | ||
std::cerr << "Usage: <program name> get_order <symbol> <order id>\n" << "Example:\n" | ||
<< " main get_order BTCUSD 4" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
Request request(Request::Operation::GET_ORDER, credential, "binance-us", argv[2]); | ||
request.setParam("ORDER_ID", argv[3]); | ||
session.sendRequest(request, &eventQueue); | ||
} else if (mode == "get_open_orders") { | ||
if (argc != 3) { | ||
std::cerr << "Usage: <program name> get_open_orders <symbol>\n" << "Example:\n" | ||
<< " main get_open_orders BTCUSD" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
Request request(Request::Operation::GET_OPEN_ORDERS, credential, "binance-us", argv[2]); | ||
session.sendRequest(request, &eventQueue); | ||
} else if (mode == "cancel_open_orders") { | ||
if (argc != 3) { | ||
std::cerr << "Usage: <program name> cancel_open_orders <symbol>\n" << "Example:\n" | ||
<< " main cancel_open_orders BTCUSD" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
Request request(Request::Operation::CANCEL_OPEN_ORDERS, credential, "binance-us", argv[2]); | ||
session.sendRequest(request, &eventQueue); | ||
} | ||
std::this_thread::sleep_for(std::chrono::seconds(10)); | ||
session.stop(); | ||
std::cout << "Bye" << std::endl; | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
project(market_data_advanced) | ||
set(NAME market_data_advanced) | ||
project(${NAME}) | ||
add_definitions(-DENABLE_SERVICE_MARKET_DATA) | ||
add_definitions(-DENABLE_EXCHANGE_COINBASE) | ||
add_definitions(-DENABLE_EXCHANGE_BINANCE_US) | ||
file(GLOB SOURCES main.cpp) | ||
add_executable(market_data_advanced ${SOURCES}) | ||
add_executable(${NAME} main.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
project(market_data_simple) | ||
set(NAME market_data_simple) | ||
project(${NAME}) | ||
add_definitions(-DENABLE_SERVICE_MARKET_DATA) | ||
add_definitions(-DENABLE_EXCHANGE_COINBASE) | ||
file(GLOB SOURCES main.cpp) | ||
add_executable(market_data_simple ${SOURCES}) | ||
add_executable(${NAME} main.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
project(sample_market_making) | ||
set(NAME sample_market_making) | ||
project(${NAME}) | ||
add_definitions(-DENABLE_SERVICE_MARKET_DATA) | ||
add_definitions(-DENABLE_SERVICE_EXECUTION_MANAGEMENT) | ||
add_definitions(-DENABLE_EXCHANGE_BINANCE_US) | ||
file(GLOB SOURCES main.cpp) | ||
add_executable(sample_market_making ${SOURCES}) | ||
add_executable(${NAME} main.cpp) |
Oops, something went wrong.