Skip to content

Commit

Permalink
Release: vBroker v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dung1t committed Nov 5, 2024
1 parent 201bfcf commit 040d8df
Show file tree
Hide file tree
Showing 13 changed files with 441 additions and 222 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ MANIFEST
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
*.session

# Installer logs
pip-log.txt
Expand Down Expand Up @@ -153,7 +154,7 @@ dmypy.json

# Cython debug symbols
cython_debug/

tests/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
Expand Down
85 changes: 47 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,59 +28,68 @@ broker = Broker(
)
)

# Send OTP
# Get/Set OTP
print(broker.api.get_otp())
# Set OTP
broker.api.otp = "<OTP>"
broker.api.otp = "123456"
# Get Token
print(broker.api.get_token())

# Get Orderbook History
print(broker.api.get_orderbook(account_no="6666661"))
print(broker.api.get_orderbook(account_no="6666668"))
print(broker.api.get_order_history(
account_no="6666661", from_date="2021-09-18", to_date="2024-09-18")
broker.api.get_token()
# Get Orderbook
print(broker.api.get_ordebbook(account_no="6666661"))
print(
broker.api.get_ordebbook(account_no="6666668", from_date="2024-09-01", to_date="2024-09-20")
)
print(broker.api.get_order_history(
account_no="6666668", from_date="2024-09-18", to_date="2024-09-18")
)

# Get Max Buy/Sell Quantity
print(broker.api.get_max_buy_quantity(account_no="6666661", instrument="SSI", price=33.6))
print(broker.api.get_max_buy_quantity(account_no="6666668", instrument="VN30F2409", price=1315))
print(broker.api.get_max_buy_quantity(account_no="6666668", instrument="VN30F2411", price=1315))
print(broker.api.get_max_sell_quantity(account_no="6666661", instrument="SSI", price=33.6))
print(broker.api.get_max_sell_quantity(account_no="6666668", instrument="VN30F2409", price=1315))

# Get Position/Account Balance
print(broker.api.get_equity_positions(account_no="6666661"))
print(broker.api.get_equity_account_balance(account_no="6666661"))

print(broker.api.get_derivative_positions(account_no="6666668"))
print(broker.api.get_derivative_account_balance(account_no="6666668"))

print(broker.api.get_max_sell_quantity(account_no="6666668", instrument="VN30F2411", price=1315))
# Get Positions
print(broker.api.get_positions(account_no="6666661", is_equity=True))
print(broker.api.get_positions(account_no="6666668", is_equity=False))
# Get Balance
print(broker.api.get_balance(account_no="6666661", is_equity=True))
print(broker.api.get_balance(account_no="6666668", is_equity=False))
# Place Order
print(broker.api.place_equity_order(
account_no="6666661", side="BUY", instrument="SSI", quantity=100, price=31)
print(
broker.api.place_order(
account_no="6666661", side="BUY", instrument="SSI", quantity=100, price=25500
)
)
print(broker.api.place_derivative_order(
account_no="6666668", side="BUY", instrument="VN30F2409", quantity=1, price=1000)
print(
broker.api.place_order(
account_no="6666668", side="BUY", instrument="VN30F2411", quantity=1, price=1226.3,
is_equity=False
)
)

# 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_order(
account_no="6666661",
order_id="108200271", side="BUY", instrument="SSI", quantity=100, price=24450,
is_equity=True
)
)
print(broker.api.modify_derivative_order(
account_no="6666668", order_id="123456", side="BUY", instrument="VN30F2409", quantity=1, price=1000)
print(
broker.api.modify_order(
account_no="6666668",
order_id="18118759", side="BUY", instrument="VN30F2411", quantity=1, price=1410,
is_equity=False
)
)

# Cancel Order
print(broker.api.cancel_equity_order(
account_no="6666661", order_id="123456", side="BUY", instrument="SSI")
print(
broker.api.cancel_order(
account_no="6666661", order_id="108200271", instrument="SSI", side="BUY",
is_equity=True
)
)
print(broker.api.cancel_derivative_order(
account_no="6666668", order_id="123456", side="BUY", instrument="VN30F2409")
print(
broker.api.cancel_order(
account_no="6666668", order_id="18118759", instrument="VN30F2411", side="BUY",
is_equity=False
)
)

```

### Streaming order
Expand Down
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 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.6"
version = "1.1.0"
license = "MIT"
description = "vBroker: A Python wrapper for Viet Nam Broker API"
repository = "https://github.com/quant-vn/vbroker"
Expand Down Expand Up @@ -30,6 +30,7 @@ pydantic = "^2.9.1"
pyjwt = "^2.9.0"
pycryptodome = "^3.20.0"
xmljson = "^0.2.1"
nanoid = "^2.0.0"

[build-system]
requires = ["poetry-core"]
Expand Down
91 changes: 53 additions & 38 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,68 @@
ssi_broker_account="666666",
ssi_broker_id="",
ssi_broker_secret="",
ssi_broker_private_key="" # noqa
ssi_broker_private_key=""
)
)

# # Get/Set OTP
# print(broker.api.get_otp())
# broker.api.otp = "616623"
broker.api.otp = "123456"
# Get Token
print(broker.api.get_token())
# print(broker.api.get_order_history(
# account_no="6666661", from_date="2021-09-18", to_date="2024-09-18")
# )
# print(broker.api.get_order_history(
# account_no="6666668", from_date="2024-09-18", to_date="2024-09-18")
# )

# print(broker.api.get_orderbook(account_no="6666661"))
# print(broker.api.get_orderbook(account_no="6666668"))

# print(broker.api.get_max_buy_quantity(account_no="6666661", instrument="SSI", price=33.6))
# print(broker.api.get_max_buy_quantity(account_no="6666668", instrument="VN30F2409", price=1315))
# print(broker.api.get_max_sell_quantity(account_no="6666661", instrument="SSI", price=33.6))
# print(broker.api.get_max_sell_quantity(account_no="6666668", instrument="VN30F2409", price=1315))

# print(broker.api.get_equity_positions(account_no="6666661"))
# print(broker.api.get_equity_account_balance(account_no="6666661"))

# print(broker.api.get_derivative_positions(account_no="6666668"))
# print(broker.api.get_derivative_account_balance(account_no="6666668"))

print(broker.api.place_equity_order(
account_no="6666661", side="BUY", instrument="SSI", quantity=100, price=31)
broker.api.get_token()
# Get Orderbook
print(broker.api.get_ordebbook(account_no="6666661"))
print(
broker.api.get_ordebbook(account_no="6666668", from_date="2024-09-01", to_date="2024-09-20")
)
print(broker.api.place_derivative_order(
account_no="6666668", side="BUY", instrument="VN30F2409", quantity=1, price=1000)
# Get Max Buy/Sell Quantity
print(broker.api.get_max_buy_quantity(account_no="6666661", instrument="SSI", price=33.6))
print(broker.api.get_max_buy_quantity(account_no="6666668", instrument="VN30F2411", price=1315))
print(broker.api.get_max_sell_quantity(account_no="6666661", instrument="SSI", price=33.6))
print(broker.api.get_max_sell_quantity(account_no="6666668", instrument="VN30F2411", price=1315))
# Get Positions
print(broker.api.get_positions(account_no="6666661", is_equity=True))
print(broker.api.get_positions(account_no="6666668", is_equity=False))
# Get Balance
print(broker.api.get_balance(account_no="6666661", is_equity=True))
print(broker.api.get_balance(account_no="6666668", is_equity=False))
# Place Order
print(
broker.api.place_order(
account_no="6666661", side="BUY", instrument="SSI", quantity=100, price=25500
)
)

print(broker.api.modify_equity_order(
account_no="6666661", order_id="123456", side="BUY", instrument="SSI", quantity=100, price=31)
print(
broker.api.place_order(
account_no="6666668", side="BUY", instrument="VN30F2411", quantity=1, price=1226.3,
is_equity=False
)
)
print(broker.api.modify_derivative_order(
account_no="6666668", order_id="123456", side="BUY", instrument="VN30F2409", quantity=1, price=1000)
# Modify Order
print(
broker.api.modify_order(
account_no="6666661",
order_id="108200271", side="BUY", instrument="SSI", quantity=100, price=24450,
is_equity=True
)
)

print(broker.api.cancel_equity_order(
account_no="6666661", order_id="123456", side="BUY", instrument="SSI")
print(
broker.api.modify_order(
account_no="6666668",
order_id="18118759", side="BUY", instrument="VN30F2411", quantity=1, price=1410,
is_equity=False
)
)
print(broker.api.cancel_derivative_order(
account_no="6666668", order_id="123456", side="BUY", instrument="VN30F2409")
# Cancel Order
print(
broker.api.cancel_order(
account_no="6666661", order_id="108200271", instrument="SSI", side="BUY",
is_equity=True
)
)
print(
broker.api.cancel_order(
account_no="6666668", order_id="18118759", instrument="VN30F2411", side="BUY",
is_equity=False
)
)
4 changes: 1 addition & 3 deletions tests/test_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
ssi_broker_account="666666",
ssi_broker_id="",
ssi_broker_secret="",
ssi_broker_private_key="" # noqa
ssi_broker_private_key=""
)
)

broker.api.otp = "123456"
print(broker.api.get_token())

def on_message(msg):
print(f"MESSAGE: {msg}")
Expand Down
52 changes: 10 additions & 42 deletions vbroker/interface_broker_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ def get_otp(self) -> str:
def get_token(self) -> str:
return NotImplemented

@abstractmethod
def get_order_history(self) -> dict:
return NotImplemented

@abstractmethod
def get_orderbook(self) -> dict:
return NotImplemented

@abstractmethod
def get_max_buy_quantity(self, account_no: str, instrument: str, price: float) -> dict:
return NotImplemented
Expand All @@ -40,58 +32,34 @@ def get_max_buy_quantity(self, account_no: str, instrument: str, price: float) -
def get_max_sell_quantity(self, account_no: str, instrument: str, price: float) -> dict:
return NotImplemented

# EQUITY
@abstractmethod
def get_equity_positions(self, account_no: str) -> dict:
return NotImplemented

@abstractmethod
def get_equity_account_balance(self, account_no: str) -> dict:
return NotImplemented

@abstractmethod
def place_equity_order(
self, account_no: str, side: str, instrument: str, quantity: int, price: float
) -> 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:
def get_ordebbook(self, account_no: str, from_date: str, to_date: str) -> dict:
return NotImplemented

# DERIVATIVES
@abstractmethod
def get_derivative_positions(self, account_no: str) -> dict:
def get_positions(self, account_no: str, is_equity: bool = True) -> dict:
return NotImplemented

@abstractmethod
def get_derivative_account_balance(self, account_no: str) -> dict:
def get_balance(self, account_no: str, is_equity: bool = True) -> dict:
return NotImplemented

@abstractmethod
def place_derivative_order(
self, account_no: str, side: str, instrument: str, quantity: int, price: float
def place_order(
self, account_no: str, side: str, instrument: str,
quantity: int, price: float | str, is_equity: bool = True
) -> dict:
return NotImplemented

@abstractmethod
def modify_derivative_order(
def modify_order(
self, account_no: str, order_id: str,
side: str, instrument: str, quantity: int, price: float
side: str, instrument: str, quantity: int, price: float | str, is_equity: bool = True
) -> dict:
return NotImplemented

@abstractmethod
def cancel_derivative_order(
self, account_no: str, order_id: str, instrument: str, side: str
def cancel_order(
self, account_no: str, order_id: str, instrument: str, side: str, is_equity: bool = True
) -> dict:
return NotImplemented
Loading

0 comments on commit 040d8df

Please sign in to comment.