Skip to main content

vBroker: A Python wrapper for Viet Nam Broker API

Project description

vBroker

vBroker: A Python wrapper for Viet Nam Broker API

PyPI - Version Python Version PyPI - Downloads License: MIT

Installation

pip install vbroker

Usage

Basic usage

from vbroker import Broker, Config, EnumBroker

broker = Broker(
    broker=EnumBroker.SSI.value,
    config=Config(
        ssi_broker_account="666666",
        ssi_broker_id="<SSI_BROKER_ID>",
        ssi_broker_secret="<SSI_BROKER_SECRET>",
        ssi_broker_private_key="<SSI_BROKER_PRIVATE_KEY>"
    )
)

# Send OTP
print(broker.api.get_otp())
# Set OTP
broker.api.otp = "<OTP>"
# 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")
)
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_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"))

# Place Order
print(broker.api.place_equity_order(
    account_no="6666661", side="BUY", instrument="SSI", quantity=100, price=31)
)
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

import asyncio
from vbroker import Broker, Config, EnumBroker

broker = Broker(
    broker=EnumBroker.SSI.value,
    config=Config(
        ssi_broker_account="666666",
        ssi_broker_id="<SSI_BROKER_ID>",
        ssi_broker_secret="<SSI_BROKER_SECRET>",
        ssi_broker_private_key="<SSI_BROKER_PRIVATE_KEY>"
    )
)

broker.api.otp = "<OTP>"
print(broker.api.get_token())

def on_message(msg):
    print(f"MESSAGE: {msg}")


asyncio.run(broker.hub.listen(on_message))

MIT License

Copyright (c) 2024 Quant.vn

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vbroker-0.1.6.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

vbroker-0.1.6-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file vbroker-0.1.6.tar.gz.

File metadata

  • Download URL: vbroker-0.1.6.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.12.6 Linux/6.8.0-1014-azure

File hashes

Hashes for vbroker-0.1.6.tar.gz
Algorithm Hash digest
SHA256 4be14645e3208ec5486a05713bcacec3ec4e9f963875a95ec2aade3cdaada095
MD5 31fee972fa44183afec806d7e3b84732
BLAKE2b-256 e0ac7bd664a8dd51f267e3bb2810f4b1a809dbd43775180ac24167747e6ea538

See more details on using hashes here.

File details

Details for the file vbroker-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: vbroker-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.12.6 Linux/6.8.0-1014-azure

File hashes

Hashes for vbroker-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c8833025d45c77f2f7dd3e79e03fd12b03d885827fee6f6684c4f96ddf1accec
MD5 73c0dbf627cd5188d8b3b3d8e68b865b
BLAKE2b-256 add72e1e263c1371823745aa917609d55b517e8c86c51f186f00e747f42d5235

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page