Skip to content

Commit

Permalink
refactor: sgt trailing modes lp
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-angjelkoski committed Nov 12, 2024
1 parent ed53be7 commit 08c8e78
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ExitConfig,
StrategyType,
TrailingArithmetic,
TrailingArithmeticLP,
} from '../types.js'
export declare namespace ExecArgCreateSpotGridStrategy {
export interface Params {
Expand All @@ -21,7 +22,11 @@ export declare namespace ExecArgCreateSpotGridStrategy {
takeProfit?: ExitConfig
exitType?: ExitType
strategyType?: StrategyType
trailingArithmetic?: TrailingArithmetic
trailingArithmetic?: {
upperTrailing: string
lowerTrailing: string
lpMode?: boolean
}
}

export interface Data {
Expand All @@ -38,7 +43,7 @@ export declare namespace ExecArgCreateSpotGridStrategy {
exit_price: string
}
exit_type?: ExitType
strategy_type?: StrategyType | TrailingArithmetic
strategy_type?: StrategyType | TrailingArithmetic | TrailingArithmeticLP
}
}

Expand All @@ -58,6 +63,20 @@ export default class ExecArgCreateSpotGridStrategy extends ExecArgBase<
toData(): ExecArgCreateSpotGridStrategy.Data {
const { params } = this

const trailingBounds = params.trailingArithmetic
? {
upper_trailing_bound: params.trailingArithmetic.upperTrailing,
lower_trailing_bound: params.trailingArithmetic.lowerTrailing,
}
: undefined

const strategyType =
params.trailingArithmetic && trailingBounds
? params.trailingArithmetic.lpMode
? { trailing_arithmetic_lp: trailingBounds }
: { trailing_arithmetic: trailingBounds }
: params.strategyType ?? StrategyType.Arithmetic

return {
subaccount_id: params.subaccountId,
levels: params.levels,
Expand All @@ -76,7 +95,7 @@ export default class ExecArgCreateSpotGridStrategy extends ExecArgBase<
exit_price: params.takeProfit.exitPrice,
}
: undefined,
strategy_type: params.trailingArithmetic ?? params.strategyType,
strategy_type: strategyType,
}
}

Expand Down
8 changes: 8 additions & 0 deletions packages/sdk-ts/src/core/modules/wasm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum ExitType {

export enum StrategyType {
Arithmetic = 'arithmetic',
ArithmeticLP = 'arithmetic_lp',
Geometric = 'geometric',
}

Expand All @@ -16,6 +17,13 @@ export type TrailingArithmetic = {
}
}

export type TrailingArithmeticLP = {
trailing_arithmetic_lp: {
lower_trailing_bound: string
upper_trailing_bound: string
}
}

export type ExitConfig = {
exitType: ExitType
exitPrice: string
Expand Down

0 comments on commit 08c8e78

Please sign in to comment.