wisespace-io / binance-rs

Rust Library for the Binance API
Other
671 stars 300 forks source link

added BalanceUpdate event support #141

Closed agubarev closed 2 years ago

agubarev commented 2 years ago

AccountUpdate event never fired, now the balance updates can be caught

agubarev commented 2 years ago

although perhaps AccountUpdateEvent should be updated instead of a new variant, just pointing out the issue.

now account update payload looks like this:


  "e": "outboundAccountPosition", //Event type
  "E": 1564034571105,             //Event Time
  "u": 1564034571073,             //Time of last account update
  "B": [                          //Balances Array
    {
      "a": "ETH",                 //Asset
      "f": "10000.000000",        //Free
      "l": "0.000000"             //Locked
    }
  ]
}```
wisespace-io commented 2 years ago

@agubarev The clippy error was fixed in the master branch by @siegfried . If you sync with master your PR will build properly

agubarev commented 2 years ago

Could you review whether this update is redundant, maybe AccountUpdate should be tweaked, I would but wasn't sure if it's going to break anything. I'm using only Spot atm.

wisespace-io commented 2 years ago

@agubarev Have you added the field below to AccountUpdateEvent?

#[serde(rename = "u")]
pub last_account_update_time: u64,

I can't see a reason why it would cause problems.

agubarev commented 2 years ago

Have you added the field below to AccountUpdateEvent?

No, I've added a new event BalanceUpdateEvent and wired into WebsocketEvent.

wisespace-io commented 2 years ago

@agubarev I think we only need to tweak AccountUpdateEvent and add the missing field.

agubarev commented 2 years ago

@wisespace-io was AccountUpdateEvent intended to update balances or it has additional uses? new event payload has fewer fields


#[serde(rename_all = "camelCase")]
pub struct AccountUpdateEvent {
    #[serde(rename = "e")]
    pub event_type: String,

    #[serde(rename = "E")]
    pub event_time: u64,

    m: u64,
    t: u64,
    b: u64,
    s: u64,

    #[serde(rename = "T")]
    t_ignore: bool,
    #[serde(rename = "W")]
    w_ignore: bool,
    #[serde(rename = "D")]
    d_ignore: bool,

    #[serde(rename = "B")]
    pub balance: Vec<EventBalance>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BalanceUpdateEvent {
    #[serde(rename = "B")]
    pub balance: Vec<EventBalance>,

    #[serde(rename = "e")]
    pub event_type: String,

    #[serde(rename = "E")]
    pub event_time: u64,

    #[serde(rename = "u")]
    pub last_account_update_time: u64,
}```
agubarev commented 2 years ago

close/reopen misclicked.

@wisespace-io outboundAccountPosition payload has fewer fields than AccountUpdateEvent


#[serde(rename_all = "camelCase")]
pub struct AccountUpdateEvent {
    #[serde(rename = "e")]
    pub event_type: String,

    #[serde(rename = "E")]
    pub event_time: u64,

    m: u64,
    t: u64,
    b: u64,
    s: u64,

    #[serde(rename = "T")]
    t_ignore: bool,
    #[serde(rename = "W")]
    w_ignore: bool,
    #[serde(rename = "D")]
    d_ignore: bool,

    #[serde(rename = "B")]
    pub balance: Vec<EventBalance>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BalanceUpdateEvent {
    #[serde(rename = "B")]
    pub balance: Vec<EventBalance>,

    #[serde(rename = "e")]
    pub event_type: String,

    #[serde(rename = "E")]
    pub event_time: u64,

    #[serde(rename = "u")]
    pub last_account_update_time: u64,
}
wisespace-io commented 2 years ago

@agubarev To be honest, I am 100% sure. So, it seems safer to have the BalanceUpdateEvent that you have introduced