|
|
@@ -367,7 +367,7 @@ impl Platform for BinanceSwap {
|
|
|
"newClientOrderId": custom_id.to_string(),
|
|
|
"symbol": symbol_format,
|
|
|
});
|
|
|
- let size = (amount / ct_val).floor();
|
|
|
+ let size = amount / ct_val;
|
|
|
params["quantity"] = json!(size);
|
|
|
if price.eq(&Decimal::ZERO) {
|
|
|
params["type"] = json!("MARKET");
|
|
|
@@ -379,27 +379,25 @@ impl Platform for BinanceSwap {
|
|
|
match origin_side {
|
|
|
"kd" => {
|
|
|
params["side"] = json!("BUY");
|
|
|
- params["positionSide"] = json!("LONG");
|
|
|
+ // params["positionSide"] = json!("LONG");
|
|
|
}
|
|
|
"pd" => {
|
|
|
params["side"] = json!("SELL");
|
|
|
- params["positionSide"] = json!("LONG");
|
|
|
+ // params["positionSide"] = json!("LONG");
|
|
|
}
|
|
|
"kk" => {
|
|
|
params["side"] = json!("SELL");
|
|
|
- params["positionSide"] = json!("SHORT");
|
|
|
+ // params["positionSide"] = json!("SHORT");
|
|
|
}
|
|
|
"pk" => {
|
|
|
params["side"] = json!("BUY");
|
|
|
- params["positionSide"] = json!("SHORT");
|
|
|
+ // params["positionSide"] = json!("SHORT");
|
|
|
}
|
|
|
_ => { error!("下单参数错误"); }
|
|
|
};
|
|
|
let res_data = self.request.swap_order(params).await;
|
|
|
if res_data.code == 200 {
|
|
|
let res_data_json: Value = res_data.data;
|
|
|
- println!("data: {}", res_data_json);
|
|
|
-
|
|
|
let id = res_data_json["orderId"].to_string();
|
|
|
let custom_id = res_data_json["clientOrderId"].as_str().unwrap().to_string();
|
|
|
let price = Decimal::from_str(res_data_json["price"].as_str().unwrap()).unwrap();
|
|
|
@@ -430,7 +428,7 @@ impl Platform for BinanceSwap {
|
|
|
});
|
|
|
if order_id != "" { params["orderId"] = json!(order_id) }
|
|
|
if custom_id != "" { params["origClientOrderId"] = json!(custom_id) }
|
|
|
-
|
|
|
+ println!("{}", params);
|
|
|
let res_data = self.request.cancel_order(params).await;
|
|
|
if res_data.code == 200 {
|
|
|
let res_data_json = &res_data.data;
|
|
|
@@ -440,7 +438,7 @@ impl Platform for BinanceSwap {
|
|
|
let price = Decimal::from_str(res_data_json["price"].as_str().unwrap()).unwrap();
|
|
|
let amount = Decimal::from_str(res_data_json["origQty"].as_str().unwrap()).unwrap();
|
|
|
let deal_amount = Decimal::from_str(res_data_json["executedQty"].as_str().unwrap()).unwrap();
|
|
|
- let avg_price = deal_amount / cum_quote;
|
|
|
+ let avg_price = if cum_quote > Decimal::ZERO {deal_amount / cum_quote}else { Decimal::ZERO };
|
|
|
let result = Order {
|
|
|
id,
|
|
|
custom_id,
|
|
|
@@ -464,25 +462,18 @@ impl Platform for BinanceSwap {
|
|
|
"symbol": symbol_format.clone(),
|
|
|
});
|
|
|
let res_data = self.request.cancel_order_all(params).await;
|
|
|
+ println!("{:?}", res_data);
|
|
|
if res_data.code == 200 {
|
|
|
- let res_data_json = &res_data.data;
|
|
|
- let cum_quote = Decimal::from_str(res_data_json["cumQuote"].as_str().unwrap()).unwrap();
|
|
|
- let id = res_data_json["orderId"].to_string();
|
|
|
- let custom_id = res_data_json["clientOrderId"].as_str().unwrap().to_string();
|
|
|
- let price = Decimal::from_str(res_data_json["price"].as_str().unwrap()).unwrap();
|
|
|
- let amount = Decimal::from_str(res_data_json["origQty"].as_str().unwrap()).unwrap();
|
|
|
- let deal_amount = Decimal::from_str(res_data_json["executedQty"].as_str().unwrap()).unwrap();
|
|
|
- let avg_price = deal_amount / cum_quote;
|
|
|
let result = vec![Order {
|
|
|
- id,
|
|
|
- custom_id,
|
|
|
- price,
|
|
|
- amount,
|
|
|
- deal_amount,
|
|
|
- avg_price,
|
|
|
+ id: "".to_string(),
|
|
|
+ custom_id: "".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("463 binance_swap".to_string()),
|
|
|
+ order_type: "limit".to_string(),
|
|
|
+ trace_stack: TraceStack::new(0, Instant::now()).on_special("484 trace_stack".to_string())
|
|
|
}];
|
|
|
Ok(result)
|
|
|
} else {
|