Skip to content

Commit

Permalink
Add: Modify/Cancel Order
Browse files Browse the repository at this point in the history
  • Loading branch information
dung1t authored Sep 19, 2024
1 parent e1bc61b commit 201bfcf
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 5 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ print(broker.api.place_derivative_order(
account_no="6666668", side="BUY", instrument="VN30F2409", quantity=1, price=1000)
)

# Modify Order
print(broker.api.modify_equity_order(
account_no="6666661", order_id="123456", side="BUY", instrument="SSI", quantity=100, price=31)
)
print(broker.api.modify_derivative_order(
account_no="6666668", order_id="123456", side="BUY", instrument="VN30F2409", quantity=1, price=1000)
)

# Cancel Order
print(broker.api.cancel_equity_order(
account_no="6666661", order_id="123456", side="BUY", instrument="SSI")
)
print(broker.api.cancel_derivative_order(
account_no="6666668", order_id="123456", side="BUY", instrument="VN30F2409")
)
```

### Streaming order
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "vbroker"
version = "0.1.5"
version = "0.1.6"
license = "MIT"
description = "vBroker: A Python wrapper for Viet Nam Broker API"
repository = "https://github.com/quant-vn/vbroker"
Expand Down
14 changes: 14 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,17 @@
print(broker.api.place_derivative_order(
account_no="6666668", side="BUY", instrument="VN30F2409", quantity=1, price=1000)
)

print(broker.api.modify_equity_order(
account_no="6666661", order_id="123456", side="BUY", instrument="SSI", quantity=100, price=31)
)
print(broker.api.modify_derivative_order(
account_no="6666668", order_id="123456", side="BUY", instrument="VN30F2409", quantity=1, price=1000)
)

print(broker.api.cancel_equity_order(
account_no="6666661", order_id="123456", side="BUY", instrument="SSI")
)
print(broker.api.cancel_derivative_order(
account_no="6666668", order_id="123456", side="BUY", instrument="VN30F2409")
)
26 changes: 26 additions & 0 deletions vbroker/interface_broker_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ def place_equity_order(
) -> dict:
return NotImplemented

@abstractmethod
def modify_equity_order(
self, account_no: str, order_id: str,
side: str, instrument: str, quantity: int, price: float
) -> dict:
return NotImplemented

@abstractmethod
def cancel_equity_order(
self, account_no: str, order_id: str, nstrument: str, side: str
) -> dict:
return NotImplemented

# DERIVATIVES
@abstractmethod
def get_derivative_positions(self, account_no: str) -> dict:
Expand All @@ -69,3 +82,16 @@ def place_derivative_order(
self, account_no: str, side: str, instrument: str, quantity: int, price: float
) -> dict:
return NotImplemented

@abstractmethod
def modify_derivative_order(
self, account_no: str, order_id: str,
side: str, instrument: str, quantity: int, price: float
) -> dict:
return NotImplemented

@abstractmethod
def cancel_derivative_order(
self, account_no: str, order_id: str, instrument: str, side: str
) -> dict:
return NotImplemented
116 changes: 112 additions & 4 deletions vbroker/ssi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ def place_equity_order(
data: dict = {}
data.update(
account=account_no,
requestID="4",
requestID="25",
instrumentID=instrument,
market="VN",
buySell='B' if side == 'BUY' else 'S',
orderType="MP",
price=0,
orderType="LO",
price=3300,
quantity=quantity,
stopOrder=False,
stopPrice=0.0,
Expand All @@ -267,6 +267,60 @@ def place_equity_order(
)
return res

def modify_equity_order(
self, account_no: str, order_id: str,
side: str, instrument: str, quantity: int, price: float
) -> dict:
data: dict = {}
data.update(
account=account_no,
requestID="MODIFY1",
orderID=order_id,
marketID="VN",
instrumentID=instrument,
price=300,
quantity=quantity,
buySell='B' if side == 'BUY' else 'S',
orderType="LO",
code="",
deviceId=":".join([str(i) for i in range(11, 17)]),
userAgent=""
)
data_signed = sign(json.dumps(data), self.config.ssi_broker_private_key)
self.__headers.update({
"Authorization": self.get_token(),
"X-Signature": data_signed,
})
res = request_handler.post(
url=self.url_equity_modify_order, headers=self.__headers, data=data, limit=self.wait
)
return res

def cancel_equity_order(
self, account_no: str, order_id: str, instrument: str, side: str
) -> dict:
data: dict = {}
data.update(
account=account_no,
requestID="CANCEL1",
orderID=order_id,
marketID="VN",
instrumentID=instrument,
buySell='B' if side == 'BUY' else 'S',
code="",
deviceId=":".join([str(i) for i in range(11, 17)]),
userAgent=""
)
data_signed = sign(json.dumps(data), self.config.ssi_broker_private_key)
self.__headers.update({
"Authorization": self.get_token(),
"X-Signature": data_signed,
})
res = request_handler.post(
url=self.url_equity_cancel_order, headers=self.__headers, data=data, limit=self.wait
)
return res

# DERIVATIVES
def get_derivative_positions(self, account_no: str) -> dict:
"""
Expand Down Expand Up @@ -317,7 +371,7 @@ def place_derivative_order(
data: dict = {}
data.update(
account=account_no,
requestID="5",
requestID="26",
instrumentID=instrument,
market="VNFE",
buySell='B' if side == 'BUY' else 'S',
Expand All @@ -344,3 +398,57 @@ def place_derivative_order(
url=self.url_derivative_new_order, headers=self.__headers, data=data, limit=self.wait
)
return res

def modify_derivative_order(
self, account_no: str, order_id: str,
side: str, instrument: str, quantity: int, price: float
) -> dict:
data: dict = {}
data.update(
account=account_no,
requestID="MODIFY2",
orderID=order_id,
marketID="VNFE",
instrumentID=instrument,
price=0,
quantity=quantity,
buySell='B' if side == 'BUY' else 'S',
orderType="MTL",
code="",
deviceId=":".join([str(i) for i in range(11, 17)]),
userAgent=""
)
data_signed = sign(json.dumps(data), self.config.ssi_broker_private_key)
self.__headers.update({
"Authorization": self.get_token(),
"X-Signature": data_signed,
})
res = request_handler.post(
url=self.url_derivative_modify_order, headers=self.__headers, data=data, limit=self.wait
)
return res

def cancel_derivative_order(
self, account_no: str, order_id: str, instrument: str, side: str
) -> dict:
data: dict = {}
data.update(
account=account_no,
requestID="CANCEL2",
orderID=order_id,
marketID="VNFE",
instrumentID=instrument,
buySell='B' if side == 'BUY' else 'S',
code="",
deviceId=":".join([str(i) for i in range(11, 17)]),
userAgent=""
)
data_signed = sign(json.dumps(data), self.config.ssi_broker_private_key)
self.__headers.update({
"Authorization": self.get_token(),
"X-Signature": data_signed,
})
res = request_handler.post(
url=self.url_derivative_cancel_order, headers=self.__headers, data=data, limit=self.wait
)
return res

0 comments on commit 201bfcf

Please sign in to comment.