.
This commit is contained in:
parent
3f29717b64
commit
dc38176529
@ -18,7 +18,6 @@ from cvttpy_tools.base.base import NamedObject
|
||||
from cvttpy_tools.base.config import Config, CvttAppConfig
|
||||
from cvttpy_tools.base.logger import Log
|
||||
from cvttpy_tools.base.timeutils import NanoPerSec, SecPerHour, current_nanoseconds
|
||||
from cvttpy_tools.comm.web.rest_client import RESTSender
|
||||
from cvttpy_tools.comm.web.rest_service import RestService
|
||||
|
||||
from cvttpy_trading.trading.exchange_config import ExchangeAccounts
|
||||
@ -26,6 +25,7 @@ from cvttpy_trading.trading.instrument import ExchangeInstrument
|
||||
from cvttpy_trading.trading.mkt_data.md_summary import MdTradesAggregate, MdSummary
|
||||
|
||||
from pairs_trading.apps.pair_selector.renderer import HtmlRenderer
|
||||
from pairs_trading.lib.live.rest import RESTSender
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@ -11,13 +11,13 @@ from cvttpy_tools.base.config import Config
|
||||
from cvttpy_tools.base.timer import Timer
|
||||
from cvttpy_tools.base.timeutils import NanosT, current_seconds
|
||||
from cvttpy_tools.settings.cvtt_types import InstrumentIdT, IntervalSecT
|
||||
from cvttpy_tools.comm.web.rest_client import RESTSender
|
||||
# ---
|
||||
from cvttpy_trading.trading.instrument import ExchangeInstrument
|
||||
from cvttpy_trading.trading.accounting.exch_account import ExchangeAccountNameT
|
||||
from cvttpy_trading.trading.mkt_data.md_summary import MdTradesAggregate, MdSummary, MdSummaryCallbackT
|
||||
from cvttpy_trading.trading.exchange_config import ExchangeAccounts
|
||||
# ---
|
||||
from pairs_trading.lib.live.rest import RESTSender
|
||||
|
||||
|
||||
# class MdSummary(HistMdBar):
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
```python
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Dict
|
||||
from typing import Dict, Optional
|
||||
import time
|
||||
|
||||
import requests
|
||||
@ -9,6 +8,7 @@ import requests
|
||||
from cvttpy_tools.base.base import NamedObject
|
||||
|
||||
class RESTSender(NamedObject):
|
||||
# Synchronous request sernder
|
||||
session_: requests.Session
|
||||
base_url_: str
|
||||
|
||||
@ -26,35 +26,35 @@ class RESTSender(NamedObject):
|
||||
except requests.exceptions.RequestException:
|
||||
return False
|
||||
|
||||
def send_post(self, endpoint: str, post_body: Dict) -> requests.Response:
|
||||
|
||||
while not self.is_ready():
|
||||
print("Waiting for FrontGateway to start...")
|
||||
time.sleep(5)
|
||||
def send_post(
|
||||
self, endpoint: str, post_body: Dict, headers: Optional[Dict[str, str]] = None
|
||||
) -> requests.Response:
|
||||
|
||||
if not headers:
|
||||
headers = {"Content-Type": "application/json"}
|
||||
url = f"{self.base_url_}/{endpoint}"
|
||||
try:
|
||||
return self.session_.request(
|
||||
method="POST",
|
||||
url=url,
|
||||
json=post_body,
|
||||
headers={"Content-Type": "application/json"},
|
||||
headers=headers,
|
||||
)
|
||||
except requests.exceptions.RequestException as excpt:
|
||||
raise ConnectionError(
|
||||
f"Failed to send status={excpt.response.status_code} {excpt.response.text}" # type: ignore
|
||||
) from excpt
|
||||
|
||||
def send_get(self, endpoint: str) -> requests.Response:
|
||||
while not self.is_ready():
|
||||
print("Waiting for FrontGateway to start...")
|
||||
time.sleep(5)
|
||||
|
||||
def send_get(
|
||||
self, endpoint: str, headers: Optional[Dict[str, str]] = None
|
||||
) -> requests.Response:
|
||||
if not headers:
|
||||
headers = {}
|
||||
url = f"{self.base_url_}/{endpoint}"
|
||||
try:
|
||||
return self.session_.request(method="GET", url=url)
|
||||
return self.session_.request(method="GET", url=url, headers=headers)
|
||||
except requests.exceptions.RequestException as excpt:
|
||||
raise ConnectionError(
|
||||
f"Failed to send status={excpt.response.status_code} {excpt.response.text}" # type: ignore
|
||||
) from excpt
|
||||
```
|
||||
|
||||
@ -6,11 +6,11 @@ import requests
|
||||
from cvttpy_tools.base.base import NamedObject
|
||||
from cvttpy_tools.base.config import Config
|
||||
from cvttpy_tools.base.logger import Log
|
||||
from cvttpy_tools.comm.web.rest_client import RESTSender
|
||||
# ---
|
||||
from cvttpy_trading.trading.trading_instructions import TradingInstructions
|
||||
# ---
|
||||
from pairs_trading.apps.pair_trader import PairTrader
|
||||
from pairs_trading.lib.live.rest import RESTSender
|
||||
|
||||
|
||||
class TradingInstructionsSender(NamedObject):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user