Skip to content

Commit

Permalink
add cluent-type trade info to MW and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yghaderi committed Apr 14, 2024
1 parent 0275548 commit 0d04306
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion oxtapus/models/tsetmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MarketWatchOrderBook(BaseModel):
ask_count: int = Field(alias="zmo")


class MarketWatchAll(BaseModel):
class ClientTypeAll(BaseModel):
ins_code: str = Field(alias="insCode")
buy_vol_ind: float = Field(alias="buy_I_Volume")
buy_vol_ins: float = Field(alias="buy_N_Volume")
Expand Down
10 changes: 7 additions & 3 deletions oxtapus/tsetmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pydantic import validate_call
from urllib.parse import urlencode
import itertools
from oxtapus.models.tsetmc import HistPrice, MarketWatch
from oxtapus.models.tsetmc import HistPrice, MarketWatch, ClientTypeAll

from oxtapus.utils.http import requests, async_requests
from oxtapus.utils import (
Expand Down Expand Up @@ -96,7 +96,7 @@ def mw(self, sections: List[MWSections] | MWSections) -> str:
}
return f"{self.base_url}/ClosingPrice/GetMarketWatch?{urlencode(param)}"

def client_type(self):
def client_type_all(self):
return f"{self.base_url}/ClientType/GetClientTypeAll"

def search_ins_code(self, symbol_far) -> str:
Expand Down Expand Up @@ -319,11 +319,15 @@ def mw(self, sections: List[MWSections] | MWSections) -> pl.DataFrame:
>>> tsetmc.mw(["stock", "etf", "options"])
"""
r = self.requests(self.url.mw(sections), response="json")[0].get("marketwatch")
r_client_type = self.requests(self.url.client_type_all())[0]["clientTypeAllDto"]
records = json_normalize(
data=[MarketWatch.model_validate(i).model_dump() for i in r],
record_path="order_book",
)
return pl.DataFrame(records)
df = pl.DataFrame(records)
df_ct = pl.from_dicts([ClientTypeAll(**i).model_dump() for i in r_client_type])
df = df.join(df_ct, on=["ins_code"], how="left")
return df

def tse_options_mw(self):
"""
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 = "oxtapus"
version = "0.3.0"
version = "0.3.1"
description = ""
authors = ["Yaghoub Ghadri <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 0d04306

Please sign in to comment.