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>"
    )
)

# Get/Set OTP
print(broker.api.get_otp())
broker.api.otp = "123456"
# Get Token
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")
)
# 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.place_order(
        account_no="6666668", side="BUY", instrument="VN30F2411", quantity=1, price=1226.3,
        is_equity=False
    )
)
# 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.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_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
    )
)

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-1.1.5.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vbroker-1.1.5-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: vbroker-1.1.5.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for vbroker-1.1.5.tar.gz
Algorithm Hash digest
SHA256 f98bcf7a0ad5a7fd35b92600f47dd32886d2f1c55b13f7bdeb60dbfc69b9ea89
MD5 792edd3118f958d4ea7e0e0518c08421
BLAKE2b-256 77353c26a5c2250574892e27f0f797aeb1780c2fe7cd5972afe587023917b122

See more details on using hashes here.

File details

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

File metadata

  • Download URL: vbroker-1.1.5-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for vbroker-1.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1774ed4163dc0bfbed4c42061a5fa0ceb497bff5ad7db95e0cb0956baf6299cb
MD5 cdc37c5fa079dfab628e5e0d7206d832
BLAKE2b-256 2c37d4917c42ab5184be5cfffb515f1268dac1f3073fe07a81e6027ac9aa4037

See more details on using hashes here.

Supported by

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