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

Commit

Permalink
fix: add timeout to exchange config (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
dolcalmi authored Sep 2, 2022
1 parent 2275350 commit 4507527
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions dealer/default.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
exchange:
REQUEST_TIMEOUT: 20000

hedging:
LOW_BOUND_RATIO_SHORTING: 0.95
LOW_SAFEBOUND_RATIO_SHORTING: 0.98
Expand Down
11 changes: 9 additions & 2 deletions dealer/src/ExchangeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export abstract class ExchangeBase {
exchangeConfig: ExchangeConfiguration
exchangeId: ExchangeId
headers: Headers
timeout?: number
fundingPassword: string
exchange: ccxt.okex5
logger: pino.Logger
Expand All @@ -58,6 +59,7 @@ export abstract class ExchangeBase {
this.exchangeConfig = exchangeConfig
this.exchangeId = exchangeConfig.exchangeId as ExchangeId
this.headers = exchangeConfig.headers
this.timeout = exchangeConfig.timeout

const apiKey = process.env[`${this.exchangeId.toUpperCase()}_KEY`]
const secret = process.env[`${this.exchangeId.toUpperCase()}_SECRET`]
Expand All @@ -71,8 +73,13 @@ export abstract class ExchangeBase {
this.fundingPassword = fundingPassword

const exchangeClass = ccxt[this.exchangeId]
this.exchange = new exchangeClass({ apiKey, secret, password, headers: this.headers })

this.exchange = new exchangeClass({
apiKey,
secret,
password,
headers: this.headers,
timeout: this.timeout,
})
this.exchange.options["createMarketBuyOrderRequiresPrice"] = false

// The following check throws if something is wrong
Expand Down
1 change: 1 addition & 0 deletions dealer/src/ExchangeConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface ExchangeConfiguration {
exchangeId: SupportedExchange
instrumentId: SupportedInstrument
headers: Headers
timeout?: number

fetchDepositAddressValidateInput(currency: string)
fetchDepositAddressProcessApiResponse(response): FetchDepositAddressResult
Expand Down
3 changes: 3 additions & 0 deletions dealer/src/OkexExchangeConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ export enum DestinationAddressType {
External = 4,
}

const exchange = yamlConfig.exchange
const hedgingBounds = yamlConfig.hedging
const withdrawalFees = yamlConfig.withdrawal

export class OkexExchangeConfiguration implements ExchangeConfiguration {
exchangeId: SupportedExchange
instrumentId: SupportedInstrument
headers: Headers
timeout?: number
positionMode: PositionMode
marginMode: MarginMode
leverage: number
Expand All @@ -68,6 +70,7 @@ export class OkexExchangeConfiguration implements ExchangeConfiguration {
this.minOnChainWithdrawalAmount = withdrawalFees.MIN_ON_CHAIN_WITHDRAWAL_AMOUNT
this.minOnChainWithdrawalFee = withdrawalFees.MIN_ON_CHAIN_WITHDRAWAL_FEE
this.maxOnChainWithdrawalFee = withdrawalFees.MAX_ON_CHAIN_WITHDRAWAL_FEE
this.timeout = exchange.REQUEST_TIMEOUT || 20000

if (process.env["NETWORK"] === "testnet") {
this.headers["x-simulated-trading"] = 1
Expand Down

0 comments on commit 4507527

Please sign in to comment.