bitget_swap_test.rs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. use std::collections::BTreeMap;
  2. use serde_json::json;
  3. use tracing::{info};
  4. use exchanges::bitget_swap_rest::BitgetSwapRest;
  5. const ACCESS_KEY: &str = "";
  6. const SECRET_KEY: &str = "";
  7. const PASS_KEY: &str = "";
  8. // 测试账户信息获取
  9. #[tokio::test]
  10. async fn rest_get_account_info_test() {
  11. global::log_utils::init_log_with_info();
  12. let mut rest = get_rest();
  13. let rep_data = rest.get_account_info().await;
  14. info!(?rep_data)
  15. }
  16. // 下单测试
  17. #[tokio::test]
  18. async fn post_order_test() {
  19. global::log_utils::init_log_with_info();
  20. let mut rest = get_rest();
  21. let params = json!({
  22. "symbol": "ethusdt",
  23. "productType": "USDT-FUTURES",
  24. "marginMode": "crossed",
  25. "marginCoin": "USDT",
  26. "size": "0.1",
  27. "price": "1999",
  28. "side": "buy",
  29. "tradeSide": "open",
  30. "orderType": "limit",
  31. "clientOid": "1130615111",
  32. "reduceOnly": "NO"
  33. });
  34. let response = rest.swap_order(params).await;
  35. info!(?response)
  36. }
  37. // 撤单测试
  38. #[tokio::test]
  39. async fn cancel_order_test() {
  40. global::log_utils::init_log_with_info();
  41. let mut rest = get_rest();
  42. let params = json!({
  43. "symbol": "ethusdt",
  44. "productType": "USDT-FUTURES",
  45. "clientOid": "1130615111",
  46. });
  47. let response = rest.cancel_order(params).await;
  48. info!(?response)
  49. }
  50. // 获取订单详情测试
  51. #[tokio::test]
  52. async fn get_order_test() {
  53. global::log_utils::init_log_with_info();
  54. let mut rest = get_rest();
  55. let params = json!({
  56. "symbol": "ETHUSDT",
  57. "productType": "USDT-FUTURES",
  58. "clientOid": "1130615132",
  59. });
  60. let response = rest.get_order(params).await;
  61. info!(?response)
  62. }
  63. // 获取当前的pending订单
  64. #[tokio::test]
  65. async fn get_pending_orders_test() {
  66. global::log_utils::init_log_with_info();
  67. let mut rest = get_rest();
  68. let response = rest.get_pending_orders().await;
  69. info!(?response)
  70. }
  71. // 设置杠杆测试
  72. #[tokio::test]
  73. async fn set_leverage_test() {
  74. global::log_utils::init_log_with_info();
  75. let mut rest = get_rest();
  76. let params = json!({
  77. "symbol": "ETHUSDT",
  78. "productType": "USDT-FUTURES",
  79. "marginCoin": "USDT",
  80. "leverage": "5"
  81. });
  82. let response = rest.set_leverage(params).await;
  83. info!(?response)
  84. }
  85. // 设置持仓模式
  86. #[tokio::test]
  87. async fn set_position_mode_test() {
  88. global::log_utils::init_log_with_info();
  89. let mut rest = get_rest();
  90. let params = json!({
  91. "productType": "USDT-FUTURES",
  92. "posMode": "hedge_mode",
  93. });
  94. let response = rest.set_position_mode(params).await;
  95. info!(?response)
  96. }
  97. // 获取仓位信息
  98. #[tokio::test]
  99. async fn get_single_position_test() {
  100. global::log_utils::init_log_with_info();
  101. let mut rest = get_rest();
  102. let params = json!({
  103. "productType": "USDT-FUTURES",
  104. "symbol": "ETHUSDT",
  105. "marginCoin": "USDT"
  106. });
  107. let response = rest.get_single_position(params).await;
  108. info!(?response)
  109. }
  110. fn get_rest() -> BitgetSwapRest {
  111. let mut btree_map: BTreeMap<String, String> = BTreeMap::new();
  112. btree_map.insert("access_key".to_string(), ACCESS_KEY.to_string());
  113. btree_map.insert("secret_key".to_string(), SECRET_KEY.to_string());
  114. btree_map.insert("pass_key".to_string(), PASS_KEY.to_string());
  115. BitgetSwapRest::new(false, btree_map)
  116. }