-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into okx_implement_channel_inactive_listener
- Loading branch information
Showing
62 changed files
with
1,593 additions
and
182 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
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
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
43 changes: 43 additions & 0 deletions
43
xchange-binance/src/main/java/org/knowm/xchange/binance/dto/trade/TrailingFlag.java
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,43 @@ | ||
package org.knowm.xchange.binance.dto.trade; | ||
|
||
import org.knowm.xchange.dto.Order.IOrderFlags; | ||
|
||
/** | ||
* @see <a | ||
* href="https://github.com/binance/binance-spot-api-docs/blob/master/faqs/trailing-stop-faq.md">trailing-stop-faq</a> | ||
* @author mrmx | ||
*/ | ||
public enum TrailingFlag implements IOrderFlags { | ||
/** Trailing of 0.01% */ | ||
P0_01(1), | ||
/** Trailing of 0.1% */ | ||
P0_1(10), | ||
/** Trailing of 1% */ | ||
P1(100), | ||
/** Trailing of 10% */ | ||
P10(1000); | ||
/** Basis Points, also known as BIP or BIPS, are used to indicate a percentage change. */ | ||
private final long trailingBip; | ||
|
||
private TrailingFlag(long trailingBip) { | ||
this.trailingBip = trailingBip; | ||
} | ||
|
||
public long getTrailingBip() { | ||
return trailingBip; | ||
} | ||
|
||
static TrailingFlag of(Number percent) { | ||
switch (percent.toString()) { | ||
case "0.01": | ||
return P0_01; | ||
case "0.1": | ||
return P0_1; | ||
case "1": | ||
return P1; | ||
case "10": | ||
return P10; | ||
} | ||
throw new IllegalArgumentException("Invalid trailing " + percent); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
xchange-binance/src/test/java/org/knowm/xchange/binance/dto/trade/TrailingFlagTest.java
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,37 @@ | ||
package org.knowm.xchange.binance.dto.trade; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.catchIllegalArgumentException; | ||
import org.junit.Test; | ||
|
||
/** @author mrmx */ | ||
public class TrailingFlagTest { | ||
|
||
/** Test of method, of class BinanceOrderTrailingFlag. */ | ||
@Test | ||
public void testOfValue() { | ||
System.out.println("testOfValue"); | ||
List<Number> values = Arrays.asList(0.01, 0.1, 1, 10); | ||
for (Number value : values) { | ||
assertThat(TrailingFlag.of(value).getTrailingBip()).isBetween(1L, 1000L); | ||
} | ||
} | ||
|
||
/** Test of method, of class BinanceOrderTrailingFlag. */ | ||
@Test | ||
public void testOfValueWithInvalidNumbers() { | ||
System.out.println("testOfValueWithInvalidNumbers"); | ||
List<Number> values = Arrays.asList(0.011, 0.11, 2, 11); | ||
for (Number value : values) { | ||
assertThat( | ||
catchIllegalArgumentException( | ||
() -> { | ||
TrailingFlag.of(value); | ||
})) | ||
.as("Invalid value " + value) | ||
.isNotNull(); | ||
} | ||
} | ||
} |
Oops, something went wrong.