Skip to content

Commit 13ef7d2

Browse files
author
ubuntu
committed
update docs
1 parent 7d88456 commit 13ef7d2

1 file changed

Lines changed: 37 additions & 28 deletions

File tree

README.md

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@
4949
* [Thread safety](#thread-safety)
5050
* [Enable library logging](#enable-library-logging)
5151
* [Set timer](#set-timer)
52+
* [Heartbeat](#heartbeat)
5253
* [Performance Tuning](#performance-tuning)
5354
* [Known Issues and Workarounds](#known-issues-and-workarounds)
5455

5556
<!---toc end-->
5657

5758
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
5859

60+
5961
# ccapi
6062
* A header-only C++ library for streaming market data and executing trades directly from cryptocurrency exchanges (i.e. the connections are between your server and the exchange server without anything in-between).
6163
* Bindings for other languages such as Python, Java, C#, Go, and Javascript are provided.
@@ -848,30 +850,29 @@ class MyEventHandler : public EventHandler {
848850
MyEventHandler(const std::string& fixSubscriptionCorrelationId) : fixSubscriptionCorrelationId(fixSubscriptionCorrelationId) {}
849851
850852
void processEvent(const Event& event, Session* sessionPtr) override {
851-
if (event.getType() == Event::Type::AUTHORIZATION_STATUS) {
852-
std::cout << "Received an event of type AUTHORIZATION_STATUS:\n" + event.toPrettyString(2, 2) << std::endl;
853-
auto message = event.getMessageList().at(0);
854-
if (message.getType() == Message::Type::AUTHORIZATION_SUCCESS) {
853+
std::cout << "Received an event:\n" + event.toPrettyString(2, 2) << std::endl;
854+
if (!willSendRequest) {
855+
sessionPtr->setTimer("id", 1000, nullptr, [this, sessionPtr]() {
855856
Request request(Request::Operation::FIX, "binance");
856857
request.appendFixParam({
857858
{35, "D"},
858-
{11, "6d4eb0fb-2229-469f-873e-557dd78ac11e"},
859-
{55, "BTC-USD"},
859+
{11, request.generateNextClientOrderId()},
860+
{55, "BTCUSDT"},
860861
{54, "1"},
861-
{44, "20000"},
862-
{38, "0.001"},
862+
{44, "100000"},
863+
{38, "0.0001"},
863864
{40, "2"},
864865
{59, "1"},
865866
});
866867
sessionPtr->sendRequestByFix(this->fixSubscriptionCorrelationId, request);
867-
}
868-
} else if (event.getType() == Event::Type::FIX) {
869-
std::cout << "Received an event of type FIX:\n" + event.toPrettyString(2, 2) << std::endl;
868+
});
869+
willSendRequest = true;
870870
}
871871
}
872872
873873
private:
874874
std::string fixSubscriptionCorrelationId;
875+
bool willSendRequest{};
875876
};
876877
877878
} /* namespace ccapi */
@@ -893,17 +894,15 @@ int main(int argc, char** argv) {
893894
return EXIT_FAILURE;
894895
}
895896
SessionOptions sessionOptions;
896-
sessionOptions.heartbeatFixIntervalMilliseconds = 30000; // Note the unit is millisecond
897-
sessionOptions.heartbeatFixTimeoutMilliseconds = 5000; // Note the unit is millisecond, should be less than heartbeatFixIntervalMilliseconds
898897
SessionConfigs sessionConfigs;
899898
std::string fixSubscriptionCorrelationId("any");
900899
MyEventHandler eventHandler(fixSubscriptionCorrelationId);
901900
Session session(sessionOptions, sessionConfigs, &eventHandler);
902-
Subscription subscription("binance", "", "FIX", "8013=S&9406=Y",
903-
fixSubscriptionCorrelationId); // https://developers.binance.com/docs/binance-spot-api-docs/fix-api#logon-a
901+
Subscription subscription("binance", "", "FIX", "", fixSubscriptionCorrelationId);
904902
session.subscribe(subscription);
905903
std::this_thread::sleep_for(std::chrono::seconds(10));
906904
session.stop();
905+
std::cout << "Bye" << std::endl;
907906
return EXIT_SUCCESS;
908907
}
909908
```
@@ -917,12 +916,16 @@ Received an event:
917916
type = SESSION_CONNECTION_UP,
918917
recapType = UNKNOWN,
919918
time = 1970-01-01T00:00:00.000000000Z,
920-
timeReceived = 2025-08-02T05:32:27.276351820Z,
919+
timeReceived = 2025-08-08T18:50:06.816550779Z,
921920
elementList = [
922921
Element [
923922
tagValueList = [
924923

925-
]
924+
],
925+
nameValueMap = {
926+
CONNECTION_ID = IF8j4HbdLP0,
927+
CONNECTION_URL = tcp+tls://fix-oe.binance.com:9000
928+
}
926929
]
927930
],
928931
correlationIdList = [ any ],
@@ -937,15 +940,18 @@ Received an event:
937940
type = AUTHORIZATION_SUCCESS,
938941
recapType = UNKNOWN,
939942
time = 1970-01-01T00:00:00.000000000Z,
940-
timeReceived = 2025-08-02T05:32:27.279333577Z,
943+
timeReceived = 2025-08-08T18:50:06.819417404Z,
941944
elementList = [
942945
Element [
943946
tagValueList = [
944947
(35, "A"),
945948
(98, "0"),
946949
(108, "60"),
947-
(25037, "043bde93-187b-4791-ad8e-f82a9188dd1a")
948-
]
950+
(25037, "e9ed8253-8f49-4a1b-bba9-718ff73991e5")
951+
],
952+
nameValueMap = {
953+
954+
}
949955
]
950956
],
951957
correlationIdList = [ any ],
@@ -960,22 +966,22 @@ Received an event:
960966
type = FIX,
961967
recapType = UNKNOWN,
962968
time = 1970-01-01T00:00:00.000000000Z,
963-
timeReceived = 2025-08-02T05:32:28.280030845Z,
969+
timeReceived = 2025-08-08T18:50:07.820112736Z,
964970
elementList = [
965971
Element [
966972
tagValueList = [
967973
(35, "8"),
968-
(17, "99562025401"),
969-
(11, "x-XHKUG2CH-1754112748000"),
970-
(37, "46872802898"),
974+
(17, "100146443390"),
975+
(11, "x-XHKUG2CH-1754679007000"),
976+
(37, "47156106695"),
971977
(38, "0.00010000"),
972978
(40, "2"),
973979
(54, "1"),
974980
(55, "BTCUSDT"),
975981
(44, "100000.00000000"),
976982
(59, "1"),
977-
(60, "20250802-05:32:28.278968"),
978-
(25018, "20250802-05:32:28.278968"),
983+
(60, "20250808-18:50:07.819027"),
984+
(25018, "20250808-18:50:07.819027"),
979985
(25001, "3"),
980986
(150, "0"),
981987
(14, "0.00000000"),
@@ -985,8 +991,11 @@ Received an event:
985991
(32, "0.00000000"),
986992
(39, "0"),
987993
(636, "Y"),
988-
(25023, "20250802-05:32:28.278968")
989-
]
994+
(25023, "20250808-18:50:07.819027")
995+
],
996+
nameValueMap = {
997+
998+
}
990999
]
9911000
],
9921001
correlationIdList = [ any ],

0 commit comments

Comments
 (0)