Skip to content

Commit 83fc825

Browse files
author
Fernando Fernandes
committed
Remove offset margin
1 parent 57e2784 commit 83fc825

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Sources/SwiftTrader/SwiftTrader+Offset.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ public extension SwiftTrader {
2121
let profitPercentage: Double = (input.profitPercentage / 100)
2222
logger.log("Profit percentage: \(profitPercentage.toDecimalString())")
2323

24-
// Instead of creating an order with a fixed target percentage (say 0.025), add some fat to it (e.g.: 0.027)
25-
let offsetMargin: Double = 0.02
26-
logger.log("Offset margin: \(offsetMargin.toDecimalString())")
27-
28-
// E.g.: (0.75 - 0.02) / 100 = 0.0073, which translates to 0.0027 (0,27%)
29-
let offset: Double = (input.offset - offsetMargin) / 100
24+
// E.g.: 0.75 -> 0.0075
25+
let offset: Double = (input.offset / 100)
3026
logger.log("Offset: \(offset.toDecimalString())")
3127

3228
// E.g.: (0.0747 - 0.0073) = 0.0674 (6,74%)

Sources/SwiftTrader/SwiftTrader.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,15 @@ public extension SwiftTrader {
9797
/// - Returns: An instance of `KucoinFuturesPlaceOrder` or `SwiftTraderError`.
9898
func kucoinFuturesPlaceOrder(_ orderInput: SwiftTraderOrderInput) async throws -> Result<KucoinFuturesPlaceOrder, SwiftTraderError> {
9999

100+
#warning("TODO: parameterize cleaning up untriggered stop orders")
100101
let orderParameters = try createOrderParameters(for: orderInput)
102+
103+
do {
104+
#warning("TODO: test")
105+
try await kucoinFuturesCancelStopOrders(symbol: orderInput.contractSymbol)
106+
} catch {
107+
#warning("TODO: log")
108+
}
101109

102110
let request = KucoinFuturesPlaceOrdersRequest(
103111
orderParameters: orderParameters,
@@ -124,7 +132,7 @@ public extension SwiftTrader {
124132
///
125133
/// - Parameter symbol: `String`, represents the specific contract for which all the untriggered stop orders will be cancelled.
126134
/// - Returns: An instance of `KucoinFuturesCancelStopOrders` or `SwiftTraderError`.
127-
func kucoinFuturesCancelStopOrders(symbol: String) async throws -> Result<KucoinFuturesCancelStopOrders, SwiftTraderError> {
135+
@discardableResult func kucoinFuturesCancelStopOrders(symbol: String) async throws -> Result<KucoinFuturesCancelStopOrders, SwiftTraderError> {
128136
let request = KucoinFuturesCancelOrdersRequest(
129137
symbol: symbol,
130138
kucoinAuth: kucoinAuth,

0 commit comments

Comments
 (0)