Market Making Made Simple

Photo by Chris Liverani on Unsplash

Being a trader has never been easy, being a successful trader is harder, and being a successful high-frequency trader is even harder. We are a group of thinkers and doers to (help you to) defy this convention. Cryptos were created to democratize currencies, crypto exchanges were created to democratize trading, and we created CryptoChassis to democratize high-frequency trading (HFT). In this post we will discuss one particular HFT category called market making and demonstrate that it isn’t a mystery and you can certainly do it.

Back a while ago we conducted a formal interview with one of our professional traders to understand the barrier of entering HFT from an end user point of view. At that moment his firm was trading Bitcoin (futures) based on classical signals and indicators with a medium-to-low trading frequency and their order executions were largely semi-manual. However, they wanted to move into HFT and particularly mentioned market making. The biggest pain point for them came from the automated order execution part and originated from the fact that signing (i.e. authenticating) an order request (submit, cancel, etc.) in C++ was a hard problem (BTW it isn’t an easy problem in any programming languages). Each exchange has its own unique signing protocol and it’s a pain in the ass to code it in C++ for one exchange let alone many exchanges. So they were actively looking for a library to make their life much easier. On Jan 5th 2021, we officially launched the execution management feature on our Github repo: https://github.com/crypto-chassis/ccapi_cpp.

If in the past you were intimidated when hearing about coding “execution engine” or “market making”, that should no longer be the case. Our library allows you to create, cancel, and query an order on a crypto exchange using about 5 lines of code from your side: a piece of cake even for a C++ beginner. The importance and relevance for professional traders is that you can devote much more time and efforts towards testing and refining clever trading strategies rather than debugging why an exchange has returned an illusive “invalid signature” error message. To demonstrate market making with our library, we have crafted an example: https://github.com/crypto-chassis/ccapi_cpp/blob/master/example/src/sample_market_making/main.cpp, Now let us summarize the code in its high-level skeletons to help beginners as well as gurus to understand it in just one glimpse:

class MyEventHandler : public EventHandler {
public:
bool processEvent(const Event& event, Session *session) override {
// If event is for market data, get best bid/ask price/size
bestBidPrice = element.getValue("BID_PRICE");
bestAskPrice = element.getValue("ASK_PRICE");
// If event is for execution management, act accordingly (e.g. order submission failure)
}
std::pair<std::string, std::string> getBBO() {
return std::make_pair(bestBidPrice, bestAskPrice);
}
private:
std::string bestBidPrice;
std::string bestAskPrice;
};

int main(int argc, char **argv) {
// Create a session to stream best bid/ask and submit/cancel orders
SessionOptions sessionOptions;
SessionConfigs sessionConfigs;
MyEventHandler eventHandler;
Session session(sessionOptions, sessionConfigs, &eventHandler);
Subscription subscription("coinbase", "BTC-USD", "MARKET_DEPTH");
session.subscribe(subscription);
// market making loop
while (true) {
Request requestCancel(Request::Operation::CANCEL_OPEN_ORDERS, "coinbase", "BTC-USD");
session.sendRequest(requestCancel);
auto bbo = eventHandler.getBBO();
// decide your market making bid/ask prices/quantities based on bbo and other factors
std::vector<Request> requestList;
Request requestBuy(Request::Operation::CREATE_ORDER, "coinbase", "BTC-USD");
requestBuy.appendParam({
{"SIDE", "BUY"},
{"QUANTITY", orderQuantity},
{"LIMIT_PRICE", buyPrice}
});
requestList.push_back(requestBuy);
Request requestSell(Request::Operation::CREATE_ORDER, "coinbase", "BTC-USD");
requestSell.appendParam({
{"SIDE", "SELL"},
{"QUANTITY", orderQuantity},
{"LIMIT_PRICE", sellPrice}
});
requestList.push_back(requestSell);
session.sendRequest(requestList);
take-a-nap :)
}
}

The distilled code shown above represents one of the simplest forms of market making (which some people called “pure market making”). What we have done is that:

  1. Obtain market data via subscription(“coinbase”, “BTC-USD”, “MARKET_DEPTH”).
  2. Decide our market making order prices based on the market data.
  3. Submit two orders to coinbase via two requests each carrying its SIDE, QUANTITY, and LIMIT_PRICE.

Compared to this lengthy documentation from coinbase, the code shown above certainly represents a significant time-saving. Our open-source library sends your orders (as well as your market data subscriptions) directly to the exchanges without any middleman: inspect the code if you have any doubt. From this example you can also clearly see that the two backbone features, i.e. order execution management and market data subscription, are seamlessly integrated in our library. You can pick and choose to use one component standalone or both at the same time. All in all we hope that our team has created something that is really useful for you. 🚋

Disclaimer: This is an educational post rather than investment/financial advice.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store