Skip to content

Commit 6f0d427

Browse files
author
Fernando Fernandes
committed
Add tickerSize as parameter
1 parent c06576d commit 6f0d427

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Sources/SwiftTrader/Model/SwiftTraderOrderInput.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public struct SwiftTraderOrderInput {
1414

1515
public let exchange: SwiftTraderExchange
1616
public let ticker: String
17+
public let tickerSize: String
1718
public let contractSymbol: String
1819
public let entryPrice: Double
1920
public let currentPrice: Double
@@ -24,13 +25,15 @@ public struct SwiftTraderOrderInput {
2425

2526
public init(exchange: SwiftTraderExchange,
2627
ticker: String,
28+
tickerSize: String,
2729
contractSymbol: String,
2830
entryPrice: Double,
2931
currentPrice: Double,
3032
profitPercentage: Double,
3133
offset: Double) {
3234
self.exchange = exchange
3335
self.ticker = ticker
36+
self.tickerSize = tickerSize
3437
self.contractSymbol = contractSymbol
3538
self.entryPrice = entryPrice
3639
self.currentPrice = currentPrice

Sources/SwiftTrader/SwiftTrader+Offset.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public extension SwiftTrader {
3030
logger.log("Offset: \(offset.toDecimalString())")
3131

3232
// E.g.: (0.0747 - 0.0073) = 0.0674 (6,74%)
33-
let targetPercentage: Double = profitPercentage - offset
33+
// Use "abs" to filter out negative numbers.
34+
let targetPercentage: Double = abs(profitPercentage - offset)
3435
logger.log("Target percentage: \(targetPercentage.toDecimalString())")
3536

3637
// E.g.: 42000.69 * 0.0674 = 2830.846506
@@ -55,7 +56,7 @@ public extension SwiftTrader {
5556
// "44831.536506" becomes "44831.53".
5657
let charactersToBeRemoved = abs(targetPriceCount - entryPriceCount)
5758
var targetPriceString = "\(targetPrice.toDecimalString())".dropLast(charactersToBeRemoved)
58-
logger.log("Target price normalize: \(targetPriceString)")
59+
logger.log("Target price normalized: \(targetPriceString)")
5960

6061
// Finally, avoid the following Kucoin error with minimal effort: "The parameter shall be a multiple of ..."
6162
// First, just try replacing the last character by "1". E.g.: "0.00002347" becomes "0.00002341"
@@ -73,6 +74,7 @@ public extension SwiftTrader {
7374
// error when you place the order. The tick size is the smallest price increment in which the prices are quoted.
7475
if let priceDouble = Double(targetPriceString), priceDouble > 10 {
7576
targetPriceString = "\(priceDouble.rounded(.down).toDecimalString())"
77+
logger.log("Target price string: \(targetPriceString)")
7678
}
7779

7880
return KucoinOrderParameters(

0 commit comments

Comments
 (0)