|
|
@@ -279,22 +279,23 @@ impl Platform for BitgetSwap {
|
|
|
}
|
|
|
|
|
|
async fn get_order_detail(&mut self, order_id: &str, custom_id: &str) -> Result<Order, Error> {
|
|
|
- Err(Error::new(ErrorKind::NotFound, "bitget_swap get_order_detail:该交易所方法未实现".to_string()))
|
|
|
- // let ct_val = self.market.ct_val;
|
|
|
- // let res_data = self.request.get_order(order_id.to_string(), custom_id.to_string()).await;
|
|
|
- // if res_data.code == "200" {
|
|
|
- // let res_data_str = &res_data.data;
|
|
|
- // let res_data_json: Vec<serde_json::Value> = serde_json::from_str(res_data_str).unwrap();
|
|
|
- // if res_data_json.len() == 0 {
|
|
|
- // Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
- // } else {
|
|
|
- // let order_info = res_data_json[0].clone();
|
|
|
- // let result = format_order_item(order_info, ct_val);
|
|
|
- // Ok(result)
|
|
|
- // }
|
|
|
- // } else {
|
|
|
- // Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
- // }
|
|
|
+ let symbol_format = utils::format_symbol(self.symbol.clone(), "");
|
|
|
+ let params = json!({
|
|
|
+ "symbol": symbol_format,
|
|
|
+ "productType": "USDT-FUTURES",
|
|
|
+ "clientOid": custom_id,
|
|
|
+ "orderId": order_id
|
|
|
+ });
|
|
|
+
|
|
|
+ let ct_val = self.market.ct_val;
|
|
|
+ let response = self.request.get_order(params).await;
|
|
|
+ if response.code == "200" {
|
|
|
+ let res_data_json = response.data;
|
|
|
+ let result = format_order_item(res_data_json, ct_val);
|
|
|
+ Ok(result)
|
|
|
+ } else {
|
|
|
+ Err(Error::new(ErrorKind::Other, response.to_string()))
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
async fn get_orders_list(&mut self, _status: &str) -> Result<Vec<Order>, Error> {
|
|
|
@@ -313,132 +314,96 @@ impl Platform for BitgetSwap {
|
|
|
}
|
|
|
|
|
|
async fn take_order(&mut self, custom_id: &str, origin_side: &str, price: Decimal, amount: Decimal) -> Result<Order, Error> {
|
|
|
- Err(Error::new(ErrorKind::NotFound, "bitget_swap take_order:该交易所方法未实现".to_string()))
|
|
|
- // let symbol_format = utils::format_symbol(self.symbol.clone(), "");
|
|
|
- // let mut params = json!({
|
|
|
- // "symbol": symbol_format.to_string(),
|
|
|
- // "clientOid": custom_id,
|
|
|
- // "price": price.to_string(),
|
|
|
- // });
|
|
|
- // if price.eq(&Decimal::ZERO) {
|
|
|
- // params["orderType"] = json!("market");
|
|
|
- // params["force"] = json!("post_only");
|
|
|
- // } else {
|
|
|
- // params["orderType"] = json!("limit");
|
|
|
- // params["force"] = json!("gtc");
|
|
|
- // };
|
|
|
- // params["size"] = json!(amount);
|
|
|
- // match origin_side {
|
|
|
- // "kd" => {
|
|
|
- // params["side"] = json!("buy");
|
|
|
- // }
|
|
|
- // "pd" => {
|
|
|
- // params["side"] = json!("sell");
|
|
|
- // }
|
|
|
- // "kk" => {
|
|
|
- // params["side"] = json!("sell");
|
|
|
- // }
|
|
|
- // "pk" => {
|
|
|
- // params["side"] = json!("buy");
|
|
|
- // }
|
|
|
- // _ => { error!("下单参数错误"); }
|
|
|
- // };
|
|
|
- // let res_data = self.request.spot_order(params).await;
|
|
|
- // if res_data.code == "200" {
|
|
|
- // let res_data_str = &res_data.data;
|
|
|
- // let res_data_json: serde_json::Value = serde_json::from_str(res_data_str).unwrap();
|
|
|
- // let result = Order {
|
|
|
- // id: res_data_json["orderId"].as_str().unwrap().to_string(),
|
|
|
- // custom_id: res_data_json["clientOid"].as_str().unwrap().to_string(),
|
|
|
- // price: Decimal::ZERO,
|
|
|
- // amount: Decimal::ZERO,
|
|
|
- // deal_amount: Decimal::ZERO,
|
|
|
- // avg_price: Decimal::ZERO,
|
|
|
- // status: "NEW".to_string(),
|
|
|
- // order_type: "".to_string(),
|
|
|
- // trace_stack: TraceStack::new(0, Instant::now()).on_special("328 bitget_swap".to_string()),
|
|
|
- // };
|
|
|
- // Ok(result)
|
|
|
- // } else {
|
|
|
- // Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
- // }
|
|
|
+ let ct_val = self.market.ct_val;
|
|
|
+
|
|
|
+ return self.take_order_symbol(self.symbol.clone(), ct_val, custom_id, origin_side, price, amount).await;
|
|
|
}
|
|
|
|
|
|
async fn take_order_symbol(&mut self, symbol: String, ct_val: Decimal, custom_id: &str, origin_side: &str, price: Decimal, amount: Decimal) -> Result<Order, Error> {
|
|
|
- Err(Error::new(ErrorKind::NotFound, "bitget_swap take_order_symbol:该交易所方法未实现".to_string()))
|
|
|
- // let symbol_format = utils::format_symbol(symbol.clone(), "");
|
|
|
- // let mut params = json!({
|
|
|
- // "symbol": symbol_format.to_string(),
|
|
|
- // "clientOid": custom_id,
|
|
|
- // "price": price.to_string(),
|
|
|
- // });
|
|
|
- // if price.eq(&Decimal::ZERO) {
|
|
|
- // params["orderType"] = json!("market");
|
|
|
- // params["force"] = json!("post_only");
|
|
|
- // } else {
|
|
|
- // params["orderType"] = json!("limit");
|
|
|
- // params["force"] = json!("gtc");
|
|
|
- // };
|
|
|
- // let size = (amount / ct_val).floor();
|
|
|
- // params["size"] = json!(size);
|
|
|
- // match origin_side {
|
|
|
- // "kd" => {
|
|
|
- // params["side"] = json!("buy");
|
|
|
- // }
|
|
|
- // "pd" => {
|
|
|
- // params["side"] = json!("sell");
|
|
|
- // }
|
|
|
- // "kk" => {
|
|
|
- // params["side"] = json!("sell");
|
|
|
- // }
|
|
|
- // "pk" => {
|
|
|
- // params["side"] = json!("buy");
|
|
|
- // }
|
|
|
- // _ => { error!("下单参数错误"); }
|
|
|
- // };
|
|
|
- // let res_data = self.request.spot_order(params).await;
|
|
|
- // if res_data.code == "200" {
|
|
|
- // let res_data_str = &res_data.data;
|
|
|
- // let res_data_json: serde_json::Value = serde_json::from_str(res_data_str).unwrap();
|
|
|
- // let result = Order {
|
|
|
- // id: res_data_json["orderId"].as_str().unwrap().to_string(),
|
|
|
- // custom_id: res_data_json["clientOid"].as_str().unwrap().to_string(),
|
|
|
- // price: Decimal::ZERO,
|
|
|
- // amount: Decimal::ZERO,
|
|
|
- // deal_amount: Decimal::ZERO,
|
|
|
- // avg_price: Decimal::ZERO,
|
|
|
- // status: "NEW".to_string(),
|
|
|
- // order_type: "".to_string(),
|
|
|
- // trace_stack: TraceStack::new(0, Instant::now()).on_special("380 bitget_swap".to_string()),
|
|
|
- // };
|
|
|
- // Ok(result)
|
|
|
- // } else {
|
|
|
- // Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
- // }
|
|
|
+ let symbol_format = utils::format_symbol(symbol, "");
|
|
|
+ let final_size = amount / ct_val;
|
|
|
+ let mut params = json!({
|
|
|
+ "symbol": symbol_format,
|
|
|
+ "clientOid": custom_id,
|
|
|
+ "productType": "USDT-FUTURES",
|
|
|
+ "marginMode": "crossed",
|
|
|
+ "marginCoin": "USDT",
|
|
|
+ "size": final_size.to_string()
|
|
|
+ });
|
|
|
+ if price.eq(&Decimal::ZERO) {
|
|
|
+ params["orderType"] = json!("market");
|
|
|
+ params["force"] = json!("gtc");
|
|
|
+ } else {
|
|
|
+ params["price"] = json!(price.to_string());
|
|
|
+ params["orderType"] = json!("limit");
|
|
|
+ params["force"] = json!("gtc");
|
|
|
+ };
|
|
|
+ match origin_side {
|
|
|
+ "kd" => {
|
|
|
+ params["side"] = json!("buy");
|
|
|
+ params["tradeSide"] = json!("open");
|
|
|
+ }
|
|
|
+ "pd" => {
|
|
|
+ params["side"] = json!("buy");
|
|
|
+ params["tradeSide"] = json!("close");
|
|
|
+ }
|
|
|
+ "kk" => {
|
|
|
+ params["side"] = json!("sell");
|
|
|
+ params["tradeSide"] = json!("open");
|
|
|
+ }
|
|
|
+ "pk" => {
|
|
|
+ params["side"] = json!("sell");
|
|
|
+ params["tradeSide"] = json!("close");
|
|
|
+ }
|
|
|
+ _ => { panic!("bitget_usdt_swap 下单参数错误"); }
|
|
|
+ };
|
|
|
+ let res_data = self.request.swap_order(params).await;
|
|
|
+ if res_data.code != "200" {
|
|
|
+ return Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
+ }
|
|
|
+
|
|
|
+ let res_data_json = res_data.data;
|
|
|
+ let result = Order {
|
|
|
+ id: res_data_json["orderId"].as_str().unwrap().to_string(),
|
|
|
+ custom_id: res_data_json["clientOid"].as_str().unwrap().to_string(),
|
|
|
+ price: Decimal::ZERO,
|
|
|
+ amount: Decimal::ZERO,
|
|
|
+ deal_amount: Decimal::ZERO,
|
|
|
+ avg_price: Decimal::ZERO,
|
|
|
+ status: "NEW".to_string(),
|
|
|
+ order_type: "".to_string(),
|
|
|
+ trace_stack: TraceStack::new(0, Instant::now()).on_special("328 bitget_swap".to_string()),
|
|
|
+ };
|
|
|
+ return Ok(result)
|
|
|
}
|
|
|
|
|
|
async fn cancel_order(&mut self, order_id: &str, custom_id: &str) -> Result<Order, Error> {
|
|
|
- Err(Error::new(ErrorKind::NotFound, "bitget_swap cancel_order:该交易所方法未实现".to_string()))
|
|
|
- // let symbol_format = utils::format_symbol(self.symbol.clone(), "");
|
|
|
- // let res_data = self.request.spot_cancel_order(symbol_format.clone(), order_id.to_string(), custom_id.to_string()).await;
|
|
|
- // if res_data.code == "200" {
|
|
|
- // let res_data_str = &res_data.data;
|
|
|
- // let res_data_json: serde_json::Value = serde_json::from_str(res_data_str).unwrap();
|
|
|
- // let result = Order {
|
|
|
- // id: res_data_json["orderId"].as_str().unwrap().to_string(),
|
|
|
- // custom_id: res_data_json["clientOid"].as_str().unwrap().to_string(),
|
|
|
- // price: Decimal::ZERO,
|
|
|
- // amount: Decimal::ZERO,
|
|
|
- // deal_amount: Decimal::ZERO,
|
|
|
- // avg_price: Decimal::ZERO,
|
|
|
- // status: "REMOVE".to_string(),
|
|
|
- // order_type: "".to_string(),
|
|
|
- // trace_stack: TraceStack::new(0, Instant::now()).on_special("403 bitget_swap".to_string()),
|
|
|
- // };
|
|
|
- // Ok(result)
|
|
|
- // } else {
|
|
|
- // Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
- // }
|
|
|
+ let symbol_format = utils::format_symbol(self.symbol.clone(), "");
|
|
|
+ let params = json!({
|
|
|
+ "symbol": symbol_format,
|
|
|
+ "productType": "USDT-FUTURES",
|
|
|
+ "clientOid": custom_id,
|
|
|
+ });
|
|
|
+ let response = self.request.cancel_order(params).await;
|
|
|
+
|
|
|
+ // 取消失败,进行报错
|
|
|
+ if response.code != "200" {
|
|
|
+ return Err(Error::new(ErrorKind::NotFound, response.to_string()));
|
|
|
+ }
|
|
|
+
|
|
|
+ let res_data_json = response.data;
|
|
|
+ let result = Order {
|
|
|
+ id: res_data_json["orderId"].as_str().unwrap().to_string(),
|
|
|
+ custom_id: res_data_json["clientOid"].as_str().unwrap().to_string(),
|
|
|
+ price: Decimal::ZERO,
|
|
|
+ amount: Decimal::ZERO,
|
|
|
+ deal_amount: Decimal::ZERO,
|
|
|
+ avg_price: Decimal::ZERO,
|
|
|
+ status: "REMOVE".to_string(),
|
|
|
+ order_type: "".to_string(),
|
|
|
+ trace_stack: TraceStack::new(0, Instant::now()).on_special("443 bitget_swap".to_string()),
|
|
|
+ };
|
|
|
+ Ok(result)
|
|
|
}
|
|
|
|
|
|
async fn cancel_orders(&mut self) -> Result<Vec<Order>, Error> {
|
|
|
@@ -534,7 +499,7 @@ impl Platform for BitgetSwap {
|
|
|
Err(Error::new(ErrorKind::NotFound, "bitget_swap set_auto_deposit_status:该交易所方法未实现".to_string()))
|
|
|
}
|
|
|
|
|
|
- async fn wallet_transfers(&mut self, coin: &str, from: &str, to: &str, amount: Decimal) -> Result<String, Error> {
|
|
|
+ async fn wallet_transfers(&mut self, _coin: &str, _from: &str, _to: &str, _amount: Decimal) -> Result<String, Error> {
|
|
|
Err(Error::new(ErrorKind::NotFound, "bitget_swap wallet_transfers:该交易所方法未实现".to_string()))
|
|
|
// let coin_format = coin.to_string().to_uppercase();
|
|
|
// let res_data = self.request.wallet_transfer(from.to_string(), to.to_string(), amount.to_string(), coin_format.clone(), "".to_string(), "".to_string()).await;
|
|
|
@@ -547,7 +512,7 @@ impl Platform for BitgetSwap {
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
- async fn command_order(&mut self, order_command: &mut OrderCommand, trace_stack: &TraceStack) {
|
|
|
+ async fn command_order(&mut self, _order_command: &mut OrderCommand, _trace_stack: &TraceStack) {
|
|
|
// let mut handles = vec![];
|
|
|
// // 撤销订单
|
|
|
// let cancel = order_command.cancel;
|
|
|
@@ -675,9 +640,8 @@ pub fn format_account_info(balance_data: Value) -> Account {
|
|
|
pub fn format_order_item(order: Value, ct_val: Decimal) -> Order {
|
|
|
let price = Decimal::from_str(order["price"].as_str().unwrap_or(order["priceAvg"].as_str().unwrap())).unwrap();
|
|
|
let size = Decimal::from_str(order["size"].as_str().unwrap()).unwrap();
|
|
|
- let status = order["status"].as_str().unwrap_or("");
|
|
|
- let base_volume = Decimal::from_str(order["baseVolume"].as_str().unwrap()).unwrap();
|
|
|
-
|
|
|
+ let status = order["state"].as_str().unwrap();
|
|
|
+ let base_volume = Decimal::from_str(order["quoteVolume"].as_str().unwrap()).unwrap();
|
|
|
let avg_price = Decimal::from_str(order["priceAvg"].as_str().unwrap()).unwrap();
|
|
|
|
|
|
let amount = size * ct_val;
|
|
|
@@ -698,6 +662,6 @@ pub fn format_order_item(order: Value, ct_val: Decimal) -> Order {
|
|
|
avg_price,
|
|
|
status: custom_status,
|
|
|
order_type: order["orderType"].as_str().unwrap().to_string(),
|
|
|
- trace_stack: TraceStack::new(0, Instant::now()).on_special("622 bitget_swap".to_string()),
|
|
|
+ trace_stack: TraceStack::new(0, Instant::now()).on_special("700 bitget_swap".to_string()),
|
|
|
}
|
|
|
}
|