httptrading 1.0.3__tar.gz → 1.0.5__tar.gz

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.
Files changed (23) hide show
  1. {httptrading-1.0.3 → httptrading-1.0.5}/PKG-INFO +1 -1
  2. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading/broker/base.py +1 -0
  3. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading/broker/futu_sec.py +3 -0
  4. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading/broker/interactive_brokers.py +3 -0
  5. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading/broker/longbridge.py +3 -0
  6. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading/broker/tiger.py +3 -0
  7. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading/http_server.py +30 -22
  8. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading.egg-info/PKG-INFO +1 -1
  9. {httptrading-1.0.3 → httptrading-1.0.5}/pyproject.toml +1 -1
  10. {httptrading-1.0.3 → httptrading-1.0.5}/LICENSE +0 -0
  11. {httptrading-1.0.3 → httptrading-1.0.5}/README.md +0 -0
  12. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading/__init__.py +0 -0
  13. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading/broker/__init__.py +0 -0
  14. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading/model.py +0 -0
  15. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading/tool/__init__.py +0 -0
  16. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading/tool/leaky_bucket.py +0 -0
  17. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading/tool/locate.py +0 -0
  18. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading/tool/time.py +0 -0
  19. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading.egg-info/SOURCES.txt +0 -0
  20. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading.egg-info/dependency_links.txt +0 -0
  21. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading.egg-info/requires.txt +0 -0
  22. {httptrading-1.0.3 → httptrading-1.0.5}/httptrading.egg-info/top_level.txt +0 -0
  23. {httptrading-1.0.3 → httptrading-1.0.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: httptrading
3
- Version: 1.0.3
3
+ Version: 1.0.5
4
4
  Summary: 统一交易通道的接口服务
5
5
  Author-email: songwei <github@songwei.name>
6
6
  License: MIT
@@ -82,6 +82,7 @@ class BaseBroker(ABC):
82
82
  direction: str,
83
83
  qty: int,
84
84
  price: float = None,
85
+ full_args: dict = None,
85
86
  **kwargs
86
87
  ) -> str:
87
88
  raise NotImplementedError
@@ -320,6 +320,7 @@ class Futu(SecuritiesBroker):
320
320
  direction: str,
321
321
  qty: int,
322
322
  price: float = None,
323
+ full_args: dict = None,
323
324
  **kwargs
324
325
  ) -> str:
325
326
  from futu import RET_OK, TrdSide, OrderType as FutuOrderType, TimeInForce as FutuTimeInForce, Session
@@ -398,6 +399,7 @@ class Futu(SecuritiesBroker):
398
399
  direction: str,
399
400
  qty: int,
400
401
  price: float = None,
402
+ full_args: dict = None,
401
403
  **kwargs
402
404
  ) -> str:
403
405
  return await self.call_sync(lambda : self._place_order(
@@ -408,6 +410,7 @@ class Futu(SecuritiesBroker):
408
410
  direction=direction,
409
411
  qty=qty,
410
412
  price=price,
413
+ full_args=full_args,
411
414
  **kwargs
412
415
  ))
413
416
 
@@ -205,6 +205,7 @@ class InteractiveBrokers(SecuritiesBroker):
205
205
  direction: str,
206
206
  qty: int,
207
207
  price: float = None,
208
+ full_args: dict = None,
208
209
  **kwargs
209
210
  ) -> str:
210
211
  import ib_insync
@@ -274,6 +275,7 @@ class InteractiveBrokers(SecuritiesBroker):
274
275
  direction: str,
275
276
  qty: int,
276
277
  price: float = None,
278
+ full_args: dict = None,
277
279
  **kwargs
278
280
  ) -> str:
279
281
  return await self.call_async(self._place_order(
@@ -284,6 +286,7 @@ class InteractiveBrokers(SecuritiesBroker):
284
286
  direction=direction,
285
287
  qty=qty,
286
288
  price=price,
289
+ full_args=full_args,
287
290
  **kwargs
288
291
  ))
289
292
 
@@ -310,6 +310,7 @@ class LongBridge(SecuritiesBroker):
310
310
  direction: str,
311
311
  qty: int,
312
312
  price: float = None,
313
+ full_args: dict = None,
313
314
  **kwargs
314
315
  ) -> str:
315
316
  from longport.openapi import OrderType as LbOrderType, OrderSide, TimeInForceType, OutsideRTH
@@ -382,6 +383,7 @@ class LongBridge(SecuritiesBroker):
382
383
  direction: str,
383
384
  qty: int,
384
385
  price: float = None,
386
+ full_args: dict = None,
385
387
  **kwargs
386
388
  ) -> str:
387
389
  return await self.call_sync(lambda : self._place_order(
@@ -392,6 +394,7 @@ class LongBridge(SecuritiesBroker):
392
394
  direction=direction,
393
395
  qty=qty,
394
396
  price=price,
397
+ full_args=full_args,
395
398
  **kwargs
396
399
  ))
397
400
 
@@ -281,6 +281,7 @@ class Tiger(SecuritiesBroker):
281
281
  direction: str,
282
282
  qty: int,
283
283
  price: float = None,
284
+ full_args: dict = None,
284
285
  **kwargs
285
286
  ) -> str:
286
287
  if contract.trade_type != TradeType.Securities:
@@ -360,6 +361,7 @@ class Tiger(SecuritiesBroker):
360
361
  direction: str,
361
362
  qty: int,
362
363
  price: float = None,
364
+ full_args: dict = None,
363
365
  **kwargs
364
366
  ) -> str:
365
367
  return await self.call_sync(lambda: self._place_order(
@@ -370,6 +372,7 @@ class Tiger(SecuritiesBroker):
370
372
  direction=direction,
371
373
  qty=qty,
372
374
  price=price,
375
+ full_args=full_args,
373
376
  **kwargs
374
377
  ))
375
378
 
@@ -84,6 +84,7 @@ class PlaceOrderView(HttpTradingView):
84
84
  qty=qty,
85
85
  price=price,
86
86
  json=body_d,
87
+ full_args=body_d,
87
88
  )
88
89
  return self.response_api(broker, {
89
90
  'orderId': order_id,
@@ -162,28 +163,33 @@ class MarketStatusView(HttpTradingView):
162
163
  })
163
164
 
164
165
 
165
- @web.middleware
166
- async def auth_middleware(request: web.Request, handler):
167
- instance_id = request.match_info.get('instance_id', '')
168
- token = request.headers.get('HT-TOKEN', '')
169
- if not instance_id:
170
- raise web.HTTPNotFound
171
- if not token:
172
- raise web.HTTPNotFound
173
- if len(token) < 16 or len(token) > 64:
174
- raise web.HTTPNotFound
175
- for broker in HttpTradingView.brokers():
176
- if broker.instance_id != instance_id:
177
- continue
178
- if token not in broker.tokens:
166
+ def create_auth_middleware(token_header: str):
167
+ assert isinstance(token_header, str)
168
+ assert token_header
169
+
170
+ @web.middleware
171
+ async def _auth_middleware(request: web.Request, handler):
172
+ instance_id = request.match_info.get('instance_id', '')
173
+ token = request.headers.get(token_header, '')
174
+ if not instance_id:
175
+ raise web.HTTPNotFound
176
+ if not token:
177
+ raise web.HTTPNotFound
178
+ if len(token) < 16 or len(token) > 64:
179
179
  raise web.HTTPNotFound
180
- setattr(request, '__current_broker__', broker)
181
- break
182
- else:
183
- raise web.HTTPNotFound
184
- response: web.Response = await handler(request)
185
- delattr(request, '__current_broker__')
186
- return response
180
+ for broker in HttpTradingView.brokers():
181
+ if broker.instance_id != instance_id:
182
+ continue
183
+ if token not in broker.tokens:
184
+ raise web.HTTPNotFound
185
+ setattr(request, '__current_broker__', broker)
186
+ break
187
+ else:
188
+ raise web.HTTPNotFound
189
+ response: web.Response = await handler(request)
190
+ delattr(request, '__current_broker__')
191
+ return response
192
+ return _auth_middleware
187
193
 
188
194
 
189
195
  @web.middleware
@@ -218,6 +224,7 @@ def run(
218
224
  brokers: list[BaseBroker],
219
225
  std_apis: Callable[[], list[web.RouteDef]] = None,
220
226
  extend_apis: list[web.RouteDef] = None,
227
+ token_header: str = 'HT-TOKEN',
221
228
  **kwargs
222
229
  ) -> None:
223
230
  """
@@ -226,11 +233,12 @@ def run(
226
233
  @param brokers: 需要控制的交易通道对象列表
227
234
  @param std_apis: 如果需要替换默认提供的接口, 这里提供工厂函数的回调
228
235
  @param extend_apis: 如果需要增加自定义接口, 这里传入 RouteDef 列表
236
+ @param token_header: 定制 token 凭据的 header 键名
229
237
  @param kwargs: 其他的参数将传给 aiohttp.web.run_app 函数
230
238
  """
231
239
  app = web.Application(
232
240
  middlewares=[
233
- auth_middleware,
241
+ create_auth_middleware(token_header=token_header),
234
242
  exception_middleware,
235
243
  ],
236
244
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: httptrading
3
- Version: 1.0.3
3
+ Version: 1.0.5
4
4
  Summary: 统一交易通道的接口服务
5
5
  Author-email: songwei <github@songwei.name>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "httptrading"
3
- version = "1.0.3"
3
+ version = "1.0.5"
4
4
  description = "统一交易通道的接口服务"
5
5
  authors = [
6
6
  {name = "songwei", email = "github@songwei.name"},
File without changes
File without changes
File without changes