Skip to content

Commit e38d14f

Browse files
authored
actualize data types; replace Market; rename Order (#37)
* actualize data types; replace Market; rename Order
1 parent 5f0742d commit e38d14f

File tree

10 files changed

+77
-86
lines changed

10 files changed

+77
-86
lines changed

README.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,8 @@ async def create_stop_order(transaction_id: int):
158158
),
159159
)
160160
return await client.orders.create_stop_order(payload)
161-
162-
163-
if __name__ == "__main__":
164-
import asyncio
165-
166-
res = asyncio.run(create_order())
167-
print(res)
168-
169-
print(asyncio.run(create_stop_order(1111111111111111111)))
170-
171-
print(asyncio.run(get_orders()))
172-
173-
print(asyncio.run(del_order(res.data.transactionId)))
174-
175-
print(asyncio.run(get_orders()))
176161
```
177-
162+
Больше примеров в examples/
178163

179164
## Authors
180165

examples/order.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
async def create_order():
2424
payload = CreateOrderRequestModel(
2525
clientId=client_id,
26-
securityBoard=BoardType.Futures,
27-
securityCode="SiH3",
28-
buySell=OrderType.Sell,
26+
securityBoard=BoardType.TQBR,
27+
securityCode="ALRS",
28+
buySell=OrderType.Buy,
2929
quantity=1,
30-
price=74920,
30+
price=72.23,
3131
property=PropertyType.PutInQueue,
3232
condition=None,
3333
validateBefore=None,
@@ -55,20 +55,20 @@ async def del_order(transaction_id: int):
5555
async def create_stop_order(transaction_id: int):
5656
payload = CreateStopOrderRequestModel(
5757
clientId=client_id,
58-
securityBoard=BoardType.Futures,
59-
securityCode="SiH3",
60-
buySell=OrderType.Buy,
58+
securityBoard=BoardType.TQBR,
59+
securityCode="ALRS",
60+
buySell=OrderType.Sell,
6161
linkOrder=transaction_id,
6262
stopLoss=StopLossModel(
63-
activationPrice=74940,
63+
activationPrice=71.80,
6464
marketPrice=True,
6565
quantity=StopQuantity(
6666
value=1,
6767
units=StopQuantityUnits.Lots,
6868
)
6969
),
7070
takeProfit=TakeProfitModel(
71-
activationPrice=74850,
71+
activationPrice=72.30,
7272
marketPrice=True,
7373
quantity=StopQuantity(
7474
value=1,
@@ -77,18 +77,3 @@ async def create_stop_order(transaction_id: int):
7777
),
7878
)
7979
return await client.orders.create_stop_order(payload)
80-
81-
82-
if __name__ == "__main__":
83-
import asyncio
84-
85-
res = asyncio.run(create_order())
86-
print(res)
87-
88-
print(asyncio.run(create_stop_order(1111111111111111111)))
89-
90-
print(asyncio.run(get_orders()))
91-
92-
print(asyncio.run(del_order(res.data.transactionId)))
93-
94-
print(asyncio.run(get_orders()))

examples/security.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,11 @@
66
client = Client(token)
77

88

9-
async def get_all_data():
10-
return await client.securities.get_data()
11-
12-
139
async def get_data_by_code(code: str):
1410
return await client.securities.get_data(code)
1511

1612

1713
if __name__ == "__main__":
1814
import asyncio
1915

20-
print(asyncio.run(get_all_data()))
21-
22-
code_ = "SiZ2"
23-
print(asyncio.run(get_data_by_code(code_)))
16+
print(asyncio.run(get_data_by_code("SBER")))

finam_trade_api/models.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from enum import Enum
12
from typing import Optional
23

34
from pydantic import BaseModel
@@ -11,3 +12,13 @@ class BaseErrorModel(BaseModel):
1112

1213
class ErrorBodyModel(BaseModel):
1314
error: BaseErrorModel
15+
16+
17+
class Market(str, Enum):
18+
Stock = "Stock"
19+
Forts = "Forts"
20+
Spbex = "Spbex"
21+
Mma = "Mma"
22+
Ets = "Ets"
23+
Bonds = "Bonds"
24+
Options = "Options"

finam_trade_api/order/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
DelStopOrderData,
1414
DelStopOrderRequestModel,
1515
DelStopOrderResponseModel,
16-
OrderResponse,
16+
Order,
1717
OrdersRequestModel,
1818
OrdersResponseData,
1919
OrdersResponseModel,

finam_trade_api/order/model.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from pydantic import BaseModel
55

6+
from finam_trade_api.models import Market
7+
68

79
class OrderType(str, Enum):
810
Sell = "Sell"
@@ -21,9 +23,9 @@ class ConditionType(str, Enum):
2123

2224

2325
class PropertyType(str, Enum):
24-
PutInQueue = "PutInQueue"
25-
CancelBalance = "CancelBalance"
26-
ImmOrCancel = "ImmOrCancel"
26+
PutInQueue = "PutInQueue" # неисполненная часть заявки помещается в очередь заявок биржи;
27+
CancelBalance = "CancelBalance" # неисполненная часть заявки снимается с торгов;
28+
ImmOrCancel = "ImmOrCancel" # сделки совершаются в том случае, если заявка может быть удовлетворена полностью
2729

2830

2931
class ValidBeforeType(str, Enum):
@@ -67,58 +69,67 @@ class ValidBefore(BaseModel):
6769

6870

6971
class OrderStatus(str, Enum):
72+
NONE = "None"
7073
Active = "Active"
7174
Cancelled = "Cancelled"
7275
Matched = "Matched"
7376

7477

75-
class OrderMarket(str, Enum):
76-
Stock = "Stock"
77-
Forts = "Forts"
78-
Spbex = "Spbex"
79-
Mma = "Mma"
80-
Ets = "Ets"
81-
Bonds = "Bonds"
82-
Options = "Options"
83-
84-
85-
class OrderResponse(BaseModel):
78+
class Order(BaseModel):
8679
orderNo: int
8780
transactionId: int
8881
securityCode: Optional[str] = None
8982
clientId: Optional[str] = None
90-
status: Optional[OrderStatus] = None
83+
status: OrderStatus
9184
buySell: OrderType
9285
createdAt: Optional[str] = None
9386
acceptedAt: Optional[str] = None
94-
price: float = 0
87+
price: float = 0 # В последующих версиях API поле для рыночных заявок будет равно null, а не 0.
9588
quantity: int
9689
balance: int
9790
message: Optional[str] = None
9891
currency: Optional[str] = None
9992
condition: Optional[Condition] = None
10093
validBefore: Optional[ValidBefore] = None
10194
securityBoard: Optional[str] = None
102-
market: Optional[OrderMarket] = None
95+
market: Market
10396

10497

10598
class OrdersResponseData(BaseModel):
10699
clientId: str
107-
orders: List[OrderResponse]
100+
orders: List[Order]
108101

109102

110103
class OrdersResponseModel(BaseModel):
111104
data: OrdersResponseData
112105

113106

114107
class StopOrder(BaseModel):
115-
stopOrderId: int
108+
stopId: int
116109
securityCode: str
110+
securityBoard: BoardType
111+
market: Market
112+
clientId: str
113+
buySell: OrderType
114+
expirationDate: Optional[str] = None
115+
linkOrder: int
116+
validBefore: Optional[ValidBefore] = None
117+
status: OrderStatus
118+
message: Optional[str] = None
119+
orderNo: int
120+
tradeNo: int
121+
acceptedAt: Optional[str] = None
122+
canceledAt: Optional[str] = None
123+
currency: Optional[str] = None
124+
takeProfitExtremum: float
125+
takeProfitLevel: float
126+
stopLoss: Optional["StopLossModel"] = None
127+
takeProfit: Optional["TakeProfitModel"] = None
117128

118129

119130
class StopOrdersResponseData(BaseModel):
120131
clientId: str
121-
stopOrders: List[StopOrder]
132+
stops: List[StopOrder]
122133

123134

124135
class StopOrdersResponseModel(BaseModel):
@@ -142,7 +153,7 @@ class CreateOrderRequestModel(BaseModel):
142153
buySell: OrderType
143154
quantity: int
144155
useCredit: bool = False
145-
price: Optional[float] # цена заявки
156+
price: float = 0 # В последующих версиях API поле для рыночных заявок будет равно null, а не 0.
146157
property: PropertyType
147158
condition: Optional[Condition] = None
148159
validBefore: Optional[ValidBefore] = None
@@ -155,9 +166,11 @@ class StopQuantity(BaseModel):
155166

156167
class StopLossModel(BaseModel):
157168
activationPrice: float
158-
price: Optional[float] = None
169+
price: float = 0
159170
marketPrice: bool
160171
quantity: StopQuantity
172+
time: int = 0 # Защитное время, сек.
173+
useCredit: bool = False
161174

162175

163176
class StopPrice(BaseModel):
@@ -171,7 +184,7 @@ class TakeProfitModel(BaseModel):
171184
spreadPrice: Optional[StopPrice] = None
172185
marketPrice: bool
173186
quantity: StopQuantity
174-
time: Optional[int] = None # Защитное время, сек.
187+
time: int = 0 # Защитное время, сек.
175188
useCredit: bool = False
176189

177190

finam_trade_api/portfolio/model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from pydantic import BaseModel
44

5+
from finam_trade_api.models import Market
6+
57

68
class PortfolioRequestOptionalModel(BaseModel):
79
includeCurrencies: str = "true"
@@ -23,7 +25,7 @@ class PortfolioContent(BaseModel):
2325

2426
class Position(BaseModel):
2527
securityCode: str
26-
market: str
28+
market: Market
2729
balance: int
2830
currentPrice: float
2931
equity: float

finam_trade_api/securities/model.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
from typing import List
1+
from typing import List, Optional
22

33
from pydantic import BaseModel
44

5+
from finam_trade_api.models import Market
6+
57

68
class Security(BaseModel):
79
code: str
810
board: str
9-
market: str
10-
decimals: float
11-
lotSize: float
12-
minStep: float
13-
currency: str
14-
shortName: str
15-
properties: float
16-
timeZoneName: str
11+
market: Market
12+
decimals: int
13+
lotSize: int
14+
minStep: int
15+
currency: Optional[str] = None
16+
shortName: Optional[str] = None
17+
properties: int
18+
timeZoneName: Optional[str] = None
1719
bpCost: float
1820
accruedInterest: float
1921
priceSign: str
20-
ticker: str
21-
lotDivider: float
22+
ticker: Optional[str] = None
23+
lotDivider: int
2224

2325

2426
class SecurityData(BaseModel):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "finam-trade-api"
3-
version = "2.2.0"
3+
version = "2.3.0"
44
description = "Асинхронный REST-клиент для API Finam"
55
authors = ["DBoyara <[email protected]>"]
66
license = "GNU GPL v.3.0"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
maintainer="DBoyara",
66
maintainer_email="[email protected]",
77
packages=find_packages(),
8-
version="2.2.0",
8+
version="2.3.0",
99
install_requires=["aiohttp >= 3.8.3, < 4.0.0", "pydantic >= 1.10.2, < 2.0.0"],
1010
python_requires=">3.8.0, <4",
1111
license="GNU GPL v.3.0",

0 commit comments

Comments
 (0)