pm2 + sig handling
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
9cdbc8d234
commit
24756fbb7f
|
@ -2,6 +2,7 @@ mango-service-v3/node_modules
|
|||
mango-service-v3/dist
|
||||
mango-service-v3/run-dev-server.sh
|
||||
mango-service-v3/run-build-and-publish-docker-image.sh
|
||||
mango-service-v3/run-build-and-test-docker-locally.sh
|
||||
mango-service-v3/run-update-api-docs.sh
|
||||
py/.venv
|
||||
py/.idea
|
||||
|
|
|
@ -26,6 +26,8 @@ See Todos
|
|||
# Todos
|
||||
## Small
|
||||
losely sorted in order of importance/priority
|
||||
- devenet integration tests
|
||||
- retry framework in python
|
||||
- error thrown in endpoints just crashes expressjs, need explicit handling
|
||||
- rpc node related issues
|
||||
- how to ensure that order has been placed or definitely not placed?
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
FROM node:16
|
||||
|
||||
RUN npm install -g pm2
|
||||
|
||||
WORKDIR /usr
|
||||
COPY package.json ./
|
||||
COPY yarn.lock ./
|
||||
RUN yarn install
|
||||
COPY . .
|
||||
RUN yarn build
|
||||
|
||||
ENV PORT=3000
|
||||
|
||||
CMD [ "yarn", "dev" ]
|
||||
CMD ["pm2-docker", "start", "dist/server.js", "-i", "1", "-n", "mango-service-v3", "--max-memory-restart", "200M"]
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
import { logger } from "./utils";
|
||||
import App from "./app";
|
||||
|
||||
process.on("SIGTERM", function () {
|
||||
console.log("SIGTERM received");
|
||||
// todo add cleanup logic
|
||||
process.exit();
|
||||
});
|
||||
|
||||
process.on("SIGINT", function () {
|
||||
console.log("SIGINT received");
|
||||
// todo add cleanup logic
|
||||
process.exit();
|
||||
});
|
||||
|
||||
const app = new App();
|
||||
|
||||
app.listen();
|
||||
|
||||
// todo add a handler for ctrl+c from docker
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from mango_service_v3_py.api import MangoServiceV3Client
|
||||
from mango_service_v3_py.dtos import PlaceOrder
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
import time
|
||||
|
||||
from mango_service_v3_py.api import MangoServiceV3Client
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
mango_service_v3_client = MangoServiceV3Client()
|
||||
sleep = 0.5
|
||||
while True:
|
||||
try:
|
||||
resp = mango_service_v3_client.get_balances()
|
||||
print(resp)
|
||||
sleep = sleep * 2
|
||||
time.sleep(sleep)
|
||||
except:
|
||||
pass
|
|
@ -1,4 +1,3 @@
|
|||
import os
|
||||
import time
|
||||
|
||||
from mango_service_v3_py.api import MangoServiceV3Client
|
||||
|
|
|
@ -245,7 +245,7 @@ class MM:
|
|||
if __name__ == "__main__":
|
||||
|
||||
mm = MM()
|
||||
logger.info("deleting all orders...")
|
||||
logger.info("cancelling all orders...")
|
||||
|
||||
try:
|
||||
mm.mango_service_v3_client.cancel_all_orders()
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import json
|
||||
import os
|
||||
import time
|
||||
from decimal import Decimal
|
||||
from threading import Timer
|
||||
from typing import List
|
||||
|
||||
import httpx
|
||||
|
@ -41,41 +39,34 @@ class MangoServiceV3Client:
|
|||
else:
|
||||
self.BASE_URL = "http://localhost:3000/api"
|
||||
|
||||
@delayed(2)
|
||||
def get_open_positions(self) -> List[Position]:
|
||||
response = httpx.get(f"{self.BASE_URL}/positions", timeout=10.0)
|
||||
return parse_obj_as(List[Position], json.loads(response.text)["result"])
|
||||
|
||||
@delayed(2)
|
||||
def get_balances(self) -> List[Balance]:
|
||||
response = httpx.get(f"{self.BASE_URL}/wallet/balances", timeout=10.0)
|
||||
return parse_obj_as(List[Balance], json.loads(response.text)["result"])
|
||||
|
||||
@delayed(2)
|
||||
def get_markets(self) -> List[Market]:
|
||||
response = httpx.get(f"{self.BASE_URL}/markets", timeout=10.0)
|
||||
return parse_obj_as(List[Market], json.loads(response.text)["result"])
|
||||
|
||||
@delayed(2)
|
||||
def get_market_by_market_name(self, market_name: str) -> List[Market]:
|
||||
response = httpx.get(f"{self.BASE_URL}/markets/{market_name}", timeout=10.0)
|
||||
return parse_obj_as(List[Market], json.loads(response.text)["result"])
|
||||
|
||||
@delayed(2)
|
||||
def get_orderboook(self, market_name: str, depth: int = 30) -> Orderbook:
|
||||
response = httpx.get(
|
||||
f"{self.BASE_URL}/markets/{market_name}/orderbook?depth={depth}"
|
||||
)
|
||||
return parse_obj_as(Orderbook, json.loads(response.text)["result"])
|
||||
|
||||
@delayed(2)
|
||||
def get_trades(self, market_name: str) -> List[Trade]:
|
||||
response = httpx.get(
|
||||
f"{self.BASE_URL}/markets/{market_name}/trades", timeout=10.0
|
||||
)
|
||||
return parse_obj_as(List[Trade], json.loads(response.text)["result"])
|
||||
|
||||
@delayed(2)
|
||||
def get_candles(
|
||||
self, market_name: str, resolution: int, start_time: int, end_time: int
|
||||
) -> List[Candle]:
|
||||
|
@ -84,19 +75,16 @@ class MangoServiceV3Client:
|
|||
)
|
||||
return parse_obj_as(List[Candle], json.loads(response.text)["result"])
|
||||
|
||||
@delayed(2)
|
||||
def get_orders(self,) -> List[Order]:
|
||||
response = httpx.get(f"{self.BASE_URL}/orders", timeout=10.0)
|
||||
return parse_obj_as(List[Order], json.loads(response.text)["result"])
|
||||
|
||||
@delayed(2)
|
||||
def get_orders_by_market_name(self, market_name: str) -> List[Order]:
|
||||
response = httpx.get(
|
||||
f"{self.BASE_URL}/orders?market={market_name}", timeout=10.0
|
||||
)
|
||||
return parse_obj_as(List[Order], json.loads(response.text)["result"])
|
||||
|
||||
@delayed(2)
|
||||
def place_order(self, order: PlaceOrder) -> None:
|
||||
response = httpx.post(
|
||||
f"{self.BASE_URL}/orders", json=order.dict(by_alias=True), timeout=10.0
|
||||
|
@ -106,17 +94,14 @@ class MangoServiceV3Client:
|
|||
# List[BadRequestError], json.loads(response.text)["errors"]
|
||||
# )
|
||||
|
||||
@delayed(2)
|
||||
def cancel_order_by_client_id(self, client_id):
|
||||
response = httpx.delete(
|
||||
f"{self.BASE_URL}/orders/by_client_id/{client_id}", timeout=10.0
|
||||
)
|
||||
|
||||
@delayed(2)
|
||||
def cancel_order_by_order_id(self, order_id):
|
||||
response = httpx.delete(f"{self.BASE_URL}/orders/{order_id}", timeout=10.0)
|
||||
|
||||
@delayed(2)
|
||||
def cancel_all_orders(self):
|
||||
response = httpx.delete(f"{self.BASE_URL}/orders", timeout=10.0)
|
||||
|
||||
|
|
Loading…
Reference in New Issue