Skip to content

Commit

Permalink
[Mod] add TickTrade and TickBook object
Browse files Browse the repository at this point in the history
  • Loading branch information
vnpy committed Dec 21, 2023
1 parent e18faee commit 0615b58
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ ignore =
# line too long, fixed by black
E501,
# line break before binary operator
W503,
W503,
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 3.9.0

1. First release of VeighNa Crypto
## Framework

1. First release of VeighNa Crypto as a fork of the original VeighNa project
2. Translate core and UI language from Chinese to English
3. Support only crypto exchanges for the Exchange enum
4. Remove unnecessary offset converter related data update and functions
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ pyzmq==23.2.1
plotly==5.10.0
importlib-metadata==4.12.0
tqdm==4.64.1
backports.zoneinfo; python_version < '3.9'
sortedcontainers==2.4.0
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ install_requires =
pyzmq
plotly
tqdm
sortedcontainers

[options.package_data]
* = *.dll, *.so, *.pyd
3 changes: 3 additions & 0 deletions vnpy/trader/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
EVENT_QUOTE = "eQuote."
EVENT_CONTRACT = "eContract."
EVENT_LOG = "eLog"

EVENT_TICK_BOOK = "eTickBook"
EVENT_TICK_TRADE = "eTickTrade"
59 changes: 59 additions & 0 deletions vnpy/trader/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
from datetime import datetime
from logging import INFO

from sortedcontainers import SortedDict

from .constant import Direction, Exchange, Interval, Offset, Status, Product, OptionType, OrderType


ACTIVE_STATUSES = set([Status.SUBMITTING, Status.NOTTRADED, Status.PARTTRADED])


Expand Down Expand Up @@ -421,3 +424,59 @@ def create_quote_data(self, quoteid: str, gateway_name: str) -> QuoteData:
gateway_name=gateway_name,
)
return quote


@dataclass
class TickTrade(BaseData):
"""
Detailed fill data of the market.
"""

symbol: str
exchange: Exchange
price: float
volume: int
datetime: datetime
direction: Direction = None

def __post_init__(self) -> None:
""""""
self.vt_symbol: str = f"{self.symbol}.{self.exchange.value}"


class TickBook:
"""Order book with detailed market depth"""

def __init__(self, vt_symbol: str) -> None:
""""""
self.vt_symbol: str = vt_symbol

self.bid_book: SortedDict = SortedDict(lambda i: -i)
self.ask_book: SortedDict = SortedDict()

self.sequence_id: int = 0

def update_bid(self, price: float, volume: float) -> None:
"""Update bid data into the book"""
if volume:
self.bid_book[price] = volume
else:
self.bid_book.pop(price, None)

def update_ask(self, price: float, volume: float) -> None:
"""Update ask data into the book"""
if volume:
self.ask_book[price] = volume
else:
self.ask_book.pop(price, None)

def update_sequence(self, sequence_id: int) -> None:
"""Update sequence id of order book"""
self.sequence_id = sequence_id

def clear(self) -> None:
"""Clear all depth data"""
self.bid_book.clear()
self.ask_book.clear()

self.sequence_id = 0

0 comments on commit 0615b58

Please sign in to comment.