hyperquant 0.31__py3-none-any.whl → 0.33__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  from typing import Literal, Optional
2
2
  import pybotters
3
3
  from .models.ourbit import OurbitSwapDataStore
4
+ from decimal import Decimal, ROUND_HALF_UP
4
5
 
5
6
 
6
7
  class OurbitSwap:
@@ -92,7 +93,13 @@ class OurbitSwap:
92
93
  return res.data["data"]
93
94
  case _:
94
95
  raise Exception(f"Failed api {res.response.url}: {res.data}")
95
-
96
+
97
+
98
+ def fmt_price(self, symbol, price: float) -> float:
99
+ tick = self.store.detail.find({"symbol": symbol})[0].get("tick_size")
100
+ tick_dec = Decimal(str(tick))
101
+ price_dec = Decimal(str(price))
102
+ return float((price_dec / tick_dec).quantize(Decimal("1"), rounding=ROUND_HALF_UP) * tick_dec)
96
103
 
97
104
  async def place_order(
98
105
  self,
@@ -123,8 +130,10 @@ class OurbitSwap:
123
130
  if usdt_amount is not None:
124
131
  cs = self.store.detail.find({"symbol": symbol})[0].get("contract_sz")
125
132
  size = max(int(usdt_amount / cs / price), 1)
126
-
127
133
 
134
+ price = self.fmt_price(symbol, price)
135
+
136
+ print(f'下单价格 {price}')
128
137
  leverage = max(max_lev, leverage)
129
138
 
130
139
  data = {
@@ -147,19 +156,63 @@ class OurbitSwap:
147
156
 
148
157
  if "close" in side:
149
158
  if side == 'close_buy':
150
- data["side"] = 4
151
- elif side == 'close_sell':
152
159
  data["side"] = 2
153
- data["type"] = 5
160
+ elif side == 'close_sell':
161
+ data["side"] = 4
162
+
154
163
  if position_id is None:
155
164
  raise ValueError("position_id is required for closing position")
156
165
  data["positionId"] = position_id
157
- import time
158
- print(time.time(), '下单')
166
+ # import time
167
+ # print(time.time(), '下单')
159
168
  res = await self.client.fetch(
160
169
  "POST", f"{self.api_url}/api/v1/private/order/create", data=data
161
170
  )
162
171
  return self.ret_content(res)
172
+
173
+ async def place_tpsl(self,
174
+ position_id: int,
175
+ take_profit: Optional[float] = None,
176
+ stop_loss: Optional[float] = None,
177
+ ):
178
+ """
179
+ position_id 持仓ID
180
+
181
+ .. code:: json
182
+
183
+ {
184
+ "success": true,
185
+ "code": 0,
186
+ "data": 2280508
187
+ }
188
+ """
189
+ if (take_profit is None) and (stop_loss is None):
190
+ raise ValueError("params err")
191
+
192
+ data = {
193
+ "positionId": position_id,
194
+ "profitTrend": "1",
195
+ "lossTrend": "1",
196
+ "profitLossVolType": "SAME",
197
+ "volType": 2,
198
+ "takeProfitReverse": 2,
199
+ "stopLossReverse": 2,
200
+ "priceProtect": "0",
201
+ }
202
+
203
+ if take_profit is not None:
204
+ data["takeProfitPrice"] = take_profit
205
+ if stop_loss is not None:
206
+ data["stopLossPrice"] = stop_loss
207
+
208
+
209
+ res = await self.client.fetch(
210
+ "POST",
211
+ f"{self.api_url}/api/v1/private/stoporder/place",
212
+ data=data
213
+ )
214
+
215
+ return self.ret_content(res)
163
216
 
164
217
  async def cancel_orders(self, order_ids: list[str]):
165
218
  res = await self.client.fetch(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyperquant
3
- Version: 0.31
3
+ Version: 0.33
4
4
  Summary: A minimal yet hyper-efficient backtesting framework for quantitative trading
5
5
  Project-URL: Homepage, https://github.com/yourusername/hyperquant
6
6
  Project-URL: Issues, https://github.com/yourusername/hyperquant/issues
@@ -6,7 +6,7 @@ hyperquant/logkit.py,sha256=WALpXpIA3Ywr5DxKKK3k5EKubZ2h-ISGfc5dUReQUBQ,7795
6
6
  hyperquant/notikit.py,sha256=x5yAZ_tAvLQRXcRbcg-VabCaN45LUhvlTZnUqkIqfAA,3596
7
7
  hyperquant/broker/auth.py,sha256=hrdVuBTZwD3xSy5GI5JTFJhKiHhvIjZHA_7G5IUFznQ,1580
8
8
  hyperquant/broker/hyperliquid.py,sha256=7MxbI9OyIBcImDelPJu-8Nd53WXjxPB5TwE6gsjHbto,23252
9
- hyperquant/broker/ourbit.py,sha256=VE1eLvQ1hakOxWbXHmW8KXwYrP_Apsv0_FOPtmU3MKs,8033
9
+ hyperquant/broker/ourbit.py,sha256=ejaRAM3Q8Iho7ng3o7xx-j0mT3GjrTykfVZNMTg5lO4,9567
10
10
  hyperquant/broker/ws.py,sha256=98Djt5n5sHUJKVbQ8Ql1t-G-Wiwu__4MYcUr5P6SDL0,326
11
11
  hyperquant/broker/lib/hpstore.py,sha256=LnLK2zmnwVvhEbLzYI-jz_SfYpO1Dv2u2cJaRAb84D8,8296
12
12
  hyperquant/broker/lib/hyper_types.py,sha256=HqjjzjUekldjEeVn6hxiWA8nevAViC2xHADOzDz9qyw,991
@@ -16,6 +16,6 @@ hyperquant/datavison/_util.py,sha256=92qk4vO856RqycO0YqEIHJlEg-W9XKapDVqAMxe6rbw
16
16
  hyperquant/datavison/binance.py,sha256=3yNKTqvt_vUQcxzeX4ocMsI5k6Q6gLZrvgXxAEad6Kc,5001
17
17
  hyperquant/datavison/coinglass.py,sha256=PEjdjISP9QUKD_xzXNzhJ9WFDTlkBrRQlVL-5pxD5mo,10482
18
18
  hyperquant/datavison/okx.py,sha256=yg8WrdQ7wgWHNAInIgsWPM47N3Wkfr253169IPAycAY,6898
19
- hyperquant-0.31.dist-info/METADATA,sha256=ZfMLDTVVmQdtj-qCg1kwN1fl1TJfRpzHki-6AoUnhEI,4317
20
- hyperquant-0.31.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
21
- hyperquant-0.31.dist-info/RECORD,,
19
+ hyperquant-0.33.dist-info/METADATA,sha256=TNKlHrMHpNgxFAsCIE3Oos_-skhADOqL7xMM6VrscjQ,4317
20
+ hyperquant-0.33.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
21
+ hyperquant-0.33.dist-info/RECORD,,