-
Notifications
You must be signed in to change notification settings - Fork 2
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 #263 from northwesternfintech/testing
Add full cpp integration test coverage
- Loading branch information
Showing
30 changed files
with
976 additions
and
160 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
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 was deleted.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
exchange/test/src/integration/test_algos/cpp/buy_market_order_1000.hpp
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,94 @@ | ||
#include <cstdint> | ||
|
||
#include <string> | ||
|
||
/** | ||
* Place a market order | ||
* | ||
* IMPORTANT: | ||
* You should handle the case where the order fails due to rate limiting | ||
* (maybe wait and try again?) | ||
* | ||
* @param side Side of the order to place ("BUY" or "SELL") | ||
* @param ticker Ticker of the order to place ("ETH", "BTC", or "LTC") | ||
* @param quantity Volume of the order to place | ||
* | ||
* @return true if order succeeded, false if order failed due to rate limiting | ||
*/ | ||
bool | ||
place_market_order(std::string const& side, std::string const& ticker, double quantity); | ||
|
||
/** | ||
* Place a limit order | ||
* | ||
* IMPORTANT: | ||
* You should handle the case where the order fails due to rate limiting | ||
* (maybe wait and try again?) | ||
* | ||
* @param side Side of the order to place ("BUY" or "SELL") | ||
* @param ticker Ticker of the order to place ("ETH", "BTC", or "LTC") | ||
* @param quantity Volume of the order to place | ||
* @param price Price of the order to place | ||
* @param ioc Immediate or cancel | ||
* | ||
* @return true if order succeeded, false if order failed due to rate limiting | ||
*/ | ||
std::int64_t place_limit_order( | ||
std::string const& side, std::string const& ticker, double quantity, double price, | ||
bool ioc = false | ||
); | ||
|
||
bool cancel_order(std::string const& ticker, std::int64_t order_id); | ||
|
||
class Strategy { | ||
public: | ||
Strategy() { place_market_order("BUY", "ETH", 5); } | ||
|
||
/** | ||
* Called whenever two orders match. Could be one of your orders, or two other | ||
* people's orders. | ||
* | ||
* @param ticker Ticker of the orders that were matched ("ETH", "BTC", or | ||
* "LTC) | ||
* @param side Side of the orders that were matched ("BUY" or "SELL") | ||
* @param price Price that trade was executed at | ||
* @quantity quantity Volume traded | ||
*/ | ||
void | ||
on_trade_update(std::string ticker, std::string side, double quantity, double price) | ||
{ | ||
if (ticker == "ETH" && price <= 101 && price >= 99 && quantity == 5) { | ||
place_limit_order("BUY", "BTC", 1, 100); | ||
} | ||
} | ||
|
||
/** | ||
* Called whenever the orderbook changes. This could be because of a trade, or | ||
* because of a new order, or both. | ||
* | ||
* @param ticker Ticker that has an orderbook update ("ETH", "BTC", or "LTC") | ||
* @param side Which orderbook as updated ("BUY" or "SELL") | ||
* @param price Price of orderbook that has an update | ||
* @param quantity Volume placed into orderbook | ||
*/ | ||
void | ||
on_orderbook_update( | ||
std::string ticker, std::string side, double quantity, double price | ||
) | ||
{} | ||
|
||
/** | ||
* Called whenever one of your orders is filled. | ||
* | ||
* @param ticker Ticker of order that was fulfilled ("ETH", "BTC", or "LTC") | ||
* @param side Side of order that was fulfilled ("BUY" or "SELL") | ||
* @param price Price that order was fulfilled at | ||
* @param quantity Amount of capital after fulfilling order | ||
*/ | ||
void | ||
on_account_update( | ||
std::string ticker, std::string side, double price, double quantity, | ||
double capital_remaining | ||
) | ||
{} | ||
}; |
95 changes: 95 additions & 0 deletions
95
exchange/test/src/integration/test_algos/cpp/buy_tsla_at_100_newline.hpp
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,95 @@ | ||
#include <cstdint> | ||
|
||
#include <string> | ||
|
||
/** | ||
* Place a market order | ||
* | ||
* IMPORTANT: | ||
* You should handle the case where the order fails due to rate limiting | ||
* (maybe wait and try again?) | ||
* | ||
* @param side Side of the order to place ("BUY" or "SELL") | ||
* @param ticker Ticker of the order to place ("ETH", "BTC", or "LTC") | ||
* @param quantity Volume of the order to place | ||
* | ||
* @return true if order succeeded, false if order failed due to rate limiting | ||
*/ | ||
bool | ||
place_market_order(std::string const& side, std::string const& ticker, double quantity); | ||
|
||
/** | ||
* Place a limit order | ||
* | ||
* IMPORTANT: | ||
* You should handle the case where the order fails due to rate limiting | ||
* (maybe wait and try again?) | ||
* | ||
* @param side Side of the order to place ("BUY" or "SELL") | ||
* @param ticker Ticker of the order to place ("ETH", "BTC", or "LTC") | ||
* @param quantity Volume of the order to place | ||
* @param price Price of the order to place | ||
* @param ioc Immediate or cancel | ||
* | ||
* @return true if order succeeded, false if order failed due to rate limiting | ||
*/ | ||
std::int64_t place_limit_order( | ||
std::string const& side, std::string const& ticker, double quantity, double price, | ||
bool ioc = false | ||
); | ||
|
||
bool cancel_order(std::string const& ticker, std::int64_t order_id); | ||
|
||
class Strategy { | ||
public: | ||
Strategy() = default; | ||
|
||
/** | ||
* Called whenever two orders match. Could be one of your orders, or two other | ||
* people's orders. | ||
* | ||
* @param ticker Ticker of the orders that were matched ("ETH", "BTC", or | ||
* "LTC) | ||
* @param side Side of the orders that were matched ("BUY" or "SELL") | ||
* @param price Price that trade was executed at | ||
* @quantity quantity Volume traded | ||
*/ | ||
void | ||
on_trade_update(std::string ticker, std::string side, double quantity, double price) | ||
{} | ||
|
||
/** | ||
* Called whenever the orderbook changes. This could be because of a trade, or | ||
* because of a new order, or both. | ||
* | ||
* @param ticker Ticker that has an orderbook update ("ETH", "BTC", or "LTC") | ||
* @param side Which orderbook as updated ("BUY" or "SELL") | ||
* @param price Price of orderbook that has an update | ||
* @param quantity Volume placed into orderbook | ||
*/ | ||
void | ||
on_orderbook_update( | ||
std::string ticker, std::string side, double quantity, double price | ||
) | ||
{ | ||
if (ticker == "ETH" && quantity < 101 && quantity > 99) { | ||
place_limit_order("BUY", "ETH\n", 100, 10); | ||
place_limit_order("BUY", "ETH", 100, 10); | ||
} | ||
} | ||
|
||
/** | ||
* Called whenever one of your orders is filled. | ||
* | ||
* @param ticker Ticker of order that was fulfilled ("ETH", "BTC", or "LTC") | ||
* @param side Side of order that was fulfilled ("BUY" or "SELL") | ||
* @param price Price that order was fulfilled at | ||
* @param quantity Amount of capital after fulfilling order | ||
*/ | ||
void | ||
on_account_update( | ||
std::string ticker, std::string side, double price, double quantity, | ||
double capital_remaining | ||
) | ||
{} | ||
}; |
Oops, something went wrong.