1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use async_trait::async_trait;
use chrono::NaiveDateTime;
use std::collections::HashMap;

use reqwest::Url;
use reqwest::Client;
use reqwest::Method;

mod accounts;
mod market;
mod client;
mod beneficiaries;
mod orders;
mod withdrawals;
mod receive;
mod quotes;
mod send;

pub struct LunoClient {
    base_url: String,
    api_key: String,
    api_secret: String,
    client: reqwest::Client,
}

#[async_trait]
pub trait Accounts {
    async fn create_account(&self, ticker: &str, name: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn update_account_name(&self, id: &str, name: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn list_pending_transactions(&self, id: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn list_transactions(&self, id: &str, min_row: i32, max_row: i32) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn list_balances(&self, assets: Vec<&str>) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
}

#[async_trait]
pub trait Market {
    async fn get_ticker(&self, ticker: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn get_tickers(&self) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn list_trades_market(&self, pair: &str, since: Option<NaiveDateTime>) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn get_orderbook_top(&self, pair: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn get_orderbook(&self, pair: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
}

#[async_trait]
pub trait Beneficiaries {
    async fn list_beneficiaries(&self) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
}

#[async_trait]
pub trait Orders {
    async fn get_fee_info(&self, pair: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn list_orders(&self, params: Option<HashMap<&str, String>>) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn list_trades_user(&self, mut params: HashMap<&str, String>) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn post_market_order(
        &self,
        pair:               &str,
        action:             &str,
        counter_volume:     Option<&str>,           // for buy orders
        base_volume:        Option<&str>,           // for sell orders
        base_account_id:    Option<&str>,
        counter_account_id: Option<&str>,
    )  -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn get_order(&self, id: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn post_limit_order(
                            &self,
        pair:               &str,
        action:             &str,
        post_only:          Option<&str>,
        volume:             &str,
        price:              &str,
        stop_price:         Option<&str>,
        stop_direction:     Option<&str>,
        base_account_id:    Option<&str>,
        counter_account_id: Option<&str>
    )  -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn stop_order(&self, order_id: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
}

#[async_trait]
pub trait Quotes {
    async fn create_quote(&self, action: &str, base_amount: f64, pair: &str, base_account_id: Option<&str>, counter_account_id: Option<&str>) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn get_quote(&self, id: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn exercise_quote(&self, id: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn delete_quote(&self, id: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
}

#[async_trait]
pub trait Receive {
    async fn get_receive_address(&self, asset: &str, address: Option<&str>) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn create_receive_address(&self, asset: &str, name: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
}

#[async_trait]
pub trait Send {
    async fn send(
                        &self,
        amount:         &str,
        currency:       &str,
        address:        &str,
        description:    Option<&str>,
        message:        Option<&str>,
        external_id:    Option<&str>,
        dest_tag_flag:  bool,
        dest_tag:       Option<&str>,
    )  -> Result<reqwest::Response, Box<dyn std::error::Error>>;
}

#[async_trait]
pub trait Withdrawals {
    async fn list_withdrawal_requests(&self) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn get_withdrawal(&self, id: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn request_withdrawal(
        &self,
        action: &str,
        amount: &str,
        benef_id: Option<&str>,
        reference: Option<&str>,
        extern_id: Option<&str>    
    ) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
    async fn cancel_withdrawal_request(&self, id: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>>;
}