mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
binance: add futures conversion
This commit is contained in:
parent
6ac8b36eca
commit
6071c07073
|
@ -50,6 +50,42 @@ func toGlobalMarket(symbol binance.Symbol) types.Market {
|
||||||
return market
|
return market
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Cuz it returns types.Market as well, merge following to the above function
|
||||||
|
func toGlobalFuturesMarket(symbol futures.Symbol) types.Market {
|
||||||
|
market := types.Market{
|
||||||
|
Symbol: symbol.Symbol,
|
||||||
|
LocalSymbol: symbol.Symbol,
|
||||||
|
PricePrecision: symbol.QuotePrecision,
|
||||||
|
VolumePrecision: symbol.BaseAssetPrecision,
|
||||||
|
QuoteCurrency: symbol.QuoteAsset,
|
||||||
|
BaseCurrency: symbol.BaseAsset,
|
||||||
|
}
|
||||||
|
|
||||||
|
if f := symbol.MinNotionalFilter(); f != nil {
|
||||||
|
market.MinNotional = util.MustParseFloat(f.Notional)
|
||||||
|
market.MinAmount = util.MustParseFloat(f.Notional)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The LOT_SIZE filter defines the quantity (aka "lots" in auction terms) rules for a symbol.
|
||||||
|
// There are 3 parts:
|
||||||
|
// minQty defines the minimum quantity/icebergQty allowed.
|
||||||
|
// maxQty defines the maximum quantity/icebergQty allowed.
|
||||||
|
// stepSize defines the intervals that a quantity/icebergQty can be increased/decreased by.
|
||||||
|
if f := symbol.LotSizeFilter(); f != nil {
|
||||||
|
market.MinQuantity = util.MustParseFloat(f.MinQuantity)
|
||||||
|
market.MaxQuantity = util.MustParseFloat(f.MaxQuantity)
|
||||||
|
market.StepSize = util.MustParseFloat(f.StepSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
if f := symbol.PriceFilter(); f != nil {
|
||||||
|
market.MaxPrice = util.MustParseFloat(f.MaxPrice)
|
||||||
|
market.MinPrice = util.MustParseFloat(f.MinPrice)
|
||||||
|
market.TickSize = util.MustParseFloat(f.TickSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
return market
|
||||||
|
}
|
||||||
|
|
||||||
func toGlobalIsolatedUserAsset(userAsset binance.IsolatedUserAsset) types.IsolatedUserAsset {
|
func toGlobalIsolatedUserAsset(userAsset binance.IsolatedUserAsset) types.IsolatedUserAsset {
|
||||||
return types.IsolatedUserAsset{
|
return types.IsolatedUserAsset{
|
||||||
Asset: userAsset.Asset,
|
Asset: userAsset.Asset,
|
||||||
|
@ -170,23 +206,23 @@ func toGlobalFuturesPositions(futuresPositions []*futures.AccountPosition) types
|
||||||
return retFuturesPositions
|
return retFuturesPositions
|
||||||
}
|
}
|
||||||
|
|
||||||
func toGlobalFuturesUserAssets(assets []*futures.AccountAsset) (retAssets map[types.Asset]types.FuturesUserAsset) {
|
func toGlobalFuturesUserAssets(assets []*futures.AccountAsset) (retAssets types.FuturesAssetMap) {
|
||||||
for _, asset := range assets {
|
retFuturesAssets := make(types.FuturesAssetMap)
|
||||||
// TODO: or modify to type FuturesAssetMap map[string]FuturesAssetMap
|
for _, futuresAsset := range assets {
|
||||||
retAssets[types.Asset{Currency: asset.Asset}] = types.FuturesUserAsset{
|
retFuturesAssets[futuresAsset.Asset] = types.FuturesUserAsset{
|
||||||
Asset: asset.Asset,
|
Asset: futuresAsset.Asset,
|
||||||
InitialMargin: fixedpoint.MustNewFromString(asset.InitialMargin),
|
InitialMargin: fixedpoint.MustNewFromString(futuresAsset.InitialMargin),
|
||||||
MaintMargin: fixedpoint.MustNewFromString(asset.MaintMargin),
|
MaintMargin: fixedpoint.MustNewFromString(futuresAsset.MaintMargin),
|
||||||
MarginBalance: fixedpoint.MustNewFromString(asset.MarginBalance),
|
MarginBalance: fixedpoint.MustNewFromString(futuresAsset.MarginBalance),
|
||||||
MaxWithdrawAmount: fixedpoint.MustNewFromString(asset.MaxWithdrawAmount),
|
MaxWithdrawAmount: fixedpoint.MustNewFromString(futuresAsset.MaxWithdrawAmount),
|
||||||
OpenOrderInitialMargin: fixedpoint.MustNewFromString(asset.OpenOrderInitialMargin),
|
OpenOrderInitialMargin: fixedpoint.MustNewFromString(futuresAsset.OpenOrderInitialMargin),
|
||||||
PositionInitialMargin: fixedpoint.MustNewFromString(asset.PositionInitialMargin),
|
PositionInitialMargin: fixedpoint.MustNewFromString(futuresAsset.PositionInitialMargin),
|
||||||
UnrealizedProfit: fixedpoint.MustNewFromString(asset.UnrealizedProfit),
|
UnrealizedProfit: fixedpoint.MustNewFromString(futuresAsset.UnrealizedProfit),
|
||||||
WalletBalance: fixedpoint.MustNewFromString(asset.WalletBalance),
|
WalletBalance: fixedpoint.MustNewFromString(futuresAsset.WalletBalance),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return retAssets
|
return retFuturesAssets
|
||||||
}
|
}
|
||||||
|
|
||||||
func toGlobalTicker(stats *binance.PriceChangeStats) (*types.Ticker, error) {
|
func toGlobalTicker(stats *binance.PriceChangeStats) (*types.Ticker, error) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user