-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdto.py
More file actions
69 lines (55 loc) · 2.01 KB
/
dto.py
File metadata and controls
69 lines (55 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import json
class OrderSendParameters:
alias: str
is_buy: bool
size: int
limit_price: float
stop_price: float
take_profit_offset: int
stop_loss_offset: int
stop_loss_trailing_step: int
take_profit_client_id: str
stop_loss_client_id: str
duration: str
client_id: str
def __init__(self, alias, is_buy, size):
self.alias = alias
self.is_buy = is_buy
self.size = size
self.limit_price = None
self.stop_price = None
self.take_profit_offset = None
self.stop_loss_offset = None
self.stop_loss_trailing_step = None
self.take_profit_client_id = None
self.stop_loss_client_id = None
self.duration = None
self.client_id = None
def to_json(self):
# Create a dictionary to hold the non-None fields
data = {
"alias": self.alias,
"isBuy": self.is_buy,
"size": self.size,
}
# Add optional fields if they are not None
if self.limit_price is not None:
data["limitPrice"] = self.limit_price
if self.stop_price is not None:
data["stopPrice"] = self.stop_price
if self.take_profit_offset is not None:
data["takeProfitOffset"] = self.take_profit_offset
if self.stop_loss_offset is not None:
data["stopLossOffset"] = self.stop_loss_offset
if self.stop_loss_trailing_step is not None:
data["stopLossTrailingStep"] = self.stop_loss_trailing_step
if self.take_profit_client_id is not None:
data["takeProfitClientId"] = self.take_profit_client_id
if self.stop_loss_client_id is not None:
data["stopLossClientId"] = self.stop_loss_client_id
if self.duration is not None:
data["duration"] = self.duration
if self.client_id is not None:
data["clientId"] = self.client_id
# Convert the dictionary to JSON and return it
return json.dumps(data, indent=None)