-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added futures support (OKEx, Binance, Huobi, FTX)
- Loading branch information
Showing
18 changed files
with
535 additions
and
297 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
25 changes: 0 additions & 25 deletions
25
dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/model/Futures.kt
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/model/FuturesContractType.kt
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,75 @@ | ||
package com.aneonex.bitcoinchecker.datamodule.model | ||
|
||
import java.time.DayOfWeek | ||
import java.time.LocalDate | ||
import java.time.ZoneOffset | ||
import java.time.temporal.TemporalAdjusters | ||
|
||
enum class FuturesContractType(val value: Int) { | ||
NONE(0), | ||
PERPETUAL(1), | ||
WEEKLY(2), | ||
BIWEEKLY(3), | ||
MONTHLY(4), | ||
BIMONTHLY(5), | ||
QUARTERLY(6), | ||
BIQUARTERLY(7); | ||
|
||
override fun toString(): String { | ||
return getShortName(this) ?: "None" | ||
} | ||
|
||
companion object { | ||
fun fromInt(value: Int): FuturesContractType = values().firstOrNull { it.value == value } ?: NONE | ||
|
||
fun getShortName(contractType: FuturesContractType): String? = | ||
when (contractType) { | ||
NONE -> null | ||
PERPETUAL -> | ||
@Suppress("SpellCheckingInspection") | ||
"Perp" | ||
WEEKLY -> "1W" | ||
BIWEEKLY -> "2W" | ||
MONTHLY -> "1M" | ||
BIMONTHLY -> "2M" | ||
QUARTERLY -> "1Q" | ||
BIQUARTERLY -> "2Q" | ||
} | ||
|
||
fun getDeliveryDate(contractType: FuturesContractType): LocalDate? { | ||
fun getCurrentDate() = LocalDate.now(ZoneOffset.UTC) | ||
|
||
return when(contractType) { | ||
NONE, | ||
PERPETUAL -> | ||
null | ||
|
||
WEEKLY -> getEndOfWeek(getCurrentDate()) | ||
BIWEEKLY -> getEndOfWeek(getCurrentDate().plusWeeks(1)) | ||
|
||
MONTHLY -> getEndOfMonth(getCurrentDate()) | ||
BIMONTHLY -> getEndOfMonth(getCurrentDate().plusMonths(1)) | ||
|
||
QUARTERLY -> getEndOfQuarter(getCurrentDate()) | ||
BIQUARTERLY -> getEndOfQuarter(getCurrentDate().plusMonths(3)) | ||
// else -> throw MarketParseException("Unexpected contact type") | ||
} | ||
} | ||
|
||
private fun getEndOfWeek(currentDate: LocalDate): LocalDate = | ||
if(currentDate.dayOfWeek == DayOfWeek.FRIDAY) currentDate | ||
else currentDate.with(TemporalAdjusters.next(DayOfWeek.FRIDAY)) | ||
|
||
private fun getEndOfMonth(currentDate: LocalDate): LocalDate = | ||
currentDate.with(TemporalAdjusters.lastInMonth(DayOfWeek.FRIDAY)) | ||
|
||
private fun getEndOfQuarter(currentDate: LocalDate): LocalDate { | ||
val firstDayOfQuarter: LocalDate = | ||
currentDate.with(currentDate.month.firstMonthOfQuarter()) | ||
.with(TemporalAdjusters.firstDayOfMonth()) | ||
|
||
return firstDayOfQuarter.plusMonths(2) | ||
.with(TemporalAdjusters.lastInMonth(DayOfWeek.FRIDAY)) | ||
} | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
dataModule/src/main/java/com/aneonex/bitcoinchecker/datamodule/model/FuturesMarket.kt
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.