Skip to content

Commit d3ed3bf

Browse files
authored
Merge pull request #324 from bitshares/feature/limit-order-update
Feature/limit order update
2 parents d416313 + 41addc7 commit d3ed3bf

File tree

5 files changed

+277
-9
lines changed

5 files changed

+277
-9
lines changed

bitsharesbase/objects.py

+42-1
Original file line numberDiff line numberDiff line change
@@ -454,5 +454,46 @@ def __init__(self, *args, **kwargs):
454454
elif id == 2:
455455
data = Block_id_predicate(o[1])
456456
else:
457-
raise ValueError("Unknown {}".format(self.__class__.name))
457+
raise ValueError("Unknown {}".format(self.__class__.__name__))
458+
super().__init__(data, id)
459+
460+
461+
class LimitOrderAutoAction(Static_variant):
462+
def __init__(self, o):
463+
class Create_take_profit_order_action(GrapheneObject):
464+
def __init__(self, *args, **kwargs):
465+
kwargs.update(args[0])
466+
super().__init__(
467+
OrderedDict(
468+
[
469+
("fee_asset_id", ObjectId(kwargs["fee_asset_id"], "asset")),
470+
("spread_percent", Uint16(kwargs["spread_percent"])),
471+
("size_percent", Uint16(kwargs["size_percent"])),
472+
(
473+
"expiration_seconds",
474+
Uint32(kwargs["expiration_seconds"]),
475+
),
476+
("repeat", Bool(kwargs["repeat"])),
477+
("extensions", Set([])),
478+
]
479+
)
480+
)
481+
482+
id = o[0]
483+
if id == 0:
484+
data = Create_take_profit_order_action(o[1])
485+
else:
486+
raise ValueError("Unknown {}".format(self.__class__.__name__))
458487
super().__init__(data, id)
488+
489+
490+
class LimitOrderCreateExtensions(Extension):
491+
def NestedLimitOrderAutoAction(value):
492+
if value:
493+
return Array([LimitOrderAutoAction(o) for o in value])
494+
else:
495+
return None
496+
497+
sorted_options = [
498+
("on_fill", NestedLimitOrderAutoAction),
499+
]

bitsharesbase/objecttypes.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@
2121
object_type["custom_authority"] = 17
2222
object_type["ticket"] = 18
2323
object_type["liquidity_pool"] = 19
24-
object_type["OBJECT_TYPE_COUNT"] = 19
24+
object_type["samet_fund"] = 20
25+
object_type["credit_offer"] = 21
26+
object_type["credit_deal"] = 22
27+
object_type["OBJECT_TYPE_COUNT"] = 22

bitsharesbase/operationids.py

+14
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@
6565
"liquidity_pool_deposit",
6666
"liquidity_pool_withdraw",
6767
"liquidity_pool_exchange",
68+
"samet_fund_create",
69+
"samet_fund_delete",
70+
"samet_fund_update",
71+
"samet_fund_borrow",
72+
"samet_fund_repay",
73+
"credit_offer_create",
74+
"credit_offer_delete",
75+
"credit_offer_update",
76+
"credit_offer_accept",
77+
"credit_deal_repay",
78+
"credit_deal_expired",
79+
"liquidity_pool_update",
80+
"credit_deal_update",
81+
"limit_order_update",
6882
]
6983
operations = {o: ops.index(o) for o in ops}
7084

bitsharesbase/operations.py

+106-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
Worker_initializer,
4646
isArgsThisClass,
4747
AssertPredicate,
48+
LimitOrderAutoAction,
49+
LimitOrderCreateExtensions,
4850
)
4951
from .operationids import operations
5052

@@ -386,7 +388,10 @@ def __init__(self, *args, **kwargs):
386388
("min_to_receive", Asset(kwargs["min_to_receive"])),
387389
("expiration", PointInTime(kwargs["expiration"])),
388390
("fill_or_kill", Bool(kwargs["fill_or_kill"])),
389-
("extensions", Set([])),
391+
(
392+
"extensions",
393+
LimitOrderCreateExtensions(kwargs["extensions"]),
394+
),
390395
]
391396
)
392397
)
@@ -1226,4 +1231,104 @@ def __init__(self, *args, **kwargs):
12261231
)
12271232

12281233

1234+
class Liquidity_pool_update(GrapheneObject):
1235+
def __init__(self, *args, **kwargs):
1236+
if isArgsThisClass(self, args):
1237+
self.data = args[0].data
1238+
else:
1239+
if len(args) == 1 and len(kwargs) == 0:
1240+
kwargs = args[0]
1241+
1242+
if kwargs.get("taker_fee_percent"):
1243+
taker_fee_percent = Optional(Uint16(kwargs["taker_fee_percent"]))
1244+
else:
1245+
taker_fee_percent = Optional(None)
1246+
1247+
if kwargs.get("withdrawal_fee_percent"):
1248+
withdrawal_fee_percent = Optional(
1249+
Uint16(kwargs["withdrawal_fee_percent"])
1250+
)
1251+
else:
1252+
withdrawal_fee_percent = Optional(None)
1253+
1254+
super().__init__(
1255+
OrderedDict(
1256+
[
1257+
("fee", Asset(kwargs["fee"])),
1258+
("account", ObjectId(kwargs["account"], "account")),
1259+
("pool", ObjectId(kwargs["pool"], "liquidity_pool")),
1260+
("taker_fee_percent", taker_fee_percent),
1261+
("withdrawal_fee_percent", withdrawal_fee_percent),
1262+
("extensions", Set([])),
1263+
]
1264+
)
1265+
)
1266+
1267+
1268+
class Credit_deal_update(GrapheneObject):
1269+
def __init__(self, *args, **kwargs):
1270+
if isArgsThisClass(self, args):
1271+
self.data = args[0].data
1272+
else:
1273+
if len(args) == 1 and len(kwargs) == 0:
1274+
kwargs = args[0]
1275+
super().__init__(
1276+
OrderedDict(
1277+
[
1278+
("fee", Asset(kwargs["fee"])),
1279+
("account", ObjectId(kwargs["account"], "account")),
1280+
("deal_id", ObjectId(kwargs["deal_id"], "credit_deal")),
1281+
("auto_repay", Uint8(kwargs["auto_repay"])),
1282+
("extensions", Set([])),
1283+
]
1284+
)
1285+
)
1286+
1287+
1288+
class Limit_order_update(GrapheneObject):
1289+
def __init__(self, *args, **kwargs):
1290+
if isArgsThisClass(self, args):
1291+
self.data = args[0].data
1292+
else:
1293+
if len(args) == 1 and len(kwargs) == 0:
1294+
kwargs = args[0]
1295+
1296+
if kwargs.get("new_price"):
1297+
new_price = Optional(Price(kwargs["new_price"]))
1298+
else:
1299+
new_price = Optional(None)
1300+
1301+
if kwargs.get("delta_amount_to_sell"):
1302+
delta_amount_to_sell = Optional(Asset(kwargs["delta_amount_to_sell"]))
1303+
else:
1304+
delta_amount_to_sell = Optional(None)
1305+
1306+
if kwargs.get("new_expiration"):
1307+
new_expiration = Optional(PointInTime(kwargs["new_expiration"]))
1308+
else:
1309+
new_expiration = Optional(None)
1310+
1311+
if kwargs.get("on_fill"):
1312+
on_fill = Optional(
1313+
Array([LimitOrderAutoAction(o) for o in kwargs["on_fill"]])
1314+
)
1315+
else:
1316+
on_fill = Optional(None)
1317+
1318+
super().__init__(
1319+
OrderedDict(
1320+
[
1321+
("fee", Asset(kwargs["fee"])),
1322+
("seller", ObjectId(kwargs["seller"], "account")),
1323+
("order", ObjectId(kwargs["order"], "limit_order")),
1324+
("new_price", new_price),
1325+
("delta_amount_to_sell", delta_amount_to_sell),
1326+
("new_expiration", new_expiration),
1327+
("on_fill", on_fill),
1328+
("extensions", Set([])),
1329+
]
1330+
)
1331+
)
1332+
1333+
12291334
fill_classmaps()

tests/test_transactions.py

+111-6
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,29 @@ def test_limit_order_create(self):
8383
"min_to_receive": {"amount": 10000, "asset_id": "1.3.105"},
8484
"expiration": "2016-05-18T09:22:05",
8585
"fill_or_kill": False,
86-
"extensions": [],
86+
"extensions": {
87+
"on_fill": [
88+
[
89+
0,
90+
{
91+
"fee_asset_id": "1.3.0",
92+
"spread_percent": 100,
93+
"size_percent": 1000,
94+
"expiration_seconds": 3600,
95+
"repeat": True,
96+
"extensions": [],
97+
},
98+
]
99+
]
100+
},
87101
}
88102
)
89103
self.cm = (
90-
"f68585abf4dce7c8045701016400000000000000001da08601000"
91-
"0000000001027000000000000693d343c57000000011f75cbfd49"
92-
"ae8d9b04af76cc0a7de8b6e30b71167db7fe8e2197ef9d858df18"
93-
"77043493bc24ffdaaffe592357831c978fd8a296b913979f106de"
94-
"be940d60d77b50"
104+
"f68585abf4dce7c8045701016400000000000000001da0860100000"
105+
"00000001027000000000000693d343c570001000100006400e80310"
106+
"0e0000010000011f5ddffd232fd713e106aec3068646f5a74ae145e"
107+
"08e1e13f7464885a507e808e365594f5e7c14049d9432bcf1ca2330"
108+
"a65d1b7ab88aa08b355970ca6f23e06aa0"
95109
)
96110
self.doit()
97111

@@ -1045,6 +1059,97 @@ def test_assert_b(self):
10451059
)
10461060
self.doit(0)
10471061

1062+
def test_limit_order_update(self):
1063+
self.op = operations.Limit_order_update(
1064+
**{
1065+
"fee": {"amount": 0, "asset_id": "1.3.0"},
1066+
"seller": "1.2.4",
1067+
"order": "1.7.12535",
1068+
"extensions": [],
1069+
}
1070+
)
1071+
self.cm = (
1072+
"f68585abf4dce7c80457014d00000000000000000004f76100"
1073+
"0000000000011f06d0b4467a5916ffb3d8ef4261c0719b1fb0"
1074+
"964aa5d3fbecbfbcbc9fe1117bc20e8a2c3f87e7817b83446c"
1075+
"45deb2a0d3d5b8b0d3b22fc8076ffc8eeb1a95e928"
1076+
)
1077+
self.doit(0)
1078+
1079+
self.op = operations.Limit_order_update(
1080+
**{
1081+
"fee": {"amount": 0, "asset_id": "1.3.0"},
1082+
"seller": "1.2.4",
1083+
"order": "1.7.12535",
1084+
"new_price": {
1085+
"base": {"amount": 1123456, "asset_id": "1.3.0"},
1086+
"quote": {"amount": 78901122, "asset_id": "1.3.0"},
1087+
},
1088+
"delta_amount_to_sell": {"amount": 12562, "asset_id": "1.3.0"},
1089+
"new_expiration": "2023-12-18T09:22:05",
1090+
"on_fill": [
1091+
[
1092+
0,
1093+
{
1094+
"fee_asset_id": "1.3.0",
1095+
"spread_percent": 100,
1096+
"size_percent": 1000,
1097+
"expiration_seconds": 3600,
1098+
"repeat": True,
1099+
"extensions": [],
1100+
},
1101+
]
1102+
],
1103+
"extensions": [],
1104+
}
1105+
)
1106+
self.cm = (
1107+
"f68585abf4dce7c80457014d00000000000000000004f76101"
1108+
"80241100000000000082efb304000000000001123100000000"
1109+
"000000013d0f8065010100006400e803100e00000100000001"
1110+
"2051a24fb550e4a8ec890ad404ea0e3cf6ea449d6ba397d280"
1111+
"64f7129153dd013e27846eb6567a88d8eea7557f32ddc02cdc"
1112+
"a614c5a30130c83141c4050ffc50e2"
1113+
)
1114+
self.doit()
1115+
1116+
def test_liquidity_pool_update(self):
1117+
self.op = operations.Liquidity_pool_update(
1118+
**{
1119+
"fee": {"amount": 0, "asset_id": "1.3.0"},
1120+
"account": "1.2.4",
1121+
"pool": "1.19.13356",
1122+
"taker_fee_percent": 124,
1123+
"withdrawal_fee_percent": 125,
1124+
"extensions": [],
1125+
}
1126+
)
1127+
self.cm = (
1128+
"f68585abf4dce7c80457014b00000000000000000004ac6801"
1129+
"7c00017d00000001202e3f140515ce936020348f845a4c034b"
1130+
"164441049dfe0a59a6c0fe27cbef740c10fa0d315e14e77e62"
1131+
"d8dae4f45d95fef358ff79f5304a420d6fc13abfd9374b"
1132+
)
1133+
self.doit(0)
1134+
1135+
def test_credit_deal_update(self):
1136+
self.op = operations.Credit_deal_update(
1137+
**{
1138+
"fee": {"amount": 0, "asset_id": "1.3.0"},
1139+
"account": "1.2.4",
1140+
"deal_id": "1.22.2356",
1141+
"auto_repay": 24,
1142+
"extensions": [],
1143+
}
1144+
)
1145+
self.cm = (
1146+
"f68585abf4dce7c80457014c00000000000000000004b41218"
1147+
"0000012026b59b7796cb9ca40d92b1d339558a94aa9f70d2f6"
1148+
"d8a7b8b0155c943b89bd602a1ecc9df3143664f801f401a728"
1149+
"78cce9f064dbcfc1af65826ce68a2177a38d"
1150+
)
1151+
self.doit()
1152+
10481153
def compareConstructedTX(self):
10491154
self.maxDiff = None
10501155
self.op = operations.Call_order_update(

0 commit comments

Comments
 (0)