Skip to content

Commit 21fa8cf

Browse files
committed
Change OKEX -> OKX, add support for Bitget checksums
1 parent efe43cb commit 21fa8cf

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### 0.4.2 (2022-04-17)
4+
* Update: OKEx renamed OKX (for checksum validation)
5+
* Feature: Add support for orderbook checksums with Bitget
6+
37
### 0.4.1 (2021-10-12)
48
* Bugfix: unnecessary reference counting prevented sorted dictionaries from being deallocated
59
* Bugfix: setting ordering on a sorted dict before checking that it was created successfully

orderbook/orderbook.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,16 @@ int Orderbook_init(Orderbook *self, PyObject *args, PyObject *kwds)
7676
PyErr_SetNone(PyExc_MemoryError);
7777
return -1;
7878
}
79-
} else if ((checksum_str.len > 3) && ((strncmp(checksum_str.buf, "OKEX", 4) == 0) || (strncmp(checksum_str.buf, "OKCO", 4) == 0))) {
80-
self->checksum = OKEX;
79+
} else if ((checksum_str.len > 2) && ((strncmp(checksum_str.buf, "OKX", 3) == 0) || (strncmp(checksum_str.buf, "OKCO", 4) == 0))) {
80+
self->checksum = OKX;
81+
self->checksum_buffer = calloc(4096, sizeof(uint8_t));
82+
self->checksum_len = 4096;
83+
if (!self->checksum_buffer) {
84+
PyErr_SetNone(PyExc_MemoryError);
85+
return -1;
86+
}
87+
} else if (strncmp(checksum_str.buf, "BITGET", checksum_str.len) == 0) {
88+
self->checksum = BITGET;
8189
self->checksum_buffer = calloc(4096, sizeof(uint8_t));
8290
self->checksum_len = 4096;
8391
if (!self->checksum_buffer) {
@@ -416,7 +424,7 @@ static PyObject* ftx_checksum(const Orderbook *ob, const uint32_t depth)
416424
PyObject *price = NULL;
417425
PyObject *size = NULL;
418426

419-
for(uint32_t i = 0; i < depth; ++i) { // 100 is the FTX defined number of price/size pairs to use from each side, 25 is OKEX/OKCOIN
427+
for(uint32_t i = 0; i < depth; ++i) { // 100 is the FTX defined number of price/size pairs to use from each side, 25 is OKX/OKCOIN
420428
if (i < bids_size) {
421429
price = PyTuple_GET_ITEM(ob->bids->keys, i);
422430
size = PyDict_GetItem(ob->bids->data, price);
@@ -457,7 +465,9 @@ static PyObject* calculate_checksum(const Orderbook *ob)
457465
return kraken_checksum(ob);
458466
case FTX:
459467
return ftx_checksum(ob, 100);
460-
case OKEX:
468+
case OKX:
469+
return ftx_checksum(ob, 25);
470+
case BITGET:
461471
return ftx_checksum(ob, 25);
462472
default:
463473
return NULL;

orderbook/orderbook.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ enum Checksums {
2121
CHECKSUM_PROCESSING_ERROR = -1,
2222
KRAKEN,
2323
FTX,
24-
OKEX,
24+
OKX,
25+
BITGET,
2526
INVALID_CHECKSUM_FORMAT
2627
};
2728

tests/test_checksums.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def test_kraken_checksum():
6060
assert ob.checksum() == 974947235
6161

6262

63-
def test_okex_checksum():
64-
ob = OrderBook(checksum_format='OKEX')
63+
def test_okx_checksum():
64+
ob = OrderBook(checksum_format='OKX')
6565

6666
asks = {Decimal("3366.8"): Decimal("9"), Decimal("3368"): Decimal("8"), Decimal("3372"): Decimal("8")}
6767
bids = {Decimal("3366.1"): Decimal("7")}

0 commit comments

Comments
 (0)