11import BigNumber from "bignumber.js"
22import { Balances , Dictionary , Market , Order } from "ccxt"
33import PQueue from "p-queue"
4+ import crypto from "crypto"
5+ import { v4 as uuidv4 } from 'uuid'
46
57import logger from "../logger"
68import {
@@ -1949,7 +1951,7 @@ async function createTradeOpen(tradingData: TradingData): Promise<TradeOpen> {
19491951
19501952 // Create the new trade
19511953 return Promise . resolve ( {
1952- id : "T" + Date . now ( ) , // Generate a temporary internal ID, because we only get one from the NBT Hub when reloading the payload
1954+ id : newTradeID ( ) , // Generate a temporary internal ID, because we only get one from the NBT Hub when reloading the payload
19531955 isStopped : false ,
19541956 positionType : tradingData . signal . positionType ! ,
19551957 tradingType : tradingData . strategy . tradingType ,
@@ -1969,6 +1971,14 @@ async function createTradeOpen(tradingData: TradingData): Promise<TradeOpen> {
19691971 } )
19701972}
19711973
1974+ // Generate a shortened MD5 hash of a UUID
1975+ function newTradeID ( ) : string {
1976+ var md5sum = crypto . createHash ( 'md5' ) ;
1977+ md5sum . update ( uuidv4 ( ) ) ;
1978+ // 12 characters should still be unique enough for our purposes
1979+ return md5sum . digest ( 'hex' ) . substr ( 0 , 12 )
1980+ }
1981+
19721982// Get the list of wallets that are applicable for the market and trade position, sorted by priority
19731983function getPreferredWallets ( market : Market , positionType = PositionType . LONG ) {
19741984 const primary = env ( ) . PRIMARY_WALLET . toLowerCase ( ) as WalletType // Primary wallet for reference balance
0 commit comments