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