-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
4 changed files
with
109 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
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,20 @@ | ||
package bybit.sdk.rest.asset | ||
|
||
import bybit.sdk.ext.coroutineToRestCallback | ||
import bybit.sdk.rest.ByBitRestApiCallback | ||
import bybit.sdk.rest.ByBitRestClient | ||
import kotlinx.coroutines.runBlocking | ||
|
||
class ByBitAssetClient | ||
internal constructor(internal val byBitRestClient: ByBitRestClient) { | ||
|
||
fun createUniversalTransferBlocking(params: CreateUniversalTransferParams): | ||
CreateUniversalTransferResponse = runBlocking { createUniversalTransfer(params) } | ||
|
||
fun createUniversalTransfer( | ||
params: CreateUniversalTransferParams, | ||
callback: ByBitRestApiCallback<CreateUniversalTransferResponse> | ||
) = coroutineToRestCallback(callback, { createUniversalTransfer(params) }) | ||
|
||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/kotlin/bybit/sdk/rest/asset/CreateUniversalTransfer.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,51 @@ | ||
package bybit.sdk.rest.asset | ||
|
||
import bybit.sdk.rest.APIResponseV5 | ||
import bybit.sdk.shared.AccountType | ||
import io.ktor.http.* | ||
import kotlinx.serialization.Serializable | ||
import lombok.Builder | ||
|
||
suspend fun ByBitAssetClient.createUniversalTransfer( | ||
params: CreateUniversalTransferParams | ||
): CreateUniversalTransferResponse = | ||
byBitRestClient.call({ | ||
path( | ||
"v5", | ||
"asset", | ||
"transfer", | ||
"universal-transfer", | ||
) | ||
|
||
params.transferId.let { parameters["transferId"] = it.toString() } | ||
params.coin.let { parameters["coin"] = it.toString() } | ||
params.amount.let { parameters["amount"] = it.toString() } | ||
|
||
params.fromMemberId.let { parameters["fromMemberId"] = it.toString() } | ||
params.toMemberId.let { parameters["toMemberId"] = it.toString() } | ||
|
||
params.fromAccountType.let { parameters["fromAccountType"] = it.toString() } | ||
params.toAccountType.let { parameters["toAccountType"] = it.toString() } | ||
|
||
}, HttpMethod.Post, false) | ||
|
||
@Builder | ||
data class CreateUniversalTransferParams( | ||
val transferId: String, // "be7a2462-1138-4e27-80b1-62653f24925e", | ||
val coin: String, // "ETH" | ||
val amount: String, // "0.4" | ||
val fromMemberId: Int, | ||
val toMemberId: Int, | ||
val fromAccountType: AccountType, | ||
val toAccountType: AccountType | ||
) | ||
|
||
@Serializable | ||
data class CreateUniversalTransferResult( | ||
val transferId: String | ||
) | ||
|
||
@Serializable | ||
data class CreateUniversalTransferResponse( | ||
val result: CreateUniversalTransferResult, | ||
) : APIResponseV5() |
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,35 @@ | ||
package bybit.sdk.rest | ||
|
||
|
||
import bybit.sdk.rest.asset.CreateUniversalTransferParams | ||
import bybit.sdk.shared.AccountType | ||
import java.util.* | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
internal class AssetClientTest { | ||
|
||
private var restClient: ByBitRestClient = | ||
ByBitRestClient( | ||
apiKey = System.getenv("BYBIT_API_KEY"), | ||
secret = System.getenv("BYBIT_SECRET"), | ||
testnet = true, | ||
httpClientProvider = okHttpClientProvider) | ||
|
||
@Test | ||
fun createUniversalTransfer() { | ||
val resp = restClient.assetClient.createUniversalTransferBlocking( | ||
CreateUniversalTransferParams( | ||
transferId = UUID.randomUUID().toString(), | ||
coin = "BTC", | ||
amount = "0.001", | ||
fromMemberId = 100488137, | ||
toMemberId = 408568, | ||
fromAccountType = AccountType.CONTRACT, | ||
toAccountType = AccountType.CONTRACT | ||
) | ||
) | ||
assertEquals(0, resp.retCode) | ||
assertEquals("success", resp.retMsg) | ||
} | ||
} |