-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b554646
commit 063551f
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/sdk-ts/src/core/modules/wasm/exec-args/ExecArgCreatePerpGridStrategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { | ||
dataToExecData, | ||
ExecArgBase, | ||
ExecDataRepresentation, | ||
} from '../ExecArgBase' | ||
|
||
import { ExitConfig, ExitType } from '../types' | ||
export declare namespace ExecArgCreatePerpGridStrategy { | ||
export interface Params { | ||
subaccountId: string | ||
lowerBound: string | ||
upperBound: string | ||
levels: number | ||
slippage?: string | ||
stopLoss?: string | ||
takeProfit?: string | ||
marginRatio: string | ||
} | ||
|
||
export interface Data { | ||
subaccount_id: string | ||
bounds: [string, string] | ||
slippage?: string | ||
stop_loss?: ExitConfig | ||
take_profit?: ExitConfig | ||
levels: number | ||
strategy_type: { | ||
perpetual: { | ||
margin_ratio: string | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @category Contract Exec Arguments | ||
*/ | ||
export default class ExecArgCreatePerpGridStrategy extends ExecArgBase< | ||
ExecArgCreatePerpGridStrategy.Params, | ||
ExecArgCreatePerpGridStrategy.Data | ||
> { | ||
static fromJSON( | ||
params: ExecArgCreatePerpGridStrategy.Params, | ||
): ExecArgCreatePerpGridStrategy { | ||
return new ExecArgCreatePerpGridStrategy(params) | ||
} | ||
|
||
toData(): ExecArgCreatePerpGridStrategy.Data { | ||
const { params } = this | ||
|
||
return { | ||
subaccount_id: params.subaccountId, | ||
bounds: [params.lowerBound, params.upperBound], | ||
levels: params.levels, | ||
slippage: params.slippage, | ||
strategy_type: { | ||
perpetual: { | ||
margin_ratio: params.marginRatio, | ||
}, | ||
}, | ||
stop_loss: params.stopLoss | ||
? { | ||
exitType: ExitType.Default, | ||
exitPrice: params.stopLoss, | ||
} | ||
: undefined, | ||
take_profit: params.takeProfit | ||
? { | ||
exitType: ExitType.Default, | ||
exitPrice: params.takeProfit, | ||
} | ||
: undefined, | ||
} | ||
} | ||
|
||
toExecData(): ExecDataRepresentation<ExecArgCreatePerpGridStrategy.Data> { | ||
return dataToExecData('create_strategy', this.toData()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters