bitget_swap_test.rs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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": "BTCUSDT",
  23. "productType": "USDT-FUTURES",
  24. "marginMode": "crossed",
  25. "marginCoin": "USDT",
  26. "size": "0.001",
  27. "side": "buy",
  28. "tradeSide": "close",
  29. "orderType": "market",
  30. "clientOid": "1130615113245"
  31. });
  32. let response = rest.swap_order(params).await;
  33. info!(?response)
  34. }
  35. // 撤单测试
  36. #[tokio::test]
  37. async fn cancel_order_test() {
  38. global::log_utils::init_log_with_info();
  39. let mut rest = get_rest();
  40. let params = json!({
  41. "symbol": "ethusdt",
  42. "productType": "USDT-FUTURES",
  43. "clientOid": "1130615111",
  44. });
  45. let response = rest.cancel_order(params).await;
  46. info!(?response)
  47. }
  48. // 获取订单详情测试
  49. #[tokio::test]
  50. async fn get_order_test() {
  51. global::log_utils::init_log_with_info();
  52. let mut rest = get_rest();
  53. let params = json!({
  54. "symbol": "ETHUSDT",
  55. "productType": "USDT-FUTURES",
  56. "clientOid": "1130615132",
  57. });
  58. let response = rest.get_order(params).await;
  59. info!(?response)
  60. }
  61. // 获取当前的pending订单
  62. #[tokio::test]
  63. async fn get_pending_orders_test() {
  64. global::log_utils::init_log_with_info();
  65. let mut rest = get_rest();
  66. let response = rest.get_pending_orders().await;
  67. info!(?response)
  68. }
  69. // 设置杠杆测试
  70. #[tokio::test]
  71. async fn set_leverage_test() {
  72. global::log_utils::init_log_with_info();
  73. let mut rest = get_rest();
  74. let params = json!({
  75. "symbol": "ETHUSDT",
  76. "productType": "USDT-FUTURES",
  77. "marginCoin": "USDT",
  78. "leverage": "5"
  79. });
  80. let response = rest.set_leverage(params).await;
  81. info!(?response)
  82. }
  83. // 设置持仓模式
  84. #[tokio::test]
  85. async fn set_position_mode_test() {
  86. global::log_utils::init_log_with_info();
  87. let mut rest = get_rest();
  88. let params = json!({
  89. "productType": "USDT-FUTURES",
  90. "posMode": "hedge_mode",
  91. });
  92. let response = rest.set_position_mode(params).await;
  93. info!(?response)
  94. }
  95. // 获取仓位信息
  96. #[tokio::test]
  97. async fn get_single_position_test() {
  98. global::log_utils::init_log_with_info();
  99. let mut rest = get_rest();
  100. let params = json!({
  101. "productType": "USDT-FUTURES",
  102. "symbol": "ETHUSDT",
  103. "marginCoin": "USDT"
  104. });
  105. let response = rest.get_single_position(params).await;
  106. info!(?response)
  107. }
  108. fn get_rest() -> BitgetSwapRest {
  109. let mut btree_map: BTreeMap<String, String> = BTreeMap::new();
  110. btree_map.insert("access_key".to_string(), ACCESS_KEY.to_string());
  111. btree_map.insert("secret_key".to_string(), SECRET_KEY.to_string());
  112. btree_map.insert("pass_key".to_string(), PASS_KEY.to_string());
  113. BitgetSwapRest::new(false, btree_map)
  114. }