added support for derivative trading in connectors. stub for fees calculation. hardcoded leverage 15 in order submission
This commit is contained in:
parent
613b314631
commit
e210808983
@ -17,7 +17,7 @@ use tokio::time::Duration;
|
||||
use crate::currency::{Symbol, SymbolPair};
|
||||
use crate::models::{
|
||||
ActiveOrder, OrderBook, OrderBookEntry, OrderDetails, OrderFee, OrderForm, OrderKind, Position,
|
||||
PositionState, PriceTicker, Trade, TradingPlatform, WalletKind,
|
||||
PositionState, PriceTicker, Trade, TradingFees, TradingPlatform, WalletKind,
|
||||
};
|
||||
use crate::BoxError;
|
||||
|
||||
@ -69,9 +69,9 @@ impl Client {
|
||||
// TODO: change fee with account's taker fee
|
||||
positions.iter_mut().flatten().for_each(|x| {
|
||||
if x.is_short() {
|
||||
x.update_profit_loss(best_ask, 0.2);
|
||||
x.update_profit_loss(best_ask, 0.075);
|
||||
} else {
|
||||
x.update_profit_loss(best_bid, 0.2);
|
||||
x.update_profit_loss(best_bid, 0.075);
|
||||
}
|
||||
});
|
||||
|
||||
@ -153,6 +153,7 @@ pub trait Connector: Send + Sync {
|
||||
&self,
|
||||
pair: &SymbolPair,
|
||||
) -> Result<Option<Vec<OrderDetails>>, BoxError>;
|
||||
async fn trading_fees(&self) -> Result<Vec<TradingFees>, BoxError>;
|
||||
}
|
||||
|
||||
impl Debug for dyn Connector {
|
||||
@ -188,10 +189,14 @@ impl BitfinexConnector {
|
||||
fn format_trading_pair(pair: &SymbolPair) -> String {
|
||||
if pair.to_string().to_lowercase().contains("test") {
|
||||
format!("{}:{}", pair.base(), pair.quote())
|
||||
} else {
|
||||
if pair.to_string().to_lowercase().contains("f0") {
|
||||
format!("{}:{}", pair.base(), pair.quote())
|
||||
} else {
|
||||
format!("{}{}", pair.base(), pair.quote())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// retry to submit the request until it succeeds.
|
||||
// the function may fail due to concurrent signed requests
|
||||
@ -279,9 +284,11 @@ impl Connector for BitfinexConnector {
|
||||
let order_form = match order.kind() {
|
||||
OrderKind::Limit { price, amount } => {
|
||||
bitfinex::orders::OrderForm::new(symbol_name, price, amount, order.into())
|
||||
.with_leverage(15)
|
||||
}
|
||||
OrderKind::Market { amount } => {
|
||||
OrderKind::Market { amount, .. } => {
|
||||
bitfinex::orders::OrderForm::new(symbol_name, 0.0, amount, order.into())
|
||||
.with_leverage(15)
|
||||
}
|
||||
OrderKind::Stop { price, amount } => {
|
||||
bitfinex::orders::OrderForm::new(symbol_name, price, amount, order.into())
|
||||
@ -371,6 +378,10 @@ impl Connector for BitfinexConnector {
|
||||
|
||||
Ok((!mapped_vec.is_empty()).then_some(mapped_vec))
|
||||
}
|
||||
|
||||
async fn trading_fees(&self) -> Result<Vec<TradingFees>, BoxError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&ActiveOrder> for CancelOrderForm {
|
||||
@ -439,7 +450,7 @@ impl From<&OrderForm> for bitfinex::orders::OrderKind {
|
||||
OrderKind::FillOrKill { .. } => bitfinex::orders::OrderKind::ExchangeFok,
|
||||
OrderKind::ImmediateOrCancel { .. } => bitfinex::orders::OrderKind::ExchangeIoc,
|
||||
},
|
||||
TradingPlatform::Margin => match o.kind() {
|
||||
TradingPlatform::Margin | TradingPlatform::Derivative => match o.kind() {
|
||||
OrderKind::Limit { .. } => bitfinex::orders::OrderKind::Limit,
|
||||
OrderKind::Market { .. } => bitfinex::orders::OrderKind::Market,
|
||||
OrderKind::Stop { .. } => bitfinex::orders::OrderKind::Stop,
|
||||
|
Loading…
Reference in New Issue
Block a user