|
|
@@ -13,7 +13,7 @@ use tracing::{debug, error};
|
|
|
use exchanges::okx_swap_rest::OkxSwapRest;
|
|
|
use global::trace_stack::TraceStack;
|
|
|
use crate::exchange::ExchangeEnum;
|
|
|
-use crate::{Account, Market, okx_handle, Order, OrderCommand, Platform, Position, Ticker, utils};
|
|
|
+use crate::{Account, Market, okx_handle, Order, OrderCommand, Platform, Position, PositionModeEnum, Ticker, utils};
|
|
|
|
|
|
/// Okx交易所账户信息请求数据结构
|
|
|
/// - 接口`"/api/v5/account/balance"`
|
|
|
@@ -567,7 +567,7 @@ impl Platform for OkxSwap {
|
|
|
let res_data_str = &res_data.data;
|
|
|
let data_list: Vec<SwapPosition> = serde_json::from_str(&res_data_str).unwrap();
|
|
|
let position_info: Vec<&SwapPosition> = data_list.iter().filter(|item| item.inst_id == symbol_format).collect();
|
|
|
- let result = position_info.iter().map(|item| okx_handle::format_position_item(item, ct_val)).collect();
|
|
|
+ let result = position_info.iter().map(|item| format_position_item(item, ct_val)).collect();
|
|
|
Ok(result)
|
|
|
} else {
|
|
|
Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
@@ -579,7 +579,7 @@ impl Platform for OkxSwap {
|
|
|
if res_data.code == "200" {
|
|
|
let res_data_str = &res_data.data;
|
|
|
let data_list: Vec<SwapPosition> = serde_json::from_str(&res_data_str).unwrap();
|
|
|
- let result = data_list.iter().map(|item| okx_handle::format_position_item(item, Decimal::ONE)).collect();
|
|
|
+ let result = data_list.iter().map(|item| format_position_item(item, Decimal::ONE)).collect();
|
|
|
Ok(result)
|
|
|
} else {
|
|
|
Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
@@ -1051,3 +1051,21 @@ pub fn format_order_item(data: SwapOrder, ct_val: Decimal) -> Order {
|
|
|
debug!("format-order-end, okx_swap");
|
|
|
result
|
|
|
}
|
|
|
+
|
|
|
+pub fn format_position_item(value: &SwapPosition, ct_val: Decimal) -> Position {
|
|
|
+ let position_mode = match value.pos_side.as_str() {
|
|
|
+ "long" => { PositionModeEnum::Long }
|
|
|
+ "short" => { PositionModeEnum::Short }
|
|
|
+ _ => { PositionModeEnum::Both }
|
|
|
+ };
|
|
|
+ Position {
|
|
|
+ symbol: value.inst_id.replace("-SWAP", ""),
|
|
|
+ margin_level: value.lever,
|
|
|
+ amount: value.pos * ct_val,
|
|
|
+ frozen_amount: Decimal::ZERO,
|
|
|
+ price: value.avg_px,
|
|
|
+ profit: value.upl,
|
|
|
+ position_mode,
|
|
|
+ margin: if value.margin != "" { Decimal::from_str(&value.margin).unwrap() } else { Decimal::ZERO },
|
|
|
+ }
|
|
|
+}
|