mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-07-20 09:43:30 +00:00
switch to u64
This commit is contained in:
@ -1,15 +1,14 @@
|
|||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use sha2::{Sha256, Digest};
|
use sha2::{Sha256, Digest};
|
||||||
use base91;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Coordinator;
|
pub struct Coordinator;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum OfferType {
|
pub enum OfferType {
|
||||||
Buy(u32),
|
Buy(u64),
|
||||||
Sell(u32),
|
Sell(u64),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
15
taptrade-cli-demo/trader/src/communication/api.rs
Normal file
15
taptrade-cli-demo/trader/src/communication/api.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct OfferCreationResponse {
|
||||||
|
pub locking_address: String,
|
||||||
|
pub locking_amount: u32, // validate
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct OrderRequest {
|
||||||
|
pub robohash_base91: String,
|
||||||
|
pub amount_satoshi: u64,
|
||||||
|
pub order_type: String, // buy or sell
|
||||||
|
pub bond_ratio: u8 // [2, 50]
|
||||||
|
}
|
@ -1,25 +1,14 @@
|
|||||||
use reqwest;
|
pub mod api;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::cli::{TraderSettings, OfferType};
|
use crate::cli::{TraderSettings, OfferType};
|
||||||
|
use api::{OrderRequest, OfferCreationResponse};
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct OfferCreationResponse {
|
|
||||||
pub locking_address: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
struct OrderRequest {
|
|
||||||
robohash_base91: String,
|
|
||||||
amount_satoshi: u32,
|
|
||||||
order_type: String, // buy or sell
|
|
||||||
bond_ratio: u8 // [x > 2, 50]
|
|
||||||
}
|
|
||||||
|
|
||||||
impl OfferCreationResponse {
|
impl OfferCreationResponse {
|
||||||
fn _format_request(trader_setup: &TraderSettings) -> OrderRequest {
|
fn _format_request(trader_setup: &TraderSettings) -> OrderRequest {
|
||||||
let amount: u32;
|
let amount: u64;
|
||||||
let trade_type = match &trader_setup.trade_type {
|
let trade_type = match &trader_setup.trade_type {
|
||||||
OfferType::Buy(val) => {
|
OfferType::Buy(val) => {
|
||||||
amount = *val;
|
amount = *val;
|
||||||
|
@ -6,19 +6,23 @@ mod trading;
|
|||||||
use core::panic;
|
use core::panic;
|
||||||
|
|
||||||
use cli::CliSettings;
|
use cli::CliSettings;
|
||||||
use anyhow::Result;
|
use anyhow::{anyhow, Result};
|
||||||
use communication::fetch_offer;
|
|
||||||
|
fn start_trade_pipeline(cli_input: &CliSettings) -> Result<()> {
|
||||||
|
if let CliSettings::Maker(maker_data) = cli_input {
|
||||||
|
Ok(trading::run_maker(maker_data)?)
|
||||||
|
} else if let CliSettings::Taker(taker_data) = cli_input {
|
||||||
|
Err(anyhow!("not implemented!"))
|
||||||
|
// trading::taker::run_taker(taker_data)?;
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("Wrong mode selected!"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let mode = CliSettings::parse_cli_args()?;
|
let mode = CliSettings::parse_cli_args()?;
|
||||||
dbg!("CLI input :", &mode);
|
dbg!("CLI input :", &mode);
|
||||||
|
start_trade_pipeline(&mode)?;
|
||||||
|
|
||||||
// if let CliSettings::Maker(maker_data) = &mode {
|
|
||||||
// trading::maker::run_maker(maker_data)?;
|
|
||||||
// } else if let CliSettings::Taker(taker_data) = &mode {
|
|
||||||
// trading::taker::run_taker(taker_data)?;
|
|
||||||
// } else {
|
|
||||||
// panic!("Wrong mode selected!")
|
|
||||||
// }
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,12 @@
|
|||||||
// use utils;
|
// use utils;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use crate::cli::TraderSettings;
|
use crate::cli::TraderSettings;
|
||||||
use crate::communication::create_offer;
|
use crate::communication::api::OfferCreationResponse;
|
||||||
|
|
||||||
pub fn run_maker(maker_config: &TraderSettings) -> Result<()> {
|
pub fn run_maker(maker_config: &TraderSettings) -> Result<()> {
|
||||||
let offer_conditions = create_offer(maker_config)?;
|
let offer_conditions = OfferCreationResponse::fetch(maker_config)?;
|
||||||
|
|
||||||
// maker_utils::maker(offer_conditions, maker_config)
|
// maker_utils::maker(offer_conditions, maker_config)
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user