Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

Commit

Permalink
chore: read and use dealer hedging disabled to skip
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Verreault committed Sep 21, 2022
1 parent 4507527 commit f94e6d4
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 70 deletions.
114 changes: 59 additions & 55 deletions dealer/src/Dealer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export class Dealer {
public async updatePositionAndLeverage(): Promise<
Result<UpdatedPositionAndLeverageResult>
> {
const hedging_disabled = process.env["HEDGING_DISABLED"]

const ret = await asyncRunInSpan(
"app.dealer.updatePositionAndLeverage",
{
Expand Down Expand Up @@ -204,69 +206,71 @@ export class Dealer {

const result = {} as UpdatedPositionAndLeverageResult

if (usdLiability < hedgingBounds.MINIMUM_POSITIVE_LIABILITY_USD) {
logger.debug(
{ usdLiability },
"No liabilities to hedge, skipping the order loop and closing position if any",
)

addAttributesToCurrentSpan({
[`${SemanticAttributes.CODE_FUNCTION}.results.orderLoopSkipped`]: true,
})

await this.strategy.closePosition()

result.updatePositionSkipped = true
} else {
logger.debug("starting with order loop")

const updatedPositionResult = await this.strategy.updatePosition(
usdLiability,
btcPriceInUsd,
)
result.updatedPositionResult = updatedPositionResult
if (updatedPositionResult.ok) {
const originalPosition = updatedPositionResult.value.originalPosition
const updatedPosition = updatedPositionResult.value.updatedPosition
result.updatePositionSkipped = true
if (!hedging_disabled) {
if (usdLiability < hedgingBounds.MINIMUM_POSITIVE_LIABILITY_USD) {
logger.debug(
{ usdLiability },
"No liabilities to hedge, skipping the order loop and closing position if any",
)

addAttributesToCurrentSpan({
[`${SemanticAttributes.CODE_FUNCTION}.results.updatePosition.success`]:
true,
[`${SemanticAttributes.CODE_FUNCTION}.results.updatePosition.originalPosition`]:
JSON.stringify(originalPosition),
[`${SemanticAttributes.CODE_FUNCTION}.results.updatePosition.updatedPosition`]:
JSON.stringify(updatedPosition),
[`${SemanticAttributes.CODE_FUNCTION}.results.orderLoopSkipped`]: true,
})

logger.info(
{
usdLiability,
btcPriceInUsd,
activeStrategy: this.strategy.name,
originalPosition,
updatedPosition,
},
"The {activeStrategy} was successful at UpdatePosition({usdLiability}, {btcPriceInUsd})",
)
await this.strategy.closePosition()

result.updatePositionSkipped = true
} else {
addAttributesToCurrentSpan({
[`${SemanticAttributes.CODE_FUNCTION}.results.updatePosition.success`]:
false,
[`${SemanticAttributes.CODE_FUNCTION}.results.updatePosition.error`]:
JSON.stringify(updatedPositionResult.error),
})
logger.error(
{
usdLiability,
btcPriceInUsd,
activeStrategy: this.strategy.name,
updatedPosition: updatedPositionResult,
},
"The {activeStrategy} failed during the UpdatePosition({usdLiability}, {btcPriceInUsd}) execution",
logger.debug("starting with order loop")

const updatedPositionResult = await this.strategy.updatePosition(
usdLiability,
btcPriceInUsd,
)
result.updatedPositionResult = updatedPositionResult
if (updatedPositionResult.ok) {
const originalPosition = updatedPositionResult.value.originalPosition
const updatedPosition = updatedPositionResult.value.updatedPosition

addAttributesToCurrentSpan({
[`${SemanticAttributes.CODE_FUNCTION}.results.updatePosition.success`]:
true,
[`${SemanticAttributes.CODE_FUNCTION}.results.updatePosition.originalPosition`]:
JSON.stringify(originalPosition),
[`${SemanticAttributes.CODE_FUNCTION}.results.updatePosition.updatedPosition`]:
JSON.stringify(updatedPosition),
})

logger.info(
{
usdLiability,
btcPriceInUsd,
activeStrategy: this.strategy.name,
originalPosition,
updatedPosition,
},
"The {activeStrategy} was successful at UpdatePosition({usdLiability}, {btcPriceInUsd})",
)
} else {
addAttributesToCurrentSpan({
[`${SemanticAttributes.CODE_FUNCTION}.results.updatePosition.success`]:
false,
[`${SemanticAttributes.CODE_FUNCTION}.results.updatePosition.error`]:
JSON.stringify(updatedPositionResult.error),
})
logger.error(
{
usdLiability,
btcPriceInUsd,
activeStrategy: this.strategy.name,
updatedPosition: updatedPositionResult,
},
"The {activeStrategy} failed during the UpdatePosition({usdLiability}, {btcPriceInUsd}) execution",
)
}
}
}

// Check for any in-flight fund transfer, and skip if not all completed
const dbCallResult = await database.inFlightTransfers.getPendingCount()
if (dbCallResult.ok && dbCallResult.value === 0) {
Expand Down
31 changes: 16 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ networks:
monitoring:
driver: bridge
volumes:
prometheus_data: {}
grafana_data: {}
prometheus_data: {}
grafana_data: {}
services:
otel-agent:
image: otel/opentelemetry-collector-contrib:0.43.0
command: ["--config=/etc/otel-agent-config.yaml"]
command: [ "--config=/etc/otel-agent-config.yaml" ]
environment:
- HONEYCOMB_DATASET=${HONEYCOMB_DATASET}
- HONEYCOMB_API_KEY=${HONEYCOMB_API_KEY}
- HONEYCOMB_DATASET=${HONEYCOMB_DATASET}
- HONEYCOMB_API_KEY=${HONEYCOMB_API_KEY}
volumes:
- ./dev/otel-agent-config.yaml:/etc/otel-agent-config.yaml
prometheus:
Expand Down Expand Up @@ -51,9 +51,9 @@ services:
dockerfile: dealer/Dockerfile
depends_on:
postgres:
condition: service_healthy
condition: service_healthy
extra_hosts:
- "host.docker.internal:host-gateway"
- "host.docker.internal:host-gateway"
links:
- postgres
- graphql
Expand All @@ -67,33 +67,34 @@ services:
- monitoring
environment:
# HEDGING_NOT_IN_SIMULATION: ${HEDGING_NOT_IN_SIMULATION}
HEDGING_DISABLED: ${HEDGING_DISABLED}
NETWORK: ${NETWORK}
LOG_LEVEL: ${LOG_LEVEL}
#
#
ACTIVE_STRATEGY: ${ACTIVE_STRATEGY}
ACTIVE_WALLET: ${ACTIVE_WALLET}
#
#
OKEX5_KEY: ${OKEX5_KEY}
OKEX5_SECRET: ${OKEX5_SECRET}
OKEX5_PASSWORD: ${OKEX5_PASSWORD}
OKEX5_FUND_PASSWORD: ${OKEX5_FUND_PASSWORD}
#
#
GRAPHQL_URI: ${GRAPHQL_URI}
DATABASE_URL: ${DATABASE_URL}
JAEGER_HOST: ${JAEGER_HOST}
#
#
DEALER_PHONE: ${DEALER_PHONE}
DEALER_CODE: ${DEALER_CODE}
DEALER_TOKEN: ${DEALER_TOKEN}
#
#
DEALER_BTC_BAL_OFFSET: ${DEALER_BTC_BAL_OFFSET}
DEALER_USD_BAL_OFFSET: ${DEALER_USD_BAL_OFFSET}
graphql:
build:
context: .
dockerfile: dealer/src/servers/graphql/Dockerfile
extra_hosts:
- "host.docker.internal:host-gateway"
- "host.docker.internal:host-gateway"
links:
- postgres
ports:
Expand All @@ -112,15 +113,15 @@ services:
- "5432:5432"
networks:
- monitoring
volumes:
volumes:
- ../postgresdata:/var/lib/postgresql/data
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: galoy
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 5s
timeout: 5s
retries: 5

0 comments on commit f94e6d4

Please sign in to comment.