Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple market maker bot #1066

Merged
merged 84 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
90562a6
feat(simple_trading_bot): draft for simple trading bot implementation…
Milerius Sep 13, 2021
86039aa
feat(simple_trading_bot): remove spurious use of a non-public data st…
Milerius Sep 13, 2021
896fa3f
feat(simple_trading_bot): remove unused HashSet inclusion
Milerius Sep 13, 2021
a3178fb
feat(simple_trading_bot): remove spurious usage of return.
Milerius Sep 13, 2021
638f3d6
enhancements(simple_trading_bot): fix needless_borrow warnings
Milerius Sep 13, 2021
d280897
enhancements(simple_trading_bot): rustfmt
Milerius Sep 13, 2021
f5a72ef
enhancements(simple_trading_bot): rustfmt
Milerius Sep 13, 2021
b160430
Merge branch 'dev' of https://github.com/KomodoPlatform/atomicDEX-API…
Milerius Sep 14, 2021
1ad4506
feat(simple_trading_bot): add iteration through maker_orders
Milerius Sep 14, 2021
b280e0c
Merge branch 'dev' of https://github.com/KomodoPlatform/atomicDEX-API…
Milerius Sep 14, 2021
890344d
feat(simple_trading_bot): change price url to komodo.live
Milerius Sep 14, 2021
fc28665
enhancements(simple_trading_bot): first iteration of fix based on the…
Milerius Sep 14, 2021
bac1e6c
enhancements(simple_trading_bot): confs can be negative, switching to…
Milerius Sep 14, 2021
c82bc04
enhancements(simple_trading_bot): use match expression when parsing n…
Milerius Sep 14, 2021
ddf3d96
enhancements(simple_trading_bot): use an enum for the trading bot states
Milerius Sep 15, 2021
8ef6883
enhancements(simple_trading_bot): use mmnumber instead of string.
Milerius Sep 15, 2021
9e6fa27
enhancements(simple_trading_bot): introducing TradingPair data structure
Milerius Sep 15, 2021
c07c90d
enhancements(simple_trading_bot): rename functor, make it more expres…
Milerius Sep 15, 2021
7bc9f1c
enhancements(simple_trading_bot): make lp_bot_tests a submodule of mm…
Milerius Sep 15, 2021
85f7d1a
enhancements(simple_trading_bot): make lp_bot a submodule of lp_order…
Milerius Sep 15, 2021
eb67a8d
enhancements(simple_trading_bot): don't use clone on a copiable data
Milerius Sep 15, 2021
abb55ed
feat(simple_trading_bot): add skeleton for creating orders
Milerius Sep 15, 2021
456fddb
feat(simple_trading_bot): continue implementation of creating single …
Milerius Sep 15, 2021
28f5b43
feat(clippy): fix various clippy warnings
Milerius Sep 15, 2021
7d8dbf8
feat(clippy): fix various clippy warnings
Milerius Sep 15, 2021
4868e0f
feat(price): add calculated price
Milerius Sep 15, 2021
05d07e7
feat(simple_market_maker): add more checks and fix clippy warnings
Milerius Sep 16, 2021
122af29
feat(simple_market_maker): simplify coin_find_and_checks
Milerius Sep 16, 2021
858b9be
feat(simple_market_maker): fix condition
Milerius Sep 16, 2021
b1c7c88
feat(simple_market_maker): finalize the creation of the order.
Milerius Sep 16, 2021
60599cc
feat(simple_market_maker): finalize with volume and min_volume
Milerius Sep 16, 2021
8211804
feat(simple_market_maker): add simple_market_maker_tests.rs
Milerius Sep 16, 2021
0dde0f9
fix(simple_market_maker): use the good TradingBotContext
Milerius Sep 16, 2021
d4cfa2b
feat(simple_market_maker): change approach for error checking
Milerius Sep 17, 2021
93a7f37
enhancements(simple_market_maker): review fixing
Milerius Sep 17, 2021
74e7fe2
enhancements(market_maker_bot): use MmNumber instead of string
Milerius Sep 17, 2021
89231eb
enhancements(market_maker_bot): use match expression instead of chain…
Milerius Sep 19, 2021
904ec2f
enhancements(market_maker_bot): fix code review comments
Milerius Sep 19, 2021
daa5130
enhancements(market_maker_bot): fix code review comments
Milerius Sep 19, 2021
c2f8656
enhancements(market_maker_bot): fix unit tests
Milerius Sep 19, 2021
fae2b48
feat(market_maker_bot): continue update maker order
Milerius Sep 20, 2021
242c3b0
feat(market_maker_bot): added first vwap version
Milerius Sep 21, 2021
12ad889
feat(market_maker_bot): add unit tests for vwap
Milerius Sep 21, 2021
15caeec
feat(market_maker_bot): more unit tests
Milerius Sep 21, 2021
7df25f6
feat(simple_market_maker): add last vwap unit tests
Milerius Sep 22, 2021
e99856b
feat(simple_market_maker): refactor some code
Milerius Sep 22, 2021
351f977
Merge branch 'dev' of https://github.com/KomodoPlatform/atomicDEX-API…
Milerius Sep 23, 2021
4d427d2
feat(simple_market_maker): continue refactor
Milerius Sep 23, 2021
98a7284
feat(simple_market_maker): move price service
Milerius Sep 23, 2021
79d646f
feat(simple_market_maker): continue refactoring
Milerius Sep 23, 2021
620aa76
feat(market_maker): implement the cancelling of pending orders
Milerius Sep 23, 2021
aa31c6a
feat(market_maker): fix unit tests
Milerius Sep 23, 2021
80b1ba8
feat(market_maker): fix review comments
Milerius Sep 24, 2021
b11d364
feat(market_maker): fix review comments
Milerius Sep 24, 2021
00d4e38
feat(simple_market_maker): use a proper error for balance
Milerius Sep 25, 2021
81c641c
feat(simple_market_maker): use a lp_findpair like functions
Milerius Sep 25, 2021
9d53fa3
feat(get_non_zero_balance): implement get_non_zero_balance in lp_coins
Milerius Sep 27, 2021
f57b48f
feat(simple_market_maker_bot): fix nonzerobalance
Milerius Sep 27, 2021
6ac98b7
feat(simple_market_maker_bot): add multiple spawn for order update
Milerius Sep 27, 2021
2906c8d
Merge branch 'dev' of https://github.com/KomodoPlatform/atomicDEX-API…
Milerius Sep 27, 2021
d77a110
enhancement(review): simplify update/creation order
Milerius Sep 30, 2021
21674d4
enhancement(review): simplify cex rates
Milerius Sep 30, 2021
51cc462
enhancement(review): simplify mm error creation in cancel_order
Milerius Sep 30, 2021
1b5bde4
enhancement(review): rename min_volume -> min_volume_percentage from …
Milerius Sep 30, 2021
be541a0
enhancement(review): refactor vwap calculation
Milerius Sep 30, 2021
476c659
feat(review): clippy warnings
Milerius Sep 30, 2021
641331d
Merge branch 'dev' of https://github.com/KomodoPlatform/atomicDEX-API…
Milerius Oct 4, 2021
4d2d4e1
feat(bot): cancel order only managed by the trading bot.
Milerius Oct 4, 2021
60a6ba4
feat(simple_market_maker): fix review comments
Milerius Oct 5, 2021
853e48e
feat(simple_market_maker): fix review comments
Milerius Oct 5, 2021
6c917c2
feat(simple_market_maker): change valid trades approach, remove usele…
Milerius Oct 5, 2021
fc72387
feat(simple_market_maker): continue review fixing
Milerius Oct 5, 2021
abd7f75
feat(simple_market_maker): continue review fixing
Milerius Oct 5, 2021
9db2ed9
feat(simple_market_maker): clippy fix
Milerius Oct 5, 2021
6fe1e78
feat(simple_market_maker_bot): use option for timestamp
Milerius Oct 6, 2021
d347c2d
feat(simple_market_maker_bot): simplify asynchrounous code
Milerius Oct 6, 2021
e0512aa
feat(bot): simplify order creation
Milerius Oct 6, 2021
36d5a7c
feat(sync): sync with dev
Milerius Oct 6, 2021
a667c4d
Merge branch 'dev' of https://github.com/KomodoPlatform/atomicDEX-API…
Milerius Oct 8, 2021
7d6e219
feat(simple_market_maker): fix review iteration
Milerius Oct 8, 2021
cf2e96c
feat(clippy): fix clippy warnings
Milerius Oct 8, 2021
4f2dc9c
feat(time): don't use unwrap for system time it can failed
Milerius Oct 11, 2021
b36feb9
feat(bot): add support for custom price url default to KMD one
Milerius Oct 12, 2021
98d324e
feat(bot): add support for V2 endpoint and ticker groups
Milerius Oct 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#[macro_use] extern crate ser_error_derive;

use async_trait::async_trait;
use bigdecimal::{BigDecimal, ParseBigDecimalError};
use bigdecimal::{BigDecimal, ParseBigDecimalError, Zero};
use common::executor::{spawn, Timer};
use common::mm_ctx::{from_ctx, MmArc, MmWeak};
use common::mm_error::prelude::*;
Expand Down Expand Up @@ -124,6 +124,7 @@ cfg_wasm32! {

pub type BalanceResult<T> = Result<T, MmError<BalanceError>>;
pub type BalanceFut<T> = Box<dyn Future<Item = T, Error = MmError<BalanceError>> + Send>;
pub type NonZeroBalanceFut<T> = Box<dyn Future<Item = T, Error = MmError<GetNonZeroBalance>> + Send>;
pub type NumConversResult<T> = Result<T, MmError<NumConversError>>;
pub type WithdrawResult = Result<TransactionDetails, MmError<WithdrawError>>;
pub type WithdrawFut = Box<dyn Future<Item = TransactionDetails, Error = MmError<WithdrawError>> + Send>;
Expand Down Expand Up @@ -344,6 +345,16 @@ pub trait MarketCoinOps {

fn my_address(&self) -> Result<String, String>;

fn get_non_zero_balance(&self) -> NonZeroBalanceFut<MmNumber> {
let closure = |spendable: BigDecimal| {
if spendable.is_zero() {
return MmError::err(GetNonZeroBalance::BalanceIsZero);
}
Ok(MmNumber::from(spendable))
};
Box::new(self.my_spendable_balance().map_err(From::from).and_then(closure))
}

fn my_balance(&self) -> BalanceFut<CoinBalance>;

fn my_spendable_balance(&self) -> BalanceFut<BigDecimal> {
Expand Down Expand Up @@ -698,6 +709,18 @@ pub enum BalanceError {
Internal(String),
}

#[derive(Debug, PartialEq, Display)]
pub enum GetNonZeroBalance {
#[display(fmt = "Internal error when retrieving balance - skipping")]
artemii235 marked this conversation as resolved.
Show resolved Hide resolved
MyBalanceError(BalanceError),
#[display(fmt = "Balance is zero - skipping")]
BalanceIsZero,
}

impl From<BalanceError> for GetNonZeroBalance {
fn from(e: BalanceError) -> Self { GetNonZeroBalance::MyBalanceError(e) }
}

impl From<NumConversError> for BalanceError {
fn from(e: NumConversError) -> Self { BalanceError::Internal(e.to_string()) }
}
Expand Down
13 changes: 13 additions & 0 deletions mm2src/common/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ pub trait LogOnError {

// Log the error, caller location and the given message to ERROR level here.
fn error_log_with_msg(self, msg: &str);

fn error_log_passthrough(self) -> Self;
}

impl<T, E: fmt::Display> LogOnError for Result<T, E> {
Expand Down Expand Up @@ -280,6 +282,17 @@ impl<T, E: fmt::Display> LogOnError for Result<T, E> {
error!("{}:{}] {}: {}", file, line, msg, e);
}
}

#[track_caller]
fn error_log_passthrough(self) -> Self {
if let Err(e) = &self {
let location = std::panic::Location::caller();
let file = gstuff::filename(location.file());
let line = location.line();
error!("{}:{}] {}", file, line, e);
}
self
}
}

pub trait TagParam<'a> {
Expand Down
2 changes: 2 additions & 0 deletions mm2src/common/mm_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub struct MmCtx {
pub stop_listeners: Mutex<Vec<StopListenerCallback>>,
/// The context belonging to the `ordermatch` mod: `OrdermatchContext`.
pub ordermatch_ctx: Mutex<Option<Arc<dyn Any + 'static + Send + Sync>>>,
pub simple_market_maker_bot_ctx: Mutex<Option<Arc<dyn Any + 'static + Send + Sync>>>,
pub p2p_ctx: Mutex<Option<Arc<dyn Any + 'static + Send + Sync>>>,
pub peer_id: Constructible<String>,
/// The context belonging to the `coins` crate: `CoinsContext`.
Expand Down Expand Up @@ -111,6 +112,7 @@ impl MmCtx {
ffi_handle: Constructible::default(),
stop_listeners: Mutex::new(Vec::new()),
ordermatch_ctx: Mutex::new(None),
simple_market_maker_bot_ctx: Mutex::new(None),
p2p_ctx: Mutex::new(None),
peer_id: Constructible::default(),
coins_ctx: Mutex::new(None),
Expand Down
Loading