Skip to content

Commit c762c69

Browse files
committed
Add fee api
1 parent 918e6e0 commit c762c69

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

library/src/main/kotlin/one/mixin/bot/api/call/AssetCallService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package one.mixin.bot.api.call
22

33
import one.mixin.bot.api.MixinResponse
44
import one.mixin.bot.vo.Asset
5+
import one.mixin.bot.vo.AssetFee
56
import one.mixin.bot.vo.Fiat
67
import one.mixin.bot.vo.PendingDeposit
78
import one.mixin.bot.vo.Ticker
@@ -40,4 +41,7 @@ interface AssetCallService {
4041

4142
@GET("fiats")
4243
fun getFiatsCall(): Call<MixinResponse<List<Fiat>>>
44+
45+
@GET("assets/{id}/fee")
46+
fun assetsFeeCall(@Path("id") id: String): Call<MixinResponse<AssetFee>>
4347
}

library/src/main/kotlin/one/mixin/bot/api/coroutine/AssetCoroutineService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package one.mixin.bot.api.coroutine
22

33
import one.mixin.bot.api.MixinResponse
44
import one.mixin.bot.vo.Asset
5+
import one.mixin.bot.vo.AssetFee
56
import one.mixin.bot.vo.Fiat
67
import one.mixin.bot.vo.PendingDeposit
78
import one.mixin.bot.vo.Ticker
@@ -39,4 +40,7 @@ interface AssetCoroutineService {
3940

4041
@GET("fiats")
4142
suspend fun getFiats(): MixinResponse<List<Fiat>>
43+
44+
@GET("assets/{id}/fee")
45+
suspend fun assetsFee(@Path("id") id: String): MixinResponse<AssetFee>
4246
}

samples/src/main/java/jvmMain/java/Sample.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class Sample {
2525

2626
final static String userPin = "131416";
2727
final static String CNB_assetId = "965e5c6e-434c-3fa9-b780-c50f43cd955c";
28+
final static String BTC_assetId = "c6d0c728-2624-429b-8e0d-d9d19b6592fa";
2829
final static String amount = "2";
2930

3031
public static void main(String[] args) {
@@ -48,6 +49,9 @@ public static void main(String[] args) {
4849
// get fiats
4950
getFiats(client);
5051

52+
// get BTC fee
53+
getFee(client);
54+
5155
// create user's pin
5256
createPin(client, userAesKey);
5357

@@ -191,6 +195,16 @@ private static void getFiats(HttpClient client) throws IOException {
191195
}
192196
}
193197

198+
private static void getFee(HttpClient client) throws IOException {
199+
MixinResponse<AssetFee> feeResponse = client.getAssetService().assetsFeeCall(BTC_assetId).execute().body();
200+
assert feeResponse != null;
201+
if (feeResponse.isSuccess()) {
202+
System.out.printf("Fee success: %s%n", Objects.requireNonNull(feeResponse.getData()).getAmount());
203+
} else {
204+
System.out.println("Fee fail");
205+
}
206+
}
207+
194208
private static SessionToken getUserToken(User user, KeyPair sessionKey, boolean isRsa) {
195209
if (isRsa) {
196210
return new SessionToken.RSA(user.getUserId(), user.getSessionId(), sessionKey.getPrivate());

samples/src/main/java/jvmMain/kotlin/Sample.kt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import java.util.Random
2424
import java.util.UUID
2525

2626
const val CNB_ID = "965e5c6e-434c-3fa9-b780-c50f43cd955c"
27+
const val BTC_ID = "c6d0c728-2624-429b-8e0d-d9d19b6592fa"
2728
const val DEFAULT_PIN = "131416"
2829
const val DEFAULT_AMOUNT = "2"
2930

@@ -74,6 +75,9 @@ fun main() = runBlocking {
7475
// Get fiats
7576
getFiats(client)
7677

78+
// Get BTC fee
79+
getFee(client)
80+
7781
// Get asset
7882
getAsset(client)
7983

@@ -98,7 +102,7 @@ private suspend fun createUser(client: HttpClient, sessionSecret: String): User?
98102

99103
private suspend fun createPin(client: HttpClient, userAesKey: String) {
100104
val response = client.userService.createPin(
101-
PinRequest(requireNotNull(encryptPin(userAesKey, DEFAULT_PIN)))
105+
PinRequest(encryptPin(userAesKey, DEFAULT_PIN))
102106
)
103107
if (response.isSuccess()) {
104108
println("Create pin success ${response.data?.userId}")
@@ -141,10 +145,20 @@ private suspend fun getAsset(client: HttpClient) {
141145
private suspend fun getFiats(client: HttpClient) {
142146
// Get fiats
143147
val fiatsResponse = client.assetService.getFiats()
144-
if (fiatsResponse.isSuccess) {
145-
println("Assets ${fiatsResponse.data?.get(0)?.code}: ${fiatsResponse.data?.get(0)?.rate}")
148+
if (fiatsResponse.isSuccess()) {
149+
println("Fiats ${fiatsResponse.data?.get(0)?.code}: ${fiatsResponse.data?.get(0)?.rate}")
146150
} else {
147-
println("Assets fail")
151+
println("Fiats fail")
152+
}
153+
}
154+
155+
private suspend fun getFee(client: HttpClient) {
156+
// Get fee
157+
val feeResponse = client.assetService.assetsFee(BTC_ID)
158+
if (feeResponse.isSuccess()) {
159+
println("Fee ${feeResponse.data?.amount}")
160+
} else {
161+
println("Fee fail")
148162
}
149163
}
150164

0 commit comments

Comments
 (0)