Open g302ge opened 2 years ago
Impl note: in the plain Java implementation constructed by Binance official developer. There is a fact, that every Rest api will return a simple text response, maybe the json format but not consistency for all
and the response struct is more like this
#[response]
pub enum Response {
Error(BinanceError),
Success{
// other fields
}
}
Hold on, firstly we have to implement a new proc-macro library to generate the redundance code template for any exchange like rest interfaces
recent desgin
#[derive(Debug, RestApi, Default)]
#[rest(uri="rest_api/path")
#[rest(method="GET")
#[rest(signature="USER_DATA")]
#[rest(respone="crate::spot::SomeRestApiNameResponse")]
pub struct SomeRestApiName {
// we belive that every field should implement the Default trait as default value
// else use Option as optional semantic
field1: String,
field2: Option<i32>,
// other fields
}
Derive into
#[derive(Debug, Default, serde::Serialize)
pub struct SomeRestApiName {
// fields
}
#[derive(Default)]
pub struct SomeRestApiNameBuilder {
// fields in Rest
}
impl SomeRestApiNameBuilder {
// fields builders
}
impl SomeRestApiName {
pub fn builder() -> SomeRestApiNameBuilder
}
impl SomeRestApiName {
pun fn execute<T: RestClient>(&self. client: &T) -> Result<SomeRestApiNameResponse> {
// calculate the signature if not ignore and add header
// do execute
// serde_json::from_str() -> to response
}
}
At a glance, the template code is below
Then we should get the api class with builder as below:
So we could use this directly in Client look like this